Update submodules to latest main branch #171
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Update submodules to latest main branch | |
| on: | |
| workflow_dispatch: | |
| schedule: | |
| - cron: '0 6 * * *' # 06:00 UTC daily — after the mirror job (05:30 UTC) | |
| jobs: | |
| update-submodules: | |
| runs-on: self-hosted | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| steps: | |
| - name: Checkout fork repo (main) | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| ref: main | |
| submodules: recursive | |
| token: ${{ secrets.EURO_OFFICE_MIRROR_TOKEN }} | |
| fetch-depth: 0 | |
| - name: Configure git identity | |
| run: | | |
| git config user.name "Euro-Office via GitHub Actions" | |
| git config user.email "actions@github.com" | |
| - name: Advance each submodule to latest default-branch commit | |
| run: | | |
| set -euo pipefail | |
| BODY="$RUNNER_TEMP/pr-body.md" | |
| { | |
| echo "Automated nightly submodule bump." | |
| echo | |
| echo "Updates each submodule to the latest commit on its tracking branch." | |
| echo | |
| } > "$BODY" | |
| # Enumerate every submodule from .gitmodules so none are missed. | |
| mapfile -t paths < <(git config -f .gitmodules --get-regexp '^submodule\..*\.path$' | awk '{print $2}') | |
| for path in "${paths[@]}"; do | |
| if [ ! -d "$path" ]; then | |
| echo "Skipping $path — directory not found" | |
| continue | |
| fi | |
| pushd "$path" > /dev/null | |
| old_sha="$(git rev-parse HEAD)" | |
| git fetch origin | |
| # Resolve the remote's actual default branch (HEAD), falling back to main. | |
| git remote set-head origin --auto > /dev/null 2>&1 || true | |
| branch="$(git symbolic-ref --short refs/remotes/origin/HEAD 2>/dev/null | sed 's@^origin/@@')" | |
| [ -z "$branch" ] && branch="main" | |
| echo "Updating $path → $branch" | |
| git checkout "$branch" | |
| git reset --hard "origin/$branch" | |
| new_sha="$(git rev-parse HEAD)" | |
| if [ "$old_sha" != "$new_sha" ]; then | |
| count="$(git rev-list --count "$old_sha..$new_sha")" | |
| { | |
| echo "### $path ($branch) — $count new commit(s)" | |
| echo | |
| echo '```' | |
| git log --no-merges --pretty=format:'%h %s' "$old_sha..$new_sha" | |
| echo | |
| echo '```' | |
| echo | |
| } >> "$BODY" | |
| fi | |
| popd > /dev/null | |
| done | |
| - name: Open PR if submodule pointers changed | |
| uses: peter-evans/create-pull-request@22a9089034f40e5a961c8808d113e2c98fb63676 # v7.0.11 | |
| with: | |
| token: ${{ secrets.EURO_OFFICE_MIRROR_TOKEN }} | |
| branch: chore/nightly-submodule-bump | |
| base: main | |
| delete-branch: true | |
| author: "Euro-Office via GitHub Actions <actions@github.com>" | |
| committer: "Euro-Office via GitHub Actions <actions@github.com>" | |
| commit-message: | | |
| chore: update submodules to latest main branch | |
| Signed-off-by: Euro-Office via GitHub Actions <actions@github.com> | |
| title: "chore: update submodules to latest main branch" | |
| body-path: ${{ runner.temp }}/pr-body.md |