From 519ceb68136bc4a18ebd7912433c2d19f7eaddc6 Mon Sep 17 00:00:00 2001 From: David Bauer Date: Wed, 13 Dec 2023 07:12:31 +0100 Subject: [PATCH] github: add action for Gluon update Add a new Action which can be manually triggered to perform an update of the Gluon base of a given branch. This will automatically create a new branch, update the commit hash in build-info.json and create the appropriate PR. Signed-off-by: David Bauer --- .github/bump-gluon-commit-message.sh | 31 +++++++++ .github/workflows/bump-gluon.yml | 96 ++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100755 .github/bump-gluon-commit-message.sh create mode 100644 .github/workflows/bump-gluon.yml diff --git a/.github/bump-gluon-commit-message.sh b/.github/bump-gluon-commit-message.sh new file mode 100755 index 0000000..82e0824 --- /dev/null +++ b/.github/bump-gluon-commit-message.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +set -e + +repo_path="$1" +old_commit="$2" +new_commit="$3" + +# Check if all arguments are set, print usage otherwise +if [ -z "$repo_path" ] || [ -z "$old_commit" ] || [ -z "$new_commit" ]; then + echo "Usage: bump-gluon-commit-message.sh " + exit 1 +fi + +# Get short-ref of commits +old_commit_short="$(git -C "$repo_path" rev-parse --short "$old_commit")" +new_commit_short="$(git -C "$repo_path" rev-parse --short "$new_commit")" + +# Get commit date of new commit (YYYY-MM-DD) +new_commit_date="$(git -C "$repo_path" show -s --format=%cd --date=short "$new_commit")" + +# Get Git log of commit delta +commit_log="$(git -C "$repo_path" log --oneline --no-decorate "$old_commit".."$new_commit")" + +cat <> "$GITHUB_OUTPUT" + echo "short-hash=$(git -C $GLUON_CHECKOUT_DIR rev-parse --short ${{ github.event.inputs.gluon-commit }})" >> "$GITHUB_OUTPUT" + + - name: Get build-info.json commit hash + id: build-info-hash + run: | + echo "hash=$(jq -r '.gluon.commit' $BUILD_INFO)" >> "$GITHUB_OUTPUT" + echo "short-hash=$(jq -r '.gluon.commit' $BUILD_INFO | cut -c1-7)" >> "$GITHUB_OUTPUT" + + - name: Update commit-hash + if: steps.head-hash.outputs.hash != steps.build-info-hash.outputs.hash + run: >- + jq --arg commit_hash "${{ steps.head-hash.outputs.hash }}" + --indent 4 + '.gluon.commit = $commit_hash' + $BUILD_INFO > $BUILD_INFO_TMP + + - name: Update build-info.json + if: steps.head-hash.outputs.hash != steps.build-info-hash.outputs.hash + run: mv $BUILD_INFO_TMP $BUILD_INFO + + - name: Generate commit message + if: steps.head-hash.outputs.hash != steps.build-info-hash.outputs.hash + id: commit-message + run: | + echo "msg<> "$GITHUB_OUTPUT" + ./.github/bump-gluon-commit-message.sh $GLUON_CHECKOUT_DIR ${{ steps.build-info-hash.outputs.hash }} ${{ steps.head-hash.outputs.hash }} >> "$GITHUB_OUTPUT" + echo "EOF" >> "$GITHUB_OUTPUT" + + - name: Commit and push changes + if: steps.head-hash.outputs.hash != steps.build-info-hash.outputs.hash + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: ${{ steps.commit-message.outputs.msg }} + commit_options: '--no-verify --signoff' + commit_user_name: GitHub Actions + commit_user_email: info@darmstadt.freifunk.net + branch: bump-gluon-${{ steps.head-hash.outputs.short-hash }} + create_branch: true + + - name: Create pull request + if: steps.head-hash.outputs.hash != steps.build-info-hash.outputs.hash && github.event.inputs.skip-pull-request == 'false' + run: >- + gh pr create + -B ${{ github.event.inputs.site-branch }} + -H bump-gluon-${{ steps.head-hash.outputs.short-hash }} + --fill + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}