Update Submodules #2
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: | |
| schedule: | |
| - cron: "0 0 1 * *" # First day of every month at midnight UTC | |
| workflow_dispatch: # Manual trigger option | |
| permissions: | |
| contents: write | |
| jobs: | |
| update: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| submodules: false | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Initialize and update submodules | |
| run: | | |
| # Sync submodule URLs from .gitmodules | |
| git submodule sync --recursive || true | |
| # Try to initialize and update submodules normally | |
| # If a submodule commit doesn't exist, we'll handle it below | |
| git submodule update --init --recursive 2>&1 | tee /tmp/submodule-update.log || true | |
| # For any submodules that failed due to missing commits, checkout default branch | |
| if grep -q "not our ref\|did not contain" /tmp/submodule-update.log; then | |
| echo "Some submodules failed, attempting to fix..." | |
| git submodule foreach --recursive ' | |
| if ! git rev-parse --verify HEAD >/dev/null 2>&1; then | |
| echo "Fixing $name..." | |
| git fetch origin || true | |
| git checkout origin/HEAD 2>/dev/null || git checkout origin/main 2>/dev/null || git checkout origin/master 2>/dev/null || true | |
| fi | |
| ' || true | |
| fi | |
| # Update all submodules to latest remote versions | |
| git submodule update --recursive --remote || true | |
| - name: Check for changes | |
| id: check-changes | |
| run: | | |
| if [ -n "$(git status --porcelain)" ]; then | |
| echo "has_changes=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "has_changes=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Commit and push changes | |
| if: steps.check-changes.outputs.has_changes == 'true' | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add -A | |
| git commit -m "chore: update submodules to latest versions" | |
| git push | |