2020-12-17 13:59:00 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -e -u
|
|
|
|
BASEDIR=$(dirname "$(realpath "$0")")
|
|
|
|
|
2020-12-17 21:22:16 +01:00
|
|
|
# These variables should be set in environment outside of this script.
|
|
|
|
# Build updated packages.
|
2020-12-17 21:03:35 +01:00
|
|
|
: "${BUILD_PACKAGES:=false}"
|
2020-12-17 21:22:16 +01:00
|
|
|
# Commit changes to Git.
|
|
|
|
: "${GIT_COMMIT_PACKAGES:=false}"
|
|
|
|
# Push changes to remote.
|
|
|
|
: "${GIT_PUSH_PACKAGES:=false}"
|
2020-12-17 21:03:35 +01:00
|
|
|
|
2020-12-17 13:59:00 +01:00
|
|
|
if [ -z "${GITHUB_API_TOKEN-}" ]; then
|
|
|
|
echo "You need a Github Personal Access Token be set in variable GITHUB_API_TOKEN."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -f "${BASEDIR}/github-projects.txt" ]; then
|
2020-12-18 00:09:28 +01:00
|
|
|
for line in $(grep -P '^[a-z0-9]' "${BASEDIR}/github-projects.txt"); do
|
2021-01-02 22:18:16 +01:00
|
|
|
unset package project version_regexp termux_version termux_epoch latest_version
|
2020-12-17 13:59:00 +01:00
|
|
|
package=$(echo "$line" | cut -d'|' -f1)
|
2020-12-17 20:52:46 +01:00
|
|
|
project=$(echo "$line" | cut -d'|' -f2)
|
|
|
|
version_regexp=$(echo "$line" | cut -d'|' -f3-)
|
2020-12-17 13:59:00 +01:00
|
|
|
|
|
|
|
if [ ! -d "${BASEDIR}/../../packages/${package}" ]; then
|
|
|
|
echo "Package '$package' is not available, skipping."
|
2020-12-18 18:54:12 +01:00
|
|
|
continue
|
2020-12-17 13:59:00 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Our local version of package.
|
2021-01-02 22:29:23 +01:00
|
|
|
termux_version=$(set +e +u;. "${BASEDIR}/../../packages/${package}/build.sh" 2>/dev/null; echo "$TERMUX_PKG_VERSION")
|
2021-01-02 22:18:16 +01:00
|
|
|
termux_epoch="$(echo "$termux_version" | cut -d: -f1)"
|
2021-01-02 22:29:23 +01:00
|
|
|
termux_version=$(echo "$termux_version" | cut -d: -f2-)
|
2021-01-02 23:00:40 +01:00
|
|
|
if [ "$termux_version" == "$termux_epoch" ]; then
|
|
|
|
# No epoch set.
|
|
|
|
termux_epoch=""
|
|
|
|
else
|
|
|
|
termux_epoch+=":"
|
|
|
|
fi
|
2020-12-17 13:59:00 +01:00
|
|
|
|
|
|
|
# Latest version is the current release tag on Github.
|
2021-06-13 21:34:38 +02:00
|
|
|
latest_version=$(curl --silent --location -H "Authorization: token ${GITHUB_API_TOKEN}" "https://api.github.com/repos/${project}/releases/latest" | jq -r .tag_name)
|
2020-12-17 13:59:00 +01:00
|
|
|
|
|
|
|
# Remove leading 'v' which is common in version tag.
|
|
|
|
latest_version=${latest_version#v}
|
|
|
|
|
2020-12-17 20:52:46 +01:00
|
|
|
# If needed, filter version numbers from tag by using regexp.
|
|
|
|
if [ -n "$version_regexp" ]; then
|
|
|
|
latest_version=$(grep -oP "$version_regexp" <<< "$latest_version")
|
|
|
|
fi
|
|
|
|
|
2020-12-17 13:59:00 +01:00
|
|
|
# We have no better choice for comparing versions.
|
|
|
|
if [ "$(echo -e "${termux_version}\n${latest_version}" | sort -V | head -n 1)" != "$latest_version" ] ;then
|
2020-12-17 21:03:35 +01:00
|
|
|
if [ "$BUILD_PACKAGES" = "false" ]; then
|
|
|
|
echo "Package '${package}' needs update to '${latest_version}'."
|
|
|
|
else
|
|
|
|
echo "Updating '${package}' to '${latest_version}'."
|
2021-01-02 22:18:16 +01:00
|
|
|
sed -i "s/^\(TERMUX_PKG_VERSION=\)\(.*\)\$/\1${termux_epoch}${latest_version}/g" "${BASEDIR}/../../packages/${package}/build.sh"
|
2020-12-17 21:03:35 +01:00
|
|
|
sed -i "/TERMUX_PKG_REVISION=/d" "${BASEDIR}/../../packages/${package}/build.sh"
|
2020-12-17 21:13:45 +01:00
|
|
|
echo n | "${BASEDIR}/../bin/update-checksum" "$package"
|
|
|
|
|
|
|
|
echo "Trying to build package '${package}'."
|
2020-12-17 21:22:16 +01:00
|
|
|
if "${BASEDIR}/../run-docker.sh" ./build-package.sh -a aarch64 -I "$package"; then
|
|
|
|
if [ "$GIT_COMMIT_PACKAGES" = "true" ]; then
|
|
|
|
git add "${BASEDIR}/../../packages/${package}"
|
2021-01-06 13:48:36 +01:00
|
|
|
git commit -m "$(echo -e "${package}: update to ${latest_version}\n\nThis commit has been automatically submitted by Github Actions.")"
|
2020-12-17 21:22:16 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$GIT_PUSH_PACKAGES" = "true" ]; then
|
2020-12-18 20:40:24 +01:00
|
|
|
git pull --rebase
|
2020-12-17 21:22:16 +01:00
|
|
|
git push
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "Failed to build '${package}'."
|
|
|
|
git checkout -- "${BASEDIR}/../../packages/${package}"
|
|
|
|
fi
|
2020-12-17 21:03:35 +01:00
|
|
|
fi
|
2020-12-17 13:59:00 +01:00
|
|
|
fi
|
2020-12-18 00:09:28 +01:00
|
|
|
done
|
2020-12-17 13:59:00 +01:00
|
|
|
fi
|