Files
chromebrew/.github/workflows/Updater.yml
Satadru Pramanik, DO, MPH, MEng 02ce1e95ff Adjust workflows to improve automation and use PR template verbiage. (#10995)
* Adjust workflows to improve automation and use PR template verbiage.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

* Fix reversed package architecture logic.

Signed-off-by: Satadru Pramanik <satadru@gmail.com>

---------

Signed-off-by: Satadru Pramanik <satadru@gmail.com>
2024-12-17 19:39:44 +00:00

265 lines
11 KiB
YAML

---
name: Generate Updates PR
on:
schedule:
- cron: '0 0 * * *' # Daily
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:
update-check:
if: ${{ github.repository_owner == 'chromebrew' }}
runs-on: ubuntu-24.04
outputs:
output1: ${{ steps.set-variables.outputs.TIMESTAMP }} # https://stackoverflow.com/a/75142892
output2: ${{ steps.set-variables.outputs.UPDATE_BRANCH_NAME }}
steps:
- uses: actions/checkout@v4
with:
persist-credentials: true
- uses: ruby/setup-ruby@v1
with:
ruby-version: '3.3.6'
- name: Install Python pip
run: sudo apt install -y python3-pip
- name: Install activesupport
run: sudo apt install -y ruby-activesupport
- name: Set workflow & branch variables
id: set-variables
run: |
export TIMESTAMP="$(date -u +%F-%H-%M)"
export UPDATE_BRANCH_NAME="updates-${TIMESTAMP}"
echo "TIMESTAMP=${TIMESTAMP}" >> $GITHUB_OUTPUT
echo "UPDATE_BRANCH_NAME=${UPDATE_BRANCH_NAME}" >> $GITHUB_OUTPUT
- name: Git setup
env:
UPDATE_BRANCH_NAME: ${{ steps.set-variables.outputs.UPDATE_BRANCH_NAME }}
run: |
git pull && ( git checkout -b ${UPDATE_BRANCH_NAME} || git checkout ${UPDATE_BRANCH_NAME} )
- name: Check for updates in pip packages.
id: pip-update-checks
env:
UPDATE_BRANCH_NAME: ${{ steps.set-variables.outputs.UPDATE_BRANCH_NAME }}
run: |
tools/update_python_pip_packages.rb
# Create a new branch with the updated package files only
# if there are updated packages. Otherwise exit early.
if [ -n "$(git status --porcelain)" ]; then
echo "Python pip packages were updated."
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
git add -A
git commit -m "Add unbuilt updated pip packages to ${UPDATE_BRANCH_NAME}"
echo "PIP_UPDATED=true" >> $GITHUB_OUTPUT
else
echo "Python pip packages were not updated."
echo "PIP_UPDATED=false" >> $GITHUB_OUTPUT
fi
- name: Push pip package changes
if: ${{ steps.pip-update-checks.outputs.PIP_UPDATED == 'true' }}
uses: ad-m/github-push-action@master
with:
branch: ${{ steps.set-variables.outputs.UPDATE_BRANCH_NAME }}
- name: Check for updates in ruby gem packages.
id: gem-update-checks
env:
UPDATE_BRANCH_NAME: ${{ steps.set-variables.outputs.UPDATE_BRANCH_NAME }}
run: |
tools/update_ruby_gem_packages.rb
# Create a new branch with the updated package files only
# if there are updated packages. Otherwise exit early.
if [ -n "$(git status --porcelain)" ]; then
echo "Ruby gem packages were updated."
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
git add -A
git commit -m "Add unbuilt updated ruby gem packages to ${UPDATE_BRANCH_NAME}"
echo "GEM_UPDATED=true" >> $GITHUB_OUTPUT
else
echo "Ruby gem packages were not updated."
echo "GEM_UPDATED=false" >> $GITHUB_OUTPUT
fi
- name: Push ruby gem package changes
if: ${{ steps.gem-update-checks.outputs.GEM_UPDATED == 'true' }}
uses: ad-m/github-push-action@master
with:
branch: ${{ steps.set-variables.outputs.UPDATE_BRANCH_NAME }}
- name: Cancel if no updates
id: no-update-cancel
if: ${{ ( steps.pip-update-checks.outputs.PIP_UPDATED == 'false' ) && ( steps.gem-update-checks.outputs.GEM_UPDATED == 'false' ) }}
run: |
echo "PIP_UPDATED is ${{ steps.pip-update-checks.outputs.PIP_UPDATED }}."
echo "GEM_UPDATED is ${{ steps.gem-update-checks.outputs.GEM_UPDATED }}."
git checkout master && git branch -D ${{ steps.set-variables.outputs.UPDATE_BRANCH_NAME }} && git push
# https://stackoverflow.com/a/75809743
gh run cancel ${{ github.run_id }}
gh run watch ${{ github.run_id }}
generate:
strategy:
max-parallel: 1
matrix:
arch: [i686, x86_64, armv7l]
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: update-check
if: ${{ !cancelled() && github.repository_owner == 'chromebrew' }}
concurrency:
group: ${{ matrix.arch }}-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
steps:
- name: Build Container cleanup
run: |
sudo rm -rf release
- 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: "https://github.com/chromebrew/chromebrew.git"
CREW_REPO: "https://github.com/${{ github.repository }}.git"
CREW_BRANCH: ${{ needs.update-check.outputs.output2 }}
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 || true
sudo rm -rf release
- name: Add updated packages to PR.
id: push-check
env:
UPDATE_BRANCH_NAME: ${{ needs.update-check.outputs.output2 }}
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 updated packages for ${PLATFORM} to ${UPDATE_BRANCH_NAME}"
fi
- name: Push changes
uses: ad-m/github-push-action@master
with:
branch: ${{ needs.update-check.outputs.output2 }}
build-check:
runs-on: ubuntu-24.04
needs:
- update-check
- generate
if: ${{ !cancelled() && github.repository_owner == 'chromebrew' }}
steps:
- name: fail if update or build jobs failed, otherwise create a PR
if: ${{ contains(needs.*.result, 'failure') }}
run: exit 1
- name: Report update & build success
run: echo "Update & build jobs succeeded. Creating a PR."
- uses: actions/checkout@v4
with:
clean: false
persist-credentials: true
ref: ${{ needs.update-check.outputs.output2 }}
- name: Get all changed package files
id: changed-ruby-files
uses: tj-actions/changed-files@v45
with:
base_sha: master
files: packages/*.rb
since_last_remote_commit: true
- name: Export variables to github context
run: |
# Convert "packages/foo.rb packages/bar.rb" (from steps.changed-ruby-files.outputs.all_changed_files) into "foo bar"
echo "CHANGED_PACKAGES=$(echo "${{ steps.changed-ruby-files.outputs.all_changed_files }}" | xargs basename -s .rb | xargs)" >> $GITHUB_ENV
- name: Create Pull Request
env:
CREW_BRANCH: ${{ github.ref_name }}
run: |
echo -e "Updated packages:" > /tmp/pr.txt
for file in ${CHANGED_PACKAGES}
do
echo "- ${file}" >> /tmp/pr.txt
done
cat /tmp/pr.txt
export PR_NUMBER=$(gh pr create --title "AutoBuild: ${{ github.ref_name }} started at ${{ 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: Create Pull Request
env:
TIMESTAMP: ${{ needs.update-check.outputs.output1 }}
CREW_BRANCH: ${{ needs.update-check.outputs.output2 }}
run: |
echo -e "Updated packages:" > /tmp/pr.txt
for file in ${CHANGED_PACKAGES}
do
echo "- ${file}" >> /tmp/pr.txt
done
cat /tmp/pr.txt
export PR_NUMBER=$(gh pr create --title "AutoUpdate: ${{ github.ref_name }} started at ${TIMESTAMP}" -F /tmp/pr.txt | rev | cut -d"/" -f1 | rev)
echo "PR_NUMBER is ${PR_NUMBER}"
echo "PR_NUMBER=${PR_NUMBER}" >> $GITHUB_ENV
${CREW_BRANCH}" -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 & Add Reviewer Team
env:
GH_TOKEN: ${{ secrets.CREW_PR_TOKEN }}
run: |
echo "Flipping pr ${PR_NUMBER} state."
gh pr close ${PR_NUMBER} && gh pr reopen ${PR_NUMBER}
gh pr edit ${PR_NUMBER} --add-reviewer chromebrew/active