2019-07-20 12:16:52 +02:00
|
|
|
#!/bin/bash
|
|
|
|
##
|
|
|
|
## Determine modified packages and build/upload them.
|
|
|
|
##
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2019-07-23 01:47:41 +02:00
|
|
|
## Some packages should be excluded from auto builds.
|
2019-09-13 11:38:56 +02:00
|
|
|
EXCLUDED_PACKAGES="lldb rust texlive"
|
2019-07-23 01:47:41 +02:00
|
|
|
|
2019-07-20 12:16:52 +02:00
|
|
|
###############################################################################
|
|
|
|
##
|
2019-07-23 22:32:20 +02:00
|
|
|
## Determining changes.
|
2019-07-20 12:16:52 +02:00
|
|
|
##
|
|
|
|
###############################################################################
|
|
|
|
|
2019-07-23 22:32:20 +02:00
|
|
|
set +e
|
|
|
|
|
2019-07-20 12:16:52 +02:00
|
|
|
REPO_DIR=$(realpath "$(dirname "$(realpath "$0")")/../../../")
|
|
|
|
cd "$REPO_DIR" || {
|
|
|
|
echo "[!] Failed to cd into '$REPO_DIR'."
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2019-07-22 19:03:32 +02:00
|
|
|
# Some environment variables are important for correct functionality
|
|
|
|
# of this script.
|
|
|
|
if [ -z "$CIRRUS_CHANGE_IN_REPO" ]; then
|
|
|
|
echo "[!] CIRRUS_CHANGE_IN_REPO is not set."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-07-22 20:24:29 +02:00
|
|
|
if [ -n "$CIRRUS_PR" ] && [ -z "$CIRRUS_BASE_SHA" ]; then
|
2019-07-22 19:03:32 +02:00
|
|
|
echo "[!] CIRRUS_BASE_SHA is not set."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-07-20 12:16:52 +02:00
|
|
|
# Process tag '%ci:no-build' that may be added as line to commit message.
|
|
|
|
# Will force CI to exit with status 'passed' without performing build.
|
|
|
|
if grep -qiP '^\s*%ci:no-build\s*$' <(git log --format="%B" -n 1 "$CIRRUS_CHANGE_IN_REPO"); then
|
2019-07-20 21:59:16 +02:00
|
|
|
echo "[!] Exiting with status 'passed' (tag '%ci:no-build' applied)."
|
2019-07-20 12:16:52 +02:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Process tag '%ci:reset-backlog' that may be added as line to commit message.
|
|
|
|
# Will force CI to build changes only for the current commit.
|
|
|
|
if grep -qiP '^\s*%ci:reset-backlog\s*$' <(git log --format="%B" -n 1 "$CIRRUS_CHANGE_IN_REPO"); then
|
2019-07-20 21:59:16 +02:00
|
|
|
echo "[!] Building only last pushed commit (tag '%ci:reset-backlog' applied)."
|
2019-07-20 12:16:52 +02:00
|
|
|
unset CIRRUS_LAST_GREEN_CHANGE
|
|
|
|
unset CIRRUS_BASE_SHA
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$CIRRUS_PR" ]; then
|
2019-07-23 01:47:41 +02:00
|
|
|
# Changes determined from the last commit where CI finished with status
|
|
|
|
# 'passed' (green) and the top commit.
|
2019-07-20 12:16:52 +02:00
|
|
|
if [ -z "$CIRRUS_LAST_GREEN_CHANGE" ]; then
|
2019-07-23 01:47:41 +02:00
|
|
|
GIT_CHANGES="$CIRRUS_CHANGE_IN_REPO"
|
2019-07-20 12:16:52 +02:00
|
|
|
else
|
2019-07-23 01:47:41 +02:00
|
|
|
GIT_CHANGES="${CIRRUS_LAST_GREEN_CHANGE}..${CIRRUS_CHANGE_IN_REPO}"
|
2019-07-20 12:16:52 +02:00
|
|
|
fi
|
2019-07-23 01:47:41 +02:00
|
|
|
echo "[*] Changes: $GIT_CHANGES"
|
2019-07-20 12:16:52 +02:00
|
|
|
else
|
2019-07-23 01:47:41 +02:00
|
|
|
# Changes in pull request are determined from commits between the
|
|
|
|
# top commit of base branch and latest commit of PR's branch.
|
|
|
|
GIT_CHANGES="${CIRRUS_BASE_SHA}..${CIRRUS_CHANGE_IN_REPO}"
|
|
|
|
echo "[*] Pull request: https://github.com/termux/termux-packages/pull/${CIRRUS_PR}"
|
2019-07-20 12:16:52 +02:00
|
|
|
fi
|
|
|
|
|
2019-07-23 01:47:41 +02:00
|
|
|
# Determine changes from commit range.
|
2019-07-24 20:41:27 +02:00
|
|
|
CHANGED_FILES=$(git diff-tree --no-commit-id --name-only -r "$GIT_CHANGES" 2>/dev/null)
|
2019-07-23 22:32:20 +02:00
|
|
|
|
|
|
|
# Modified packages.
|
|
|
|
PACKAGE_NAMES=$(sed -nE 's@^packages/([^/]*)/build.sh@\1@p' <<< "$CHANGED_FILES")
|
|
|
|
|
|
|
|
# Docker scripts.
|
|
|
|
DOCKER_SCRIPTS=$(grep -P '^scripts/(Dockerfile|properties.sh|setup-android-sdk.sh|setup-ubuntu.sh)$' <<< "$CHANGED_FILES")
|
|
|
|
[ -n "$DOCKER_SCRIPTS" ] && DOCKER_IMAGE_UPDATE_NEEDED=true || DOCKER_IMAGE_UPDATE_NEEDED=false
|
|
|
|
|
|
|
|
unset CHANGED_FILES
|
2019-07-23 01:47:41 +02:00
|
|
|
|
|
|
|
## Filter deleted packages.
|
|
|
|
for pkg in $PACKAGE_NAMES; do
|
|
|
|
if [ ! -d "${REPO_DIR}/packages/${pkg}" ]; then
|
2019-07-23 14:21:16 +02:00
|
|
|
PACKAGE_NAMES=$(sed -E "s/(^|\s\s*)${pkg}(\$|\s\s*)/ /g" <<< "$PACKAGE_NAMES")
|
2019-07-20 12:16:52 +02:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2019-07-23 01:47:41 +02:00
|
|
|
## Filter excluded packages.
|
|
|
|
for pkg in $EXCLUDED_PACKAGES; do
|
2019-07-23 14:21:16 +02:00
|
|
|
PACKAGE_NAMES=$(sed -E "s/(^|\s\s*)${pkg}(\$|\s\s*)/ /g" <<< "$PACKAGE_NAMES")
|
2019-07-23 01:47:41 +02:00
|
|
|
done
|
|
|
|
unset pkg
|
|
|
|
|
2019-08-14 18:59:21 +02:00
|
|
|
## Remove trailing spaces.
|
|
|
|
PACKAGE_NAMES=$(sed 's/[[:blank:]]*$//' <<< "$PACKAGE_NAMES")
|
|
|
|
|
2019-07-20 12:16:52 +02:00
|
|
|
set -e
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
##
|
2019-07-23 22:32:20 +02:00
|
|
|
## Executing requested actions. Only one per script session.
|
2019-07-20 12:16:52 +02:00
|
|
|
##
|
|
|
|
###############################################################################
|
|
|
|
|
2019-07-23 22:32:20 +02:00
|
|
|
case "$1" in
|
|
|
|
--update-docker)
|
|
|
|
if $DOCKER_IMAGE_UPDATE_NEEDED; then
|
|
|
|
if [ "$CIRRUS_BRANCH" != "master" ]; then
|
|
|
|
echo "[!] Refusing to update docker image on non-master branch."
|
|
|
|
exit 1
|
|
|
|
fi
|
2019-07-23 01:47:41 +02:00
|
|
|
|
2019-07-23 22:32:20 +02:00
|
|
|
if [ -z "$DOCKER_USERNAME" ]; then
|
|
|
|
echo "[!] Can't update docker image without Docker Hub user name."
|
|
|
|
exit 1
|
|
|
|
fi
|
2019-07-23 01:47:41 +02:00
|
|
|
|
2019-07-23 22:32:20 +02:00
|
|
|
if [ -z "$DOCKER_PASSWORD" ]; then
|
|
|
|
echo "[!] Can't update docker image without Docker Hub password."
|
|
|
|
exit 1
|
|
|
|
fi
|
2019-07-23 01:47:41 +02:00
|
|
|
|
2019-07-23 22:32:20 +02:00
|
|
|
cd "${REPO_DIR}/scripts"
|
2019-07-23 01:47:41 +02:00
|
|
|
|
2019-07-23 22:32:20 +02:00
|
|
|
docker build --tag termux/package-builder:latest .
|
|
|
|
docker login --username "$DOCKER_USERNAME" --password "$DOCKER_PASSWORD"
|
|
|
|
docker push termux/package-builder:latest
|
|
|
|
else
|
|
|
|
echo "[*] No need to update docker image."
|
|
|
|
exit 0
|
2019-07-20 12:16:52 +02:00
|
|
|
fi
|
2019-07-23 22:32:20 +02:00
|
|
|
;;
|
|
|
|
--upload)
|
|
|
|
if [ -n "$PACKAGE_NAMES" ]; then
|
|
|
|
if [ "$CIRRUS_BRANCH" != "master" ]; then
|
|
|
|
echo "[!] Refusing to upload packages on non-master branch."
|
|
|
|
exit 1
|
|
|
|
fi
|
2019-07-20 12:16:52 +02:00
|
|
|
|
2019-07-23 22:32:20 +02:00
|
|
|
if [ -z "$BINTRAY_API_KEY" ]; then
|
|
|
|
echo "[!] Can't upload packages without Bintray API key."
|
|
|
|
exit 1
|
|
|
|
fi
|
2019-07-22 20:33:21 +02:00
|
|
|
|
2019-07-23 22:32:20 +02:00
|
|
|
if [ -z "$BINTRAY_GPG_PASSPHRASE" ]; then
|
|
|
|
echo "[!] Can't upload packages without GPG passphrase."
|
|
|
|
exit 1
|
2019-07-22 17:39:16 +02:00
|
|
|
fi
|
2019-07-23 01:47:41 +02:00
|
|
|
|
2019-07-23 22:32:20 +02:00
|
|
|
echo "[*] Uploading packages to Bintray:"
|
|
|
|
"${REPO_DIR}/scripts/package_uploader.sh" -p "${PWD}/debs" $PACKAGE_NAMES
|
|
|
|
else
|
|
|
|
echo "[*] No modified packages found."
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
if [ -n "$PACKAGE_NAMES" ]; then
|
2019-07-24 20:41:27 +02:00
|
|
|
echo "[*] Building packages:" $PACKAGE_NAMES
|
2019-07-23 22:32:20 +02:00
|
|
|
./build-package.sh -a "$TERMUX_ARCH" -I $PACKAGE_NAMES
|
|
|
|
else
|
|
|
|
echo "[*] No modified packages found."
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|