Update Submodules #13
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: Delete existing local branch if any | |
run: | | |
if git show-ref --verify --quiet refs/heads/update-submodules-branch; then | |
git branch -D update-submodules-branch | |
fi | |
- name: Update all submodules | |
id: update_submodules | |
run: | | |
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: Create a new branch for changes | |
if: steps.update_submodules.outputs.needs_update == 'true' | |
run: | | |
git checkout -b update-submodules-branch | |
- 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. |