Update Submodules #8
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 | |
| on: | |
| workflow_dispatch: | |
| schedule: | |
| - cron: '0 2 * * *' | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| update-submodules: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| submodules: 'recursive' | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Configure Git | |
| run: | | |
| git config --global user.name "github-actions[bot]" | |
| git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
| - name: Update submodules to their latest default branch | |
| run: | | |
| echo "Updating submodules..." | |
| git submodule foreach --recursive ' | |
| git fetch origin | |
| if git rev-parse --verify origin/main > /dev/null 2>&1; then | |
| echo "Switching $name ($path) to origin/main" | |
| git checkout origin/main | |
| elif git rev-parse --verify origin/master > /dev/null 2>&1; then | |
| echo "Switching $name ($path) to origin/master" | |
| git checkout origin/master | |
| else | |
| echo "Could not find main or master branch for $name ($path). Submodule not updated." | |
| fi | |
| ' | |
| echo "Submodule update process complete." | |
| - name: Commit and push submodule updates | |
| run: | | |
| git add . | |
| if git diff --staged --quiet; then | |
| echo "No submodule changes to commit." | |
| else | |
| echo "Committing submodule updates..." | |
| git commit -m "ci: Update submodules to latest default branch (main/master)" | |
| echo "Pushing changes..." | |
| git push | |
| fi |