mirror of
https://github.com/termux-pacman/termux-packages.git
synced 2025-12-22 03:30:17 +00:00
packages.yml: algorithm update (#125)
This commit is contained in:
94
.github/workflows/packages.yml
vendored
94
.github/workflows/packages.yml
vendored
@@ -44,19 +44,27 @@ jobs:
|
||||
run: |
|
||||
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")
|
||||
# We are intentionally not using .commits[0].id and .commits[-1].id as github seems to
|
||||
# only send 20 commits in the payload for github action runs instead of the 2048 documented
|
||||
# limit. Perhaps 2048 is the limit just for webhooks, where they haven't documented
|
||||
# properly that the limit for github actions is only 20:
|
||||
#
|
||||
# https://docs.github.com/en/webhooks/webhook-events-and-payloads#push
|
||||
OLD_COMMIT=$(jq --raw-output .before "$GITHUB_EVENT_PATH")
|
||||
HEAD_COMMIT=$(jq --raw-output .after "$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}")
|
||||
if ! git log "$OLD_COMMIT" 2> /dev/null; then
|
||||
if [ "$(git branch --show-current)" = "master" ]; then
|
||||
echo "Force push detected on master branch. Unable to proceed."
|
||||
exit 1
|
||||
else
|
||||
# Multi-commit push.
|
||||
OLD_COMMIT="${OLD_COMMIT}~1"
|
||||
echo "::warning:: Force push detected on non-master branch. Trying to proceed at any cost but may not work as expected."
|
||||
OLD_COMMIT=$(jq --raw-output .commits[0].id "$GITHUB_EVENT_PATH")
|
||||
echo "::warning:: OLD_COMMIT is set to $OLD_COMMIT which may not be correct if you have pushed more than 20 commits."
|
||||
fi
|
||||
fi
|
||||
echo "Processing commit range: ${OLD_COMMIT}..${HEAD_COMMIT}"
|
||||
CHANGED_FILES=$(git diff-tree --no-commit-id --name-only -r "${OLD_COMMIT}" "${HEAD_COMMIT}")
|
||||
fi
|
||||
else
|
||||
# Pull requests.
|
||||
echo "Processing pull request #$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH"): ${BASE_COMMIT}..HEAD"
|
||||
@@ -67,9 +75,11 @@ jobs:
|
||||
touch ./pkgs/.placeholder
|
||||
|
||||
if [ "${{ github.event_name }}" != "workflow_dispatch" ]; then
|
||||
# GitHub sometimes add merge commits at the end
|
||||
# To prevent user confusion, filter them with --no-merges
|
||||
# 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
|
||||
if grep -qiP '^\s*%ci:no-build\s*$' <(git log --format="%B" -n 1 --no-merges "HEAD"); then
|
||||
tar cf artifacts/pkgs-${{ matrix.target_arch }}.tar pkgs
|
||||
echo "docker-build=true" >> $GITHUB_OUTPUT
|
||||
echo "[!] Force exiting as tag '%ci:no-build' was applied to HEAD commit message."
|
||||
@@ -149,18 +159,26 @@ jobs:
|
||||
fi
|
||||
done
|
||||
|
||||
declare -a packages
|
||||
declare -a packages=()
|
||||
for repo_path in $(jq --raw-output 'del(.pkg_format) | keys | .[]' repo.json); do
|
||||
repo=$(jq --raw-output '.["'${repo_path}'"].name' repo.json)
|
||||
if [ -f ./built_${repo}_packages.txt ]; then
|
||||
packages="$packages $(cat ./built_${repo}_packages.txt | tr '\n' ' ')"
|
||||
if [ -f "./built_${repo}_packages.txt" ]; then
|
||||
packages+=($(cat "./built_${repo}_packages.txt"))
|
||||
fi
|
||||
done
|
||||
|
||||
echo "packages: ${packages[*]}"
|
||||
|
||||
docker='true'
|
||||
[ -n "$packages" ] && if grep -qP "(^|\\s)${packages// /($|\\s)|(^|\\s)}($|\\s)" ./scripts/big-pkgs.list; then
|
||||
if [[ "${#packages[@]}" -gt 0 ]]; then
|
||||
for pkg in "${packages[@]}"; do
|
||||
if grep -qFx "$pkg" ./scripts/big-pkgs.list; then
|
||||
docker='false'
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
echo "docker-build=$docker" >> $GITHUB_OUTPUT
|
||||
if [ "${{ github.event_name }}" != "workflow_dispatch" ]; then
|
||||
# Build local Docker image if setup scripts were changed.
|
||||
@@ -179,56 +197,48 @@ jobs:
|
||||
|
||||
- name: Lint packages
|
||||
run: |
|
||||
declare -a package_recipes
|
||||
declare -a package_recipes=()
|
||||
for repo_path in $(jq --raw-output 'del(.pkg_format) | keys | .[]' repo.json); do
|
||||
repo=$(jq --raw-output '.["'${repo_path}'"].name' repo.json)
|
||||
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"}')"
|
||||
if [ -f "./built_${repo}_packages.txt" ]; then
|
||||
package_recipes+=($(cat "./built_${repo}_packages.txt" | repo_path="${repo_path}" awk '{print ENVIRON["repo_path"]"/"$1"/build.sh"}'))
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ! -z "$package_recipes" ]; then
|
||||
./scripts/lint-packages.sh $package_recipes
|
||||
if [[ "${#package_recipes[@]}" -gt 0 ]]; then
|
||||
./scripts/lint-packages.sh "${package_recipes[@]}"
|
||||
fi
|
||||
|
||||
- name: Free additional disk space (if needed)
|
||||
env:
|
||||
DOCKER_BUILD: ${{ steps.build-info.outputs.docker-build }}
|
||||
run: |
|
||||
declare -a packages
|
||||
for repo_path in $(jq --raw-output 'del(.pkg_format) | keys | .[]' repo.json); do
|
||||
repo=$(jq --raw-output '.["'${repo_path}'"].name' repo.json)
|
||||
if [ -f ./built_${repo}_packages.txt ]; then
|
||||
packages="$packages $(cat ./built_${repo}_packages.txt | tr '\n' ' ')"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$DOCKER_BUILD" == 'false' ]; then
|
||||
./scripts/setup-ubuntu.sh
|
||||
sudo apt install ninja-build
|
||||
sudo apt purge -yq $(dpkg -l | grep '^ii' | awk '{ print $2 }' | grep -P '(aspnetcore|cabal-|dotnet-|ghc-|libmono|mongodb-|mysql-|php)') \
|
||||
firefox google-chrome-stable microsoft-edge-stable mono-devel mono-runtime-common monodoc-manual ruby
|
||||
sudo apt autoremove -yq
|
||||
sudo apt clean
|
||||
sudo rm -fr /opt/ghc /opt/hostedtoolcache /usr/lib/node_modules /usr/local/share/boost /usr/share/dotnet /usr/share/swift
|
||||
./scripts/free-space.sh
|
||||
fi
|
||||
|
||||
- name: Build packages
|
||||
env:
|
||||
DOCKER_BUILD: ${{ steps.build-info.outputs.docker-build }}
|
||||
run: |
|
||||
declare -a packages
|
||||
declare -a packages=()
|
||||
for repo_path in $(jq --raw-output 'del(.pkg_format) | keys | .[]' repo.json); do
|
||||
repo=$(jq --raw-output '.["'${repo_path}'"].name' repo.json)
|
||||
if [ -f ./built_${repo}_packages.txt ]; then
|
||||
packages="$packages $(cat ./built_${repo}_packages.txt | tr '\n' ' ')"
|
||||
if [ -f "./built_${repo}_packages.txt" ]; then
|
||||
packages+=($(cat "./built_${repo}_packages.txt"))
|
||||
fi
|
||||
done
|
||||
|
||||
echo "packages: ${packages[*]}"
|
||||
|
||||
if [[ "${#packages[@]}" -gt 0 ]]; then
|
||||
if [ "$DOCKER_BUILD" == 'false' ]; then
|
||||
NDK=$ANDROID_NDK ANDROID_HOME=$ANDROID_SDK_ROOT ./build-package.sh --format pacman -I -C -a ${{ matrix.target_arch }} $packages
|
||||
elif [ -n "$packages" ]; then
|
||||
./scripts/run-docker.sh ./build-package.sh --format pacman -I -C -a ${{ matrix.target_arch }} $packages
|
||||
NDK="$ANDROID_NDK" ANDROID_HOME="$ANDROID_SDK_ROOT" ./build-package.sh --format pacman -I -C -a "${{ matrix.target_arch }}" "${packages[@]}"
|
||||
else
|
||||
./scripts/run-docker.sh ./build-package.sh --format pacman -I -C -a "${{ matrix.target_arch }}" "${packages[@]}"
|
||||
fi
|
||||
fi
|
||||
|
||||
- name: Generate build artifacts
|
||||
@@ -246,10 +256,12 @@ jobs:
|
||||
|
||||
# Move only pkgs from built_packages into pkgs/ folder before
|
||||
# creating an archive.
|
||||
if [ -f "./pkgs/built_${repo}_packages.txt" ] && [ -d "output" ]; then
|
||||
while read -r pkg; do
|
||||
# Match both $pkg.pkg.* and $pkg-static.pkg.*.
|
||||
find output \( -name "$pkg-*.pkg.*" -o -name "$pkg-static-*.pkg.*" \) -type f -print0 | xargs -0r mv -t pkgs/
|
||||
done < <(cat ./pkgs/built_${repo}_packages.txt)
|
||||
# Match both $pkg*.pkg.* and $pkg-static*.pkg.*
|
||||
find output \( -name "$pkg_*.pkg.*" -o -name "$pkg-static_*.pkg.*" \) -type f -print0 | xargs -0r mv -t pkgs/
|
||||
done < <(cat "./pkgs/built_${repo}_packages.txt")
|
||||
fi
|
||||
done
|
||||
|
||||
# Files containing certain symbols (e.g. ":") will cause failure in actions/upload-artifact.
|
||||
|
||||
Reference in New Issue
Block a user