Add workflow for building arbitrary packages. (#10825)

Signed-off-by: Satadru Pramanik <satadru@gmail.com>
This commit is contained in:
Satadru Pramanik, DO, MPH, MEng
2024-11-29 15:35:38 -05:00
committed by GitHub
parent 166b3fcbc0
commit 74b504ce93
2 changed files with 169 additions and 4 deletions

164
.github/workflows/Build.yml vendored Normal file
View File

@@ -0,0 +1,164 @@
---
name: Build Updates & Generate PR
on:
workflow_dispatch:
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} # setting GH_TOKEN for the entire workflow
permissions: # Global permissions configuration starts here
actions: write
contents: write
packages: write
pull-requests: write # 'write' access to pull requests
jobs:
setup:
if: ${{ ( github.repository_owner == 'chromebrew' ) && ( github.ref_name != 'master' ) }}
runs-on: ubuntu-24.04
outputs:
output1: ${{ steps.set-variables.outputs.TIMESTAMP }} # https://stackoverflow.com/a/75142892
steps:
- uses: actions/checkout@v4
with:
persist-credentials: true
- name: Set workflow & branch variables
id: set-variables
run: |
export TIMESTAMP="$(date -u +%F-%H-%M)"
echo "TIMESTAMP=${TIMESTAMP}" >> $GITHUB_OUTPUT
generate:
strategy:
max-parallel: 1
matrix:
arch: [x86_64, armv7l, i686]
runner:
- [self-hosted, X64]
- [self-hosted, ARM]
exclude:
- arch: x86_64
runner: [self-hosted, ARM]
- arch: i686
runner: [self-hosted, ARM]
- arch: armv7l
runner: [self-hosted, X64]
runs-on: ${{ matrix.runner }}
needs: setup
if: ${{ !cancelled() }}
concurrency:
group: ${{ matrix.arch }}-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
steps:
- uses: actions/checkout@v4
with:
persist-credentials: true
- name: Export target docker container to github context
env:
TARGET_ARCH: ${{ matrix.arch }}
run: |
case $TARGET_ARCH in
x86_64)
echo "CONTAINER=nocturne-x86_64.m90" >> $GITHUB_ENV
echo "PLATFORM=linux/amd64" >> $GITHUB_ENV
echo "LIB_SUFFIX=64" >> $GITHUB_ENV
;;
armv7l)
echo "CONTAINER=fievel-armv7l.m91" >> $GITHUB_ENV
echo "PLATFORM=linux/arm/v7" >> $GITHUB_ENV
echo "LIB_SUFFIX=" >> $GITHUB_ENV
;;
i686)
echo "CONTAINER=alex-i686.m58" >> $GITHUB_ENV
echo "PLATFORM=linux/386" >> $GITHUB_ENV
echo "LIB_SUFFIX=" >> $GITHUB_ENV
;;
esac
- name: Run Updater in container
id: run-updater
if: ${{ !cancelled() }}
env:
CREW_REPO: github.event.repository.clone_url
CREW_BRANCH: github.ref_name
run: |
git pull && git checkout ${CREW_BRANCH}
docker pull --platform ${PLATFORM} satmandu/crewbuild:${CONTAINER}
sudo apt install -y acl
sudo setfacl -R -m u:1000:rwx .
# getfacl .
# Use docker-in-docker shim to mount volume inside docker.
# docker run --rm -v /var/run/docker.sock:/var/run/docker.sock \
# ghcr.io/felipecrs/dond-shim:latest \
(cd /tmp ; curl -OLf https://github.com/felipecrs/docker-on-docker-shim/raw/refs/tags/v0.7.1/dond ; chmod +x /tmp/dond )
# docker run \
/tmp/dond run \
--rm \
--platform ${PLATFORM} \
--privileged \
-u chronos \
-e LD_LIBRARY_PATH="/usr/local/lib${LIB_SUFFIX}" \
-e GCONV_PATH="/usr/local/lib${LIB_SUFFIX}/gconv" \
-e CREW_REPO="${CREW_REPO}" \
-e CREW_BRANCH="${CREW_BRANCH}" \
-e GITLAB_TOKEN="${{ secrets.GITLAB_TOKEN }}" \
-e GITLAB_TOKEN_USERNAME="${{ secrets.GITLAB_TOKEN_USERNAME }}" \
-v $(pwd):/output \
"satmandu/crewbuild:${CONTAINER}" \
/bin/chromebrewstart /output/tools/github_actions_update_builder.sh > >(tee -a /tmp/build.log) 2> >(tee -a /tmp/build.log >&2)
grep "Built and Uploaded:" /tmp/build.log
sudo rm -rf release
- name: Add updated packages to PR.
id: push-check
env:
UPDATE_BRANCH_NAME: github.ref_name
run: |
if [ -n "$(git status --porcelain)" ]; then
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
git add -A
git commit -m "Add built packages for ${PLATFORM} to ${{ github.ref_name }}"
fi
- name: Push changes
uses: ad-m/github-push-action@master
with:
branch: github.ref_name
build-check:
runs-on: ubuntu-24.04
needs:
- setup
- generate
if: ${{ !cancelled() }}
steps:
- name: fail if update jobs failed, otherwise create a PR
if: ${{ contains(needs.*.result, 'failure') }}
run: exit 1
- name: Report build success
run: echo "Update jobs succeeded. Creating a PR."
- uses: actions/checkout@v4
with:
clean: false
persist-credentials: true
ref: github.ref_name
- name: Create Pull Request
env:
CREW_BRANCH: github.ref_name
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com'
mapfile -t updated_package_array < <( git diff-tree --no-commit-id --name-only -r $(git rev-parse origin/master)..$(git rev-parse --verify HEAD) | grep -v manifest | grep "^packages" | sed -e 's,packages/,,' -e 's,.rb,,')
echo -e "Updated packages:" > /tmp/pr.txt
for file in "${updated_package_array[@]}"
do
echo "- ${file}" >> /tmp/pr.txt
done
cat /tmp/pr.txt
export PR_NUMBER=$(gh pr create --title "Automatic PR to build packages for ${{ github.ref_name }} on ${{ needs.setup.outputs.output1 }}" -F /tmp/pr.txt | rev | cut -d"/" -f1 | rev)
echo "PR_NUMBER is ${PR_NUMBER}"
echo "PR_NUMBER=${PR_NUMBER}" >> $GITHUB_ENV
- name: Trigger Unit Test workflow.
run: |
gh workflow run "Unit-Test.yml" --ref ${{ github.ref_name }}
- name: Add active team reviewers to PR
run: |
curl -X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}"\
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos${{ github.owner }}/${{ github.repository }}/pulls/${PR_NUMBER}/requested_reviewers \
-d '{"team_reviewers":["active"]}'

View File

@@ -213,17 +213,18 @@ jobs:
ref: ${{ needs.update-check.outputs.output2 }}
- name: Create Pull Request
env:
TIMESTAMP: ${{ needs.update-check.outputs.output1 }}
CREW_BRANCH: ${{ needs.update-check.outputs.output2 }}
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email '41898282+github-actions[bot]@users.noreply.github.com'
git fetch --depth=5
# Add some debugging...
git log --oneline | grep $CREW_BRANCH
git log --oneline | grep $CREW_BRANCH | tail -n 1 | awk '{print $1}'
git log --oneline | grep ${TIMESTAMP}
git log --oneline | grep ${TIMESTAMP} | tail -n 1 | awk '{print $1}'
git rev-parse --verify HEAD
git diff-tree --no-commit-id --name-only -r $(git log --oneline | grep $CREW_BRANCH | tail -n 1 | awk '{print $1}')..$(git rev-parse --verify HEAD)
mapfile -t updated_package_array < <( git diff-tree --no-commit-id --name-only -r $(git log --oneline | grep $CREW_BRANCH | tail -n 1 | awk '{print $1}')..$(git rev-parse --verify HEAD) | grep -v manifest | grep "^packages" | sed -e 's,packages/,,' -e 's,.rb,,')
git diff-tree --no-commit-id --name-only -r $(git log --oneline | grep ${TIMESTAMP} | tail -n 1 | awk '{print $1}')..$(git rev-parse --verify HEAD)
mapfile -t updated_package_array < <( git diff-tree --no-commit-id --name-only -r $(git log --oneline | grep ${TIMESTAMP} | tail -n 1 | awk '{print $1}')..$(git rev-parse --verify HEAD) | grep -v manifest | grep "^packages" | sed -e 's,packages/,,' -e 's,.rb,,')
echo -e "Updated packages:" > /tmp/pr.txt
for file in "${updated_package_array[@]}"
do