Skip to content

Instantly share code, notes, and snippets.

@Borda
Last active October 30, 2023 15:12
Show Gist options
  • Select an option

  • Save Borda/a09486b7e791c01eeca8e2da831fd7e1 to your computer and use it in GitHub Desktop.

Select an option

Save Borda/a09486b7e791c01eeca8e2da831fd7e1 to your computer and use it in GitHub Desktop.
Automated git-submodule updates via PR
name: Update git submodules
on:
pull_request:
branches: ["main"]
paths:
- ".github/workflows/ci-update-submodules.yml"
schedule:
# on Sundays
- cron: "0 0 * * 0"
workflow_dispatch: {}
jobs:
submodule-update:
runs-on: "ubuntu-22.04"
permissions:
contents: write
pull-requests: write
strategy:
fail-fast: false
matrix:
submodule: ["ABC"]
defaults:
run:
shell: bash
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0
- name: initial state
run: |
git submodule status
# starting from second char as the line starts with +
short_sha=$(git submodule status | grep -A 1 ${{ matrix.submodule }} | cut -c2-9)
echo "SHA_ACTUAL=$short_sha" >> $GITHUB_ENV
- name: update submodules
env:
# verbose for eventual debugging
GIT_TRACE: 1
run: |
git submodule sync
git submodule update --remote --force
- name: final state
run: |
git status
git submodule status
# starting from second char as the line starts with +
short_sha=$(git submodule status | grep -A 1 ${{ matrix.submodule }} | cut -c2-9)
echo "SHA_LATEST=$short_sha" >> $GITHUB_ENV
- name: Create Pull Request
# create PR with cron or dispatch if there is any change
if: ${{ github.event_name != 'pull_request' && env.SHA_ACTUAL != env.SHA_LATEST }}
uses: peter-evans/create-pull-request@v5
with:
title: "deps: update ref to latest ${{ matrix.submodule }}"
committer: GitHub <noreply@github.com>
author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com>
# when you want to update only one submodule
add-paths: ${{ matrix.submodule }}
commit-message: "update submodule to `${{ env.SHA_LATEST }}`"
branch: "bump/update-${{ matrix.submodule }}"
# Delete the branch when closing pull requests, and when undeleted after merging.
delete-branch: true
# the PR's body/content
body: "**This is automated update with the latest ${{ matrix.submodule }}!**"
labels: enhancement
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment