2019-07-20 12:16:52 +02:00
|
|
|
#!/bin/bash
|
|
|
|
##
|
|
|
|
## Determine modified packages and build/upload them.
|
|
|
|
##
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
##
|
|
|
|
## Preparation.
|
|
|
|
##
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
REPO_DIR=$(realpath "$(dirname "$(realpath "$0")")/../../../")
|
|
|
|
cd "$REPO_DIR" || {
|
|
|
|
echo "[!] Failed to cd into '$REPO_DIR'."
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
DO_UPLOAD=false
|
|
|
|
if [ $# -ge 1 ]; then
|
|
|
|
if [ "$1" = "--upload" ]; then
|
|
|
|
DO_UPLOAD=true
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
##
|
|
|
|
## Determining changes.
|
|
|
|
##
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
set +e
|
|
|
|
|
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
|
|
|
|
if [ -z "$CIRRUS_LAST_GREEN_CHANGE" ]; then
|
|
|
|
UPDATED_FILES=$(git diff-tree --no-commit-id --name-only -r "$CIRRUS_CHANGE_IN_REPO" 2>/dev/null | grep -P "packages/")
|
|
|
|
else
|
|
|
|
UPDATED_FILES=$(git diff-tree --no-commit-id --name-only -r "${CIRRUS_LAST_GREEN_CHANGE}..${CIRRUS_CHANGE_IN_REPO}" 2>/dev/null | grep -P "packages/")
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
# Pull requests are handled in a bit different way.
|
|
|
|
UPDATED_FILES=$(git diff-tree --no-commit-id --name-only -r "${CIRRUS_BASE_SHA}..${CIRRUS_CHANGE_IN_REPO}" 2>/dev/null | grep -P "packages/")
|
|
|
|
fi
|
|
|
|
|
|
|
|
## Determine modified packages.
|
|
|
|
existing_dirs=""
|
|
|
|
for dir in $(echo "$UPDATED_FILES" | grep -oP "packages/[a-z0-9+._-]+" | sort | uniq); do
|
|
|
|
if [ -d "${REPO_DIR}/${dir}" ]; then
|
|
|
|
existing_dirs+=" $dir"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
PACKAGE_DIRS="$existing_dirs"
|
|
|
|
unset dir existing_dirs
|
|
|
|
|
|
|
|
## Get names of modified packages.
|
|
|
|
PACKAGE_NAMES=$(echo "$PACKAGE_DIRS" | sed 's/packages\///g')
|
|
|
|
if [ -z "$PACKAGE_NAMES" ]; then
|
|
|
|
echo "[*] No modified packages found." >&2
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
## Some packages should be excluded from auto builds.
|
|
|
|
EXCLUDED_PACKAGES="rust texlive"
|
|
|
|
|
|
|
|
for excluded_pkg in $EXCLUDED_PACKAGES; do
|
|
|
|
PACKAGE_NAMES=$(echo "$PACKAGE_NAMES" | sed "s/\<${excluded_pkg}\>//g")
|
|
|
|
done
|
|
|
|
unset excluded_pkg
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
##
|
|
|
|
## Building packages.
|
|
|
|
##
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
if ! $DO_UPLOAD; then
|
|
|
|
echo "[*] Building packages: $PACKAGE_NAMES"
|
|
|
|
if [ -n "$CIRRUS_PR" ]; then
|
2019-07-21 01:29:24 +02:00
|
|
|
echo "[*] Pull request: https://github.com/termux/termux-packages/pull/${CIRRUS_PR}"
|
2019-07-20 12:16:52 +02:00
|
|
|
else
|
|
|
|
if [ -n "$CIRRUS_LAST_GREEN_CHANGE" ]; then
|
2019-07-20 21:59:16 +02:00
|
|
|
echo "[*] Changes: ${CIRRUS_LAST_GREEN_CHANGE}..${CIRRUS_CHANGE_IN_REPO}"
|
2019-07-20 12:16:52 +02:00
|
|
|
else
|
2019-07-20 21:59:16 +02:00
|
|
|
echo "[*] Changes: ${CIRRUS_CHANGE_IN_REPO}"
|
2019-07-20 12:16:52 +02:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2019-07-20 21:59:16 +02:00
|
|
|
./build-package.sh -a "$TERMUX_ARCH" -I $PACKAGE_NAMES
|
|
|
|
else
|
2019-07-22 20:33:21 +02:00
|
|
|
if [ -z "$BINTRAY_API_KEY" ]; then
|
|
|
|
echo "[!] Can't upload without Bintray API key."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$BINTRAY_GPG_PASSPHRASE" ]; then
|
|
|
|
echo "[!] Can't upload without GPG passphrase."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2019-07-22 20:24:29 +02:00
|
|
|
# Workaround for concurrent uploads.
|
2019-07-22 21:38:32 +02:00
|
|
|
if [ "$UPLOAD_DELAY" != "0" ];
|
|
|
|
echo "[!] Using workaround for Bintray issue with concurrent uploads."
|
|
|
|
echo "[!] Delaying upload by ${UPLOAD_DELAY} seconds."
|
|
|
|
sleep $UPLOAD_DELAY
|
|
|
|
fi
|
2019-07-22 20:24:29 +02:00
|
|
|
|
2019-07-22 17:39:16 +02:00
|
|
|
for attempt in 1 2 3; do
|
2019-07-21 16:31:46 +02:00
|
|
|
echo "[*] Uploading packages to Bintray:"
|
|
|
|
if ./scripts/package_uploader.sh -p "${PWD}/debs" $PACKAGE_NAMES; then
|
|
|
|
break
|
|
|
|
else
|
2019-07-22 17:39:16 +02:00
|
|
|
if [ "$attempt" = "3" ]; then
|
|
|
|
echo "[!] Went through 3 attempts of upload, giving up..."
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
echo "[!] Failure, retrying in 30 seconds..."
|
|
|
|
sleep 30
|
|
|
|
fi
|
2019-07-21 16:31:46 +02:00
|
|
|
fi
|
2019-07-21 16:44:31 +02:00
|
|
|
done
|
2019-07-20 12:16:52 +02:00
|
|
|
fi
|