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.
|
|
|
|
EXCLUDED_PACKAGES="rust texlive"
|
|
|
|
|
2019-07-20 12:16:52 +02:00
|
|
|
###############################################################################
|
|
|
|
##
|
|
|
|
## 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
|
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.
|
|
|
|
PACKAGE_NAMES=$(git diff-tree --no-commit-id --name-only -r "$GIT_CHANGES" packages/ 2>/dev/null | sed -E 's@^packages/([^/]*)/build.sh@\1@')
|
|
|
|
|
|
|
|
## Filter deleted packages.
|
|
|
|
for pkg in $PACKAGE_NAMES; do
|
|
|
|
if [ ! -d "${REPO_DIR}/packages/${pkg}" ]; then
|
|
|
|
PACKAGE_NAMES=$(sed "s/\<${pkg}\>//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
|
|
|
|
PACKAGE_NAMES=$(sed "s/\<${pkg}\>//g" <<< "$PACKAGE_NAMES")
|
|
|
|
done
|
|
|
|
unset pkg
|
|
|
|
|
2019-07-20 12:16:52 +02:00
|
|
|
if [ -z "$PACKAGE_NAMES" ]; then
|
2019-07-23 01:47:41 +02:00
|
|
|
echo "[*] No modified packages found."
|
2019-07-20 12:16:52 +02:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
##
|
|
|
|
## Building packages.
|
|
|
|
##
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
if ! $DO_UPLOAD; then
|
|
|
|
echo "[*] Building packages: $PACKAGE_NAMES"
|
2019-07-23 01:47:41 +02:00
|
|
|
./build-package.sh -a "$TERMUX_ARCH" -I $PACKAGE_NAMES
|
|
|
|
fi
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
##
|
|
|
|
## Storing packages in cache // retrieving and uploading to Bintray.
|
|
|
|
##
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
if [ "$CIRRUS_BRANCH" = "master" ]; then
|
|
|
|
if ! $DO_UPLOAD; then
|
|
|
|
ARCHIVE_NAME="debs-${TERMUX_ARCH}-${CIRRUS_CHANGE_IN_REPO}.tar.gz"
|
|
|
|
|
|
|
|
if [ -d "${REPO_DIR}/debs" ]; then
|
|
|
|
echo "[*] Archiving packages into '${ARCHIVE_NAME}'."
|
|
|
|
tar zcf "$ARCHIVE_NAME" debs
|
|
|
|
|
|
|
|
echo "[*] Uploading '${ARCHIVE_NAME}' to cache:"
|
|
|
|
echo
|
|
|
|
curl --upload-file "$ARCHIVE_NAME" \
|
|
|
|
"http://${CIRRUS_HTTP_CACHE_HOST}/${ARCHIVE_NAME}"
|
|
|
|
echo
|
|
|
|
fi
|
2019-07-20 12:16:52 +02:00
|
|
|
else
|
2019-07-23 01:47:41 +02:00
|
|
|
if [ -z "$BINTRAY_API_KEY" ]; then
|
|
|
|
echo "[!] Can't upload without Bintray API key."
|
|
|
|
exit 1
|
2019-07-20 12:16:52 +02:00
|
|
|
fi
|
|
|
|
|
2019-07-23 01:47:41 +02:00
|
|
|
if [ -z "$BINTRAY_GPG_PASSPHRASE" ]; then
|
|
|
|
echo "[!] Can't upload without GPG passphrase."
|
|
|
|
exit 1
|
|
|
|
fi
|
2019-07-22 20:33:21 +02:00
|
|
|
|
2019-07-23 01:47:41 +02:00
|
|
|
for arch in aarch64 arm i686 x86_64; do
|
|
|
|
ARCHIVE_NAME="debs-${arch}-${CIRRUS_CHANGE_IN_REPO}.tar.gz"
|
2019-07-22 20:33:21 +02:00
|
|
|
|
2019-07-23 01:47:41 +02:00
|
|
|
echo "[*] Downloading '${ARCHIVE_NAME}' from cache:"
|
|
|
|
echo
|
|
|
|
curl --output "/tmp/${ARCHIVE_NAME}" \
|
|
|
|
"http://${CIRRUS_HTTP_CACHE_HOST}/${ARCHIVE_NAME}"
|
|
|
|
echo
|
2019-07-22 20:24:29 +02:00
|
|
|
|
2019-07-23 01:47:41 +02:00
|
|
|
if [ -s "/tmp/${ARCHIVE_NAME}" ]; then
|
|
|
|
echo "[*] Unpacking '/tmp/${ARCHIVE_NAME}':"
|
|
|
|
echo
|
|
|
|
tar xvf "/tmp/${ARCHIVE_NAME}"
|
|
|
|
echo
|
2019-07-22 17:39:16 +02:00
|
|
|
else
|
2019-07-23 01:47:41 +02:00
|
|
|
echo "[!] Empty archive '/tmp/${ARCHIVE_NAME}'."
|
2019-07-22 17:39:16 +02:00
|
|
|
fi
|
2019-07-23 01:47:41 +02:00
|
|
|
done
|
|
|
|
|
|
|
|
echo "[*] Uploading packages to Bintray:"
|
|
|
|
echo
|
|
|
|
"${REPO_DIR}/scripts/package_uploader.sh" -p "${PWD}/debs" $PACKAGE_NAMES
|
|
|
|
fi
|
2019-07-20 12:16:52 +02:00
|
|
|
fi
|