From d2014365d54863f36c6bc14ed96b0ee65aad70d2 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 23 Sep 2024 09:49:58 +0200 Subject: [PATCH] workflow: rework module bump Script (#482) * workflow: prepare for new bump Script * backport Gluon modules Updater Co-authored-by: Martin Weinelt * fix cd in basedir * remove branch switch as Github Actions need to do this * fix: spelling * fix: loop use gluon site feeds for the loop Co-authored-by: Grische <2787581+grische@users.noreply.github.com> * fix SC2086 * Update: make genereated by smaller * add labels, darf, delete-branch * configure git (user and e-mail); Update PR Titel * fix branch name --------- Co-authored-by: Martin Weinelt Co-authored-by: Grische <2787581+grische@users.noreply.github.com> (cherry picked from commit a2afe4c03685258aa87344d00f2936908b1ec051) Co-authored-by: Tobias <5702338+T0biii@users.noreply.github.com> --- .github/workflows/bump-modules.yml | 50 ++++++++++++++++++++++++ contrib/actions/update-modules.sh | 63 ++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 .github/workflows/bump-modules.yml create mode 100755 contrib/actions/update-modules.sh diff --git a/.github/workflows/bump-modules.yml b/.github/workflows/bump-modules.yml new file mode 100644 index 00000000..ab260710 --- /dev/null +++ b/.github/workflows/bump-modules.yml @@ -0,0 +1,50 @@ +--- +name: "Update Modules base" + +on: + workflow_dispatch: + +permissions: + contents: write # so it can comment + pull-requests: write # so it can create pull requests + +jobs: + update-Modules: + runs-on: ubuntu-22.04 + env: + COMMIT_NAME: github-actions[bot] + COMMIT_EMAIL: 41898282+github-actions[bot]@users.noreply.github.com + steps: + - name: Clone Firmware + uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 + + - name: Configure Git User and E-Mail + run: git config --global user.name "${{ env.COMMIT_NAME }}" && git config --global user.email "${{ env.COMMIT_EMAIL }}" + + - name: Get update branch name + id: branch-name + run: echo "branch-name=update-modules-${{ github.ref_name }}-$(date +%s)" >> $GITHUB_OUTPUT + + - name: Invoke update-modules + run: ./contrib/actions/update-modules.sh + + - name: Create Pull Request + id: cpr + uses: peter-evans/create-pull-request@c5a7806660adbe173f04e3e038b0ccdcd758773c # v6.1.0 + with: + title: '[${{ github.ref_name }}] update modules' + body: | + Update modules for ${{ github.ref_name }} branch + - Auto-generated by [create-pull-request][1] + + [1]: https://github.com/peter-evans/create-pull-request + branch: ${{ steps.branch-name.outputs.branch-name }} + labels: ${{ github.ref_name }} + draft: true # this step does not trigger a CI run, so always mark them as draft + delete-branch: true + + - name: Check outputs + if: ${{ steps.cpr.outputs.pull-request-number }} + run: | + echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}" + echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}" diff --git a/contrib/actions/update-modules.sh b/contrib/actions/update-modules.sh new file mode 100755 index 00000000..bd2bfdcc --- /dev/null +++ b/contrib/actions/update-modules.sh @@ -0,0 +1,63 @@ +#!/usr/bin/env bash + +set -eo pipefail + +# move to basedir, in case the script is not executed via `make update-modules` +cd "$(dirname "$0")/../.." || exit 1 + +# shellcheck source=./modules +source ./modules + +git diff --quiet ./modules || { + 1>&2 echo "Your modules file is dirty, aborting." + exit 1 +} + + +for MODULE in ${GLUON_SITE_FEEDS}; do + _REMOTE_URL=PACKAGES_${MODULE^^}_REPO + _REMOTE_BRANCH=PACKAGES_${MODULE^^}_BRANCH + _LOCAL_HEAD=PACKAGES_${MODULE^^}_COMMIT + + REMOTE_URL="${!_REMOTE_URL}" + REMOTE_BRANCH="${!_REMOTE_BRANCH}" + LOCAL_HEAD="${!_LOCAL_HEAD}" + + # get default branch name if none is set + [ -z "${REMOTE_BRANCH}" ] && { + REMOTE_BRANCH=$(git ls-remote --symref "${REMOTE_URL}" HEAD | awk '/^ref:/ { sub(/refs\/heads\//, "", $2); print $2 }') + } + + # fetch the commit id for the HEAD of the module + REMOTE_HEAD=$(git ls-remote "${REMOTE_URL}" "${REMOTE_BRANCH}" | awk '{ print $1 }') + + # skip ahead if the commit id did not change + [ "$LOCAL_HEAD" == "$REMOTE_HEAD" ] && continue 1 + + + + CHECKOUT=$(mktemp -d) + + # clone the target branch + git clone --bare "${REMOTE_URL}" --branch="${REMOTE_BRANCH}" "${CHECKOUT}" + + # prepare the commit message + # shellcheck disable=SC2001 + MODULE=$(echo "${MODULE,,}" | sed 's/packages_//') + TITLE="modules: update ${MODULE}" + MESSAGE="$(mktemp)" + { + echo "${TITLE}" + printf '\n\n' + git -C "${CHECKOUT}" log --oneline --no-decorate --no-merges "${LOCAL_HEAD}..${REMOTE_HEAD}" | cat + } > "$MESSAGE" + + # modify modules file + sed -i "s/${LOCAL_HEAD}/${REMOTE_HEAD}/" ./modules + git add ./modules + + git commit -F "${MESSAGE}" + + # remove the checkout + rm -fr "${CHECKOUT}" +done