mirror of
https://github.com/chromebrew/chromebrew.git
synced 2026-01-09 15:37:56 -05:00
200 lines
7.6 KiB
YAML
200 lines
7.6 KiB
YAML
---
|
|
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: [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: setup
|
|
if: ${{ !cancelled() }}
|
|
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: Dump GitHub context
|
|
env:
|
|
GITHUB_CONTEXT: ${{ toJson(github) }}
|
|
run: echo "$GITHUB_CONTEXT"
|
|
- name: Dump job context
|
|
env:
|
|
JOB_CONTEXT: ${{ toJson(job) }}
|
|
run: echo "$JOB_CONTEXT"
|
|
- name: Dump steps context
|
|
env:
|
|
STEPS_CONTEXT: ${{ toJson(steps) }}
|
|
run: echo "$STEPS_CONTEXT"
|
|
- name: Dump runner context
|
|
env:
|
|
RUNNER_CONTEXT: ${{ toJson(runner) }}
|
|
run: echo "$RUNNER_CONTEXT"
|
|
- name: Dump strategy context
|
|
env:
|
|
STRATEGY_CONTEXT: ${{ toJson(strategy) }}
|
|
run: echo "$STRATEGY_CONTEXT"
|
|
- name: Dump matrix context
|
|
env:
|
|
MATRIX_CONTEXT: ${{ toJson(matrix) }}
|
|
run: echo "$MATRIX_CONTEXT"
|
|
- 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 || true
|
|
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 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: ${{ github.ref_name }}
|
|
- name: Rebase to Master
|
|
run: |
|
|
git config user.name "${{ github.actor }}"
|
|
git config user.email "${{ github.actor }}@users.noreply.github.com"
|
|
git fetch --shallow-since="1 week"
|
|
git pull origin master --merge
|
|
git commit -m "Merge master into ${{ github.ref_name }}."
|
|
- name: Push rebase
|
|
uses: ad-m/github-push-action@master
|
|
with:
|
|
branch: ${{ 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'
|
|
git fetch --shallow-since="1 week"
|
|
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
|
|
# Close and reopen PR to try to automatically trigger
|
|
# unit test workflow.
|
|
gh pr close ${PR_NUMBER}
|
|
gh pr reopen ${PR_NUMBER}
|
|
- name: Trigger Unit Test workflow.
|
|
run: |
|
|
gh workflow run "Unit-Test.yml" --ref ${{ github.ref_name }}
|