2020-01-22 00:25:35 +00:00
|
|
|
name: Packages
|
|
|
|
|
|
|
|
on:
|
|
|
|
push:
|
|
|
|
branches:
|
|
|
|
- master
|
|
|
|
paths:
|
2022-04-17 11:37:08 +00:00
|
|
|
- 'packages/**'
|
|
|
|
- 'root-packages/**'
|
|
|
|
- 'x11-packages/**'
|
2020-01-22 00:25:35 +00:00
|
|
|
pull_request:
|
|
|
|
paths:
|
2022-04-17 11:37:08 +00:00
|
|
|
- 'packages/**'
|
|
|
|
- 'root-packages/**'
|
|
|
|
- 'x11-packages/**'
|
2021-10-26 17:19:10 +00:00
|
|
|
workflow_dispatch:
|
|
|
|
inputs:
|
|
|
|
packages:
|
|
|
|
description: "A space-separated names of packages selected for rebuilding"
|
|
|
|
required: true
|
2022-10-07 00:45:22 +00:00
|
|
|
|
2022-08-27 20:51:40 +00:00
|
|
|
permissions: {} # none
|
2020-01-22 00:25:35 +00:00
|
|
|
|
|
|
|
jobs:
|
|
|
|
build:
|
2022-08-27 20:51:40 +00:00
|
|
|
permissions:
|
|
|
|
contents: read # actions/upload-artifact doesn't need contents: write
|
2022-09-12 23:41:00 +00:00
|
|
|
runs-on: ubuntu-22.04
|
2020-01-22 00:25:35 +00:00
|
|
|
strategy:
|
|
|
|
matrix:
|
|
|
|
target_arch: [aarch64, arm, i686, x86_64]
|
2021-06-24 04:23:02 +00:00
|
|
|
fail-fast: false
|
2020-01-22 00:25:35 +00:00
|
|
|
steps:
|
|
|
|
- name: Clone repository
|
2023-09-05 08:50:22 +00:00
|
|
|
uses: actions/checkout@v4
|
2020-01-22 00:25:35 +00:00
|
|
|
with:
|
|
|
|
fetch-depth: 1000
|
2022-04-16 06:58:58 +00:00
|
|
|
- name: Gather build summary
|
2020-01-22 00:25:35 +00:00
|
|
|
run: |
|
2021-10-26 17:19:10 +00:00
|
|
|
if [ "${{ github.event_name }}" != "workflow_dispatch" ]; then
|
|
|
|
BASE_COMMIT=$(jq --raw-output .pull_request.base.sha "$GITHUB_EVENT_PATH")
|
|
|
|
OLD_COMMIT=$(jq --raw-output .commits[0].id "$GITHUB_EVENT_PATH")
|
|
|
|
HEAD_COMMIT=$(jq --raw-output .commits[-1].id "$GITHUB_EVENT_PATH")
|
|
|
|
if [ "$BASE_COMMIT" = "null" ]; then
|
|
|
|
if [ "$OLD_COMMIT" = "$HEAD_COMMIT" ]; then
|
|
|
|
# Single-commit push.
|
|
|
|
echo "Processing commit: ${HEAD_COMMIT}"
|
|
|
|
CHANGED_FILES=$(git diff-tree --no-commit-id --name-only -r "${HEAD_COMMIT}")
|
|
|
|
else
|
|
|
|
# Multi-commit push.
|
|
|
|
OLD_COMMIT="${OLD_COMMIT}~1"
|
|
|
|
echo "Processing commit range: ${OLD_COMMIT}..${HEAD_COMMIT}"
|
|
|
|
CHANGED_FILES=$(git diff-tree --no-commit-id --name-only -r "${OLD_COMMIT}" "${HEAD_COMMIT}")
|
|
|
|
fi
|
2020-01-22 00:25:35 +00:00
|
|
|
else
|
2021-10-26 17:19:10 +00:00
|
|
|
# Pull requests.
|
|
|
|
echo "Processing pull request #$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH"): ${BASE_COMMIT}..HEAD"
|
|
|
|
CHANGED_FILES=$(git diff-tree --no-commit-id --name-only -r "${BASE_COMMIT}" "HEAD")
|
2020-01-22 00:25:35 +00:00
|
|
|
fi
|
|
|
|
fi
|
2020-02-17 11:33:59 +00:00
|
|
|
mkdir -p ./artifacts ./debs
|
2020-06-02 17:25:36 +00:00
|
|
|
touch ./debs/.placeholder
|
2022-04-13 12:08:13 +00:00
|
|
|
|
2021-10-26 17:19:10 +00:00
|
|
|
if [ "${{ github.event_name }}" != "workflow_dispatch" ]; then
|
2022-04-19 15:25:54 +00:00
|
|
|
# Process tag '%ci:no-build' that may be added as line to commit message.
|
|
|
|
# Forces CI to cancel current build with status 'passed'
|
|
|
|
if grep -qiP '^\s*%ci:no-build\s*$' <(git log --format="%B" -n 1 "HEAD"); then
|
|
|
|
tar cf artifacts/debs-${{ matrix.target_arch }}.tar debs
|
|
|
|
echo "[!] Force exiting as tag '%ci:no-build' was applied to HEAD commit message."
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2021-10-26 17:19:10 +00:00
|
|
|
# Build local Docker image if setup scripts were changed.
|
|
|
|
# Useful for pull requests submitting changes for both build environment and packages.
|
2022-12-25 06:56:26 +00:00
|
|
|
if grep -qP '^scripts/(Dockerfile|properties\.sh|setup-android-sdk\.sh|setup-ubuntu\.sh)$' <<< "$CHANGED_FILES"; then
|
2021-10-26 17:19:10 +00:00
|
|
|
echo "Detected changes for environment setup scripts. Building custom Docker image now."
|
|
|
|
cd ./scripts
|
2022-07-22 21:19:08 +00:00
|
|
|
docker build -t ghcr.io/termux/package-builder:latest .
|
2021-10-26 17:19:10 +00:00
|
|
|
cd ..
|
|
|
|
fi
|
2022-04-16 06:50:09 +00:00
|
|
|
|
2023-08-30 20:40:08 +00:00
|
|
|
for repo_path in $(jq --raw-output 'del(.pkg_format) | keys | .[]' repo.json); do
|
2022-04-20 12:04:33 +00:00
|
|
|
repo=$(jq --raw-output '.["'${repo_path}'"].name' repo.json)
|
2022-04-16 06:50:09 +00:00
|
|
|
# Parse changed files and identify new packages and deleted packages.
|
|
|
|
# Create lists of those packages that will be passed to upload job for
|
|
|
|
# further processing.
|
|
|
|
while read -r file; do
|
2022-04-18 10:23:47 +00:00
|
|
|
if ! [[ $file == ${repo_path}/* ]]; then
|
2022-04-16 06:50:09 +00:00
|
|
|
# This file does not belong to a package, so ignore it
|
|
|
|
continue
|
2021-10-26 17:19:10 +00:00
|
|
|
fi
|
2022-04-18 10:23:47 +00:00
|
|
|
if [[ $file =~ ^${repo_path}/([.a-z0-9+-]*)/([.a-z0-9+-]*).subpackage.sh$ ]]; then
|
2022-04-16 06:50:09 +00:00
|
|
|
# A subpackage was modified, check if it was deleted or just updated
|
|
|
|
pkg=${BASH_REMATCH[1]}
|
|
|
|
subpkg=${BASH_REMATCH[2]}
|
2022-04-17 11:37:08 +00:00
|
|
|
if [ ! -f "${repo_path}/${pkg}/${subpkg}.subpackage.sh" ]; then
|
2022-04-18 10:23:47 +00:00
|
|
|
echo "$subpkg" >> ./deleted_${repo}_packages.txt
|
2022-04-16 06:50:09 +00:00
|
|
|
fi
|
2022-04-18 10:23:47 +00:00
|
|
|
elif [[ $file =~ ^${repo_path}/([.a-z0-9+-]*)/.*$ ]]; then
|
2022-04-16 06:50:09 +00:00
|
|
|
# package, check if it was deleted or updated
|
|
|
|
pkg=${BASH_REMATCH[1]}
|
2022-04-18 10:23:47 +00:00
|
|
|
if [ -d "${repo_path}/${pkg}" ]; then
|
|
|
|
echo "$pkg" >> ./built_${repo}_packages.txt
|
2022-04-16 06:50:09 +00:00
|
|
|
# If there are subpackages we want to create a list of those
|
|
|
|
# as well
|
2022-04-17 11:37:08 +00:00
|
|
|
for file in $(find "${repo_path}/${pkg}/" -maxdepth 1 -type f -name \*.subpackage.sh | sort); do
|
2022-04-18 10:23:47 +00:00
|
|
|
echo "$(basename "${file%%.subpackage.sh}")" >> ./built_${repo}_subpackages.txt
|
2022-04-16 06:50:09 +00:00
|
|
|
done
|
2022-04-18 10:23:47 +00:00
|
|
|
else
|
|
|
|
echo "$pkg" >> ./deleted_${repo}_packages
|
2022-04-16 06:50:09 +00:00
|
|
|
fi
|
2021-10-26 17:19:10 +00:00
|
|
|
fi
|
2022-04-16 06:50:09 +00:00
|
|
|
done<<<${CHANGED_FILES}
|
|
|
|
done
|
2021-10-26 17:19:10 +00:00
|
|
|
else
|
2021-11-04 14:07:46 +00:00
|
|
|
for pkg in ${{ github.event.inputs.packages }}; do
|
2023-08-30 20:40:08 +00:00
|
|
|
repo_paths=$(jq --raw-output 'del(.pkg_format) | keys | .[]' repo.json)
|
2022-04-18 10:23:47 +00:00
|
|
|
found=false
|
|
|
|
for repo_path in $repo_paths; do
|
2022-04-20 12:04:33 +00:00
|
|
|
repo=$(jq --raw-output '.["'${repo_path}'"].name' repo.json)
|
2022-04-18 10:23:47 +00:00
|
|
|
if [ -d "${repo_path}/${pkg}" ]; then
|
|
|
|
found=true
|
|
|
|
echo "$pkg" >> ./built_${repo}_packages.txt
|
|
|
|
for subpkg in $(find "${repo_path}/${pkg}/" -maxdepth 1 -type f -name \*.subpackage.sh | sort); do
|
|
|
|
echo "$(basename "${subpkg%%.subpackage.sh}")" >> ./built_${repo}_subpackages.txt
|
2022-04-16 06:50:09 +00:00
|
|
|
done
|
|
|
|
fi
|
2021-11-04 14:07:46 +00:00
|
|
|
done
|
2022-04-18 10:23:47 +00:00
|
|
|
if [ "$found" != true ]; then
|
|
|
|
echo "Package '${pkg}' not found in any of the repo"
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-10-26 17:19:10 +00:00
|
|
|
done
|
|
|
|
fi
|
2021-03-01 07:52:25 +00:00
|
|
|
|
2023-08-30 20:40:08 +00:00
|
|
|
for repo in $(jq --raw-output 'del(.pkg_format) | .[].name' repo.json); do
|
2022-04-16 06:50:09 +00:00
|
|
|
# Fix so that lists do not contain duplicates
|
2022-04-18 10:23:47 +00:00
|
|
|
if [ -f ./built_${repo}_packages.txt ]; then
|
2022-10-30 14:14:43 +00:00
|
|
|
sort ./built_${repo}_packages.txt | uniq > ./built_${repo}_packages.txt.tmp
|
2022-04-18 10:23:47 +00:00
|
|
|
mv ./built_${repo}_packages.txt.tmp ./built_${repo}_packages.txt
|
2022-04-16 06:50:09 +00:00
|
|
|
fi
|
2022-04-18 10:23:47 +00:00
|
|
|
if [ -f ./built_${repo}_subpackages.txt ]; then
|
2022-10-30 14:14:43 +00:00
|
|
|
sort ./built_${repo}_subpackages.txt | uniq > ./built_${repo}_subpackages.txt.tmp
|
2022-04-18 10:23:47 +00:00
|
|
|
mv ./built_${repo}_subpackages.txt.tmp ./built_${repo}_subpackages.txt
|
2022-04-16 06:50:09 +00:00
|
|
|
fi
|
2022-04-18 10:23:47 +00:00
|
|
|
if [ -f ./deleted_${repo}_packages.txt ]; then
|
2022-10-30 14:14:43 +00:00
|
|
|
sort ./deleted_${repo}_packages.txt | uniq > ./deleted_${repo}_packages.txt.tmp
|
2022-04-18 10:23:47 +00:00
|
|
|
mv ./deleted_${repo}_packages.txt.tmp ./deleted_${repo}_packages.txt
|
2022-04-16 06:50:09 +00:00
|
|
|
fi
|
|
|
|
done
|
2021-03-01 07:52:25 +00:00
|
|
|
|
2022-04-16 06:50:09 +00:00
|
|
|
- name: Lint packages
|
2022-04-16 06:58:58 +00:00
|
|
|
run: |
|
2022-04-18 10:23:47 +00:00
|
|
|
declare -a package_recipes
|
2023-08-30 20:40:08 +00:00
|
|
|
for repo_path in $(jq --raw-output 'del(.pkg_format) | keys | .[]' repo.json); do
|
2022-04-20 12:04:33 +00:00
|
|
|
repo=$(jq --raw-output '.["'${repo_path}'"].name' repo.json)
|
2022-04-18 10:23:47 +00:00
|
|
|
if [ -f ./built_${repo}_packages.txt ]; then
|
|
|
|
package_recipes="$package_recipes $(cat ./built_${repo}_packages.txt | repo_path=${repo_path} awk '{print ENVIRON["repo_path"]"/"$1"/build.sh"}')"
|
2022-04-16 06:50:09 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2022-04-19 15:21:26 +00:00
|
|
|
if [ ! -z "$package_recipes" ]; then
|
|
|
|
./scripts/lint-packages.sh $package_recipes
|
|
|
|
fi
|
2022-04-16 06:50:09 +00:00
|
|
|
|
|
|
|
- name: Build packages
|
|
|
|
run: |
|
2022-04-18 10:23:47 +00:00
|
|
|
declare -a packages
|
2023-08-30 20:40:08 +00:00
|
|
|
for repo_path in $(jq --raw-output 'del(.pkg_format) | keys | .[]' repo.json); do
|
2022-04-20 12:04:33 +00:00
|
|
|
repo=$(jq --raw-output '.["'${repo_path}'"].name' repo.json)
|
2022-04-17 11:37:08 +00:00
|
|
|
|
2022-04-18 10:23:47 +00:00
|
|
|
if [ -f ./built_${repo}_packages.txt ]; then
|
|
|
|
packages="$packages $(cat ./built_${repo}_packages.txt)"
|
2022-04-16 06:50:09 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2022-04-19 15:21:26 +00:00
|
|
|
if [ ! -z "$packages" ]; then
|
2023-10-07 04:55:04 +00:00
|
|
|
if grep -q ' rust\|swift ' <<< "${packages}"; then
|
2023-10-06 03:51:09 +00:00
|
|
|
sudo apt purge -yq $(dpkg -l | grep '^ii' | awk '{ print $2 }' | grep -P '(aspnetcore|cabal-|dotnet-|ghc-|libmono|php)') \
|
|
|
|
firefox google-chrome-stable microsoft-edge-stable mono-runtime-common monodoc-manual ruby
|
|
|
|
sudo apt autoremove -yq
|
|
|
|
sudo rm -fr /opt/hostedtoolcache /usr/share/dotnet /usr/share/swift
|
|
|
|
fi
|
2023-10-03 06:42:50 +00:00
|
|
|
if grep -q ' clvk\|dart\|libllvm\|rust\|rustc-nightly\|swift\|tinygo\|wasmer\|zig\|firefox ' <<< "$packages"; then
|
|
|
|
./scripts/setup-ubuntu.sh
|
|
|
|
sudo apt install ninja-build
|
2023-10-07 04:55:04 +00:00
|
|
|
# github CI is often running out of disk space for large packages,
|
|
|
|
# so these df checks will let us know how much there was.
|
|
|
|
df -h
|
2023-10-03 06:42:50 +00:00
|
|
|
NDK=$ANDROID_NDK_ROOT ANDROID_HOME=$ANDROID_SDK_ROOT ./build-package.sh -I -a ${{ matrix.target_arch }} $packages
|
2023-10-07 04:55:04 +00:00
|
|
|
df -h
|
2023-10-03 06:42:50 +00:00
|
|
|
else
|
|
|
|
./scripts/run-docker.sh ./build-package.sh -I -a ${{ matrix.target_arch }} $packages
|
|
|
|
fi
|
2022-04-19 15:21:26 +00:00
|
|
|
fi
|
2021-03-01 07:52:25 +00:00
|
|
|
|
2022-03-30 02:50:03 +00:00
|
|
|
- name: Generate build artifacts
|
|
|
|
if: always()
|
|
|
|
run: |
|
2022-01-30 15:06:09 +00:00
|
|
|
test -d termux-packages/output && mv termux-packages/output/* ./output/
|
|
|
|
|
2023-08-30 20:40:08 +00:00
|
|
|
for repo in $(jq --raw-output 'del(.pkg_format) | .[].name' repo.json); do
|
2022-04-16 06:50:09 +00:00
|
|
|
# Put package lists into directory with *.deb files so they will be transferred to
|
|
|
|
# upload job.
|
2022-04-18 16:23:42 +00:00
|
|
|
test -f ./built_${repo}_packages.txt && mv ./built_${repo}_packages.txt ./debs/
|
|
|
|
test -f ./built_${repo}_subpackages.txt && cat ./built_${repo}_subpackages.txt >> ./debs/built_${repo}_packages.txt \
|
2022-04-18 10:23:47 +00:00
|
|
|
&& rm ./built_${repo}_subpackages.txt
|
2022-04-18 16:23:42 +00:00
|
|
|
test -f ./deleted_${repo}_packages.txt && mv ./deleted_${repo}_packages.txt ./debs/
|
2022-04-16 06:50:09 +00:00
|
|
|
|
|
|
|
# Move only debs from built_packages into debs/ folder before
|
|
|
|
# creating an archive.
|
|
|
|
while read -r pkg; do
|
|
|
|
# Match both $pkg.deb and $pkg-static.deb.
|
|
|
|
find output \( -name "$pkg_*.deb" -o -name "$pkg-static_*.deb" \) -type f -print0 | xargs -0r mv -t debs/
|
2022-04-18 16:23:42 +00:00
|
|
|
done < <(cat ./debs/built_${repo}_packages.txt)
|
2022-04-16 06:50:09 +00:00
|
|
|
done
|
2022-04-18 16:23:42 +00:00
|
|
|
|
|
|
|
# Files containing certain symbols (e.g. ":") will cause failure in actions/upload-artifact.
|
|
|
|
# Archiving *.deb files in a tarball to avoid issues with uploading.
|
|
|
|
tar cf artifacts/debs-${{ matrix.target_arch }}-${{ github.sha }}.tar debs
|
2020-03-12 17:02:16 +00:00
|
|
|
- name: Checksums for built *.deb files
|
2022-03-30 02:50:03 +00:00
|
|
|
if: always()
|
2020-03-12 17:02:16 +00:00
|
|
|
run: |
|
|
|
|
find debs -type f -name "*.deb" -exec sha256sum "{}" \; | sort -k2
|
2020-01-22 00:25:35 +00:00
|
|
|
- name: Store *.deb files
|
2022-03-30 02:50:03 +00:00
|
|
|
if: always()
|
2022-04-16 06:50:09 +00:00
|
|
|
uses: actions/upload-artifact@v3
|
2020-01-22 00:25:35 +00:00
|
|
|
with:
|
2022-04-16 06:50:09 +00:00
|
|
|
name: debs-${{ matrix.target_arch }}-${{ github.sha }}
|
2020-01-23 20:39:46 +00:00
|
|
|
path: ./artifacts
|
2021-09-20 15:59:32 +00:00
|
|
|
|
2020-01-22 00:25:35 +00:00
|
|
|
upload:
|
2022-10-06 21:24:05 +00:00
|
|
|
concurrency: ${{ github.workflow }}
|
2022-08-27 20:51:40 +00:00
|
|
|
permissions:
|
|
|
|
contents: read
|
2022-10-07 00:45:22 +00:00
|
|
|
if: github.event_name != 'pull_request'
|
2020-01-22 00:25:35 +00:00
|
|
|
needs: build
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
|
|
- name: Clone repository
|
2023-09-05 08:50:22 +00:00
|
|
|
uses: actions/checkout@v4
|
2020-01-22 00:25:35 +00:00
|
|
|
- name: Get *.deb files
|
2022-04-16 06:50:09 +00:00
|
|
|
uses: actions/download-artifact@v3
|
2020-01-22 00:25:35 +00:00
|
|
|
with:
|
2020-01-22 22:05:16 +00:00
|
|
|
path: ./
|
2022-06-18 17:06:53 +00:00
|
|
|
- name: Upload to packages.termux.dev
|
2021-06-02 21:16:03 +00:00
|
|
|
env:
|
2022-06-18 17:06:53 +00:00
|
|
|
REPOSITORY_URL: https://packages.termux.dev/aptly-api
|
2021-06-02 21:16:03 +00:00
|
|
|
run: |
|
2022-03-08 12:56:43 +00:00
|
|
|
GITHUB_SHA=${{ github.sha }}
|
|
|
|
APTLY_API_AUTH=${{ secrets.APTLY_API_AUTH }}
|
2022-03-13 12:44:05 +00:00
|
|
|
GPG_PASSPHRASE=${{ secrets.GPG_PASSPHRASE }}
|
2022-03-08 12:56:43 +00:00
|
|
|
|
|
|
|
source scripts/aptly_api.sh
|
|
|
|
|
2022-04-18 16:23:42 +00:00
|
|
|
for archive in debs-*/debs-{aarch64,arm,i686,x86_64}-${{ github.sha }}.tar; do
|
|
|
|
tar xf "$archive"
|
|
|
|
done
|
|
|
|
|
2023-08-30 20:40:08 +00:00
|
|
|
for repo in $(jq --raw-output 'del(.pkg_format) | keys | .[]' repo.json); do
|
2022-04-20 12:04:33 +00:00
|
|
|
export REPOSITORY_NAME=$(jq --raw-output '.["'$repo'"].name' repo.json)
|
|
|
|
export REPOSITORY_DISTRIBUTION=$(jq --raw-output '.["'$repo'"].distribution' repo.json)
|
2021-06-03 13:54:54 +00:00
|
|
|
|
2022-04-16 06:50:09 +00:00
|
|
|
# Upload file to temporary directory.
|
|
|
|
uploaded_files=false
|
|
|
|
shopt -s nullglob
|
2022-10-30 14:17:33 +00:00
|
|
|
|
2022-05-05 12:56:09 +00:00
|
|
|
if [ -f debs/built_${REPOSITORY_NAME}_packages.txt ]; then
|
|
|
|
for filename in $(cat debs/built_${REPOSITORY_NAME}_packages.txt | sed -E 's/(..*)/debs\/\1_\*.deb debs\/\1-static_\*.deb/g'); do
|
|
|
|
if ! aptly_upload_file "$filename"; then
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-06-03 14:38:57 +00:00
|
|
|
|
2022-05-05 12:56:09 +00:00
|
|
|
uploaded_files=true
|
|
|
|
done
|
|
|
|
shopt -u nullglob
|
2022-04-20 12:04:33 +00:00
|
|
|
|
2022-05-05 12:56:09 +00:00
|
|
|
# Publishing repository changes.
|
|
|
|
if [ "$uploaded_files" = "true" ]; then
|
|
|
|
if ! aptly_add_to_repo; then
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-10-07 11:49:01 +00:00
|
|
|
|
2022-05-05 12:56:09 +00:00
|
|
|
# Usually temporary directory is deleted automatically, but in certain cases it is left.
|
|
|
|
aptly_delete_dir
|
2021-06-03 14:38:57 +00:00
|
|
|
|
2022-05-05 12:56:09 +00:00
|
|
|
# Final part to make changes appear in web root.
|
|
|
|
if ! aptly_publish_repo; then
|
|
|
|
exit 1
|
|
|
|
fi
|
2022-04-16 06:50:09 +00:00
|
|
|
fi
|
2021-06-03 14:38:57 +00:00
|
|
|
fi
|
2022-04-16 06:50:09 +00:00
|
|
|
done
|