Update Submodules #15
This file contains 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 | |
on: | |
schedule: | |
- cron: '0 0 * * 0' | |
workflow_dispatch: | |
jobs: | |
update_submodules: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
submodules: true | |
- name: Set up Git | |
run: | | |
git config --global user.name 'github-actions[bot]' | |
git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
- name: Get default branch | |
id: default_branch | |
run: echo "::set-output name=branch::$(git rev-parse --abbrev-ref origin/HEAD | sed 's@^origin/@@')" | |
- name: Checkout default branch | |
run: git checkout ${{ steps.default_branch.outputs.branch }} | |
- name: Clean up old branches | |
run: | | |
git fetch --all | |
git branch -r | grep -v '\->' | grep -v 'origin/HEAD' | sed 's/origin\///' | xargs -n 1 git branch -D || true | |
- name: Create or update submodules branch | |
id: update_submodules | |
run: | | |
git fetch origin | |
git checkout -B update-submodules-branch origin/update-submodules-branch || git checkout -b update-submodules-branch | |
git submodule update --init --remote | |
if [ -n "$(git status --porcelain)" ]; then | |
echo "Submodule updates found" | |
echo "::set-output name=needs_update::true" | |
else | |
echo "No submodule updates found" | |
echo "::set-output name=needs_update::false" | |
fi | |
- name: Commit and push changes | |
if: steps.update_submodules.outputs.needs_update == 'true' | |
run: | | |
git add . | |
git commit -m "Update submodules to latest commits" | |
git push origin update-submodules-branch --force | |
- name: Create or update Pull Request | |
if: steps.update_submodules.outputs.needs_update == 'true' | |
uses: peter-evans/create-pull-request@v5 | |
with: | |
commit-message: Update submodules | |
committer: github-actions[bot] <github-actions[bot]@users.noreply.github.com> | |
author: github-actions[bot] <github-actions[bot]@users.noreply.github.com> | |
branch: update-submodules-branch | |
base: ${{ steps.default_branch.outputs.branch }} | |
title: Update Submodules | |
body: This pull request updates all submodules to their latest commits. |