Submodules Sync #5
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: 'Submodules Sync' | |
| on: | |
| schedule: | |
| - cron: "0 2 * * 1" | |
| # Allows you to run this workflow manually from the Actions tab or through HTTP API | |
| workflow_dispatch: | |
| jobs: | |
| sync: | |
| name: 'Submodules Sync' | |
| runs-on: ubuntu-latest | |
| # Use the Bash shell regardless whether the GitHub Actions runner is ubuntu-latest, macos-latest, or windows-latest | |
| defaults: | |
| run: | |
| shell: bash | |
| steps: | |
| # Checkout the repository to the GitHub Actions runner | |
| - name: Checkout | |
| uses: actions/checkout@v3 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| submodules: true | |
| fetch-depth: 0 | |
| # Update references | |
| - name: Git Sumbodule Update | |
| id: submodule_update | |
| run: | | |
| cd tailscale | |
| OLD_COMMIT=$(git rev-parse HEAD) | |
| cd .. | |
| git pull --recurse-submodules | |
| git submodule update --remote --recursive | |
| cd tailscale | |
| NEW_COMMIT=$(git rev-parse HEAD) | |
| echo "old_commit=$OLD_COMMIT" >> $GITHUB_OUTPUT | |
| echo "new_commit=$NEW_COMMIT" >> $GITHUB_OUTPUT | |
| if [ "$OLD_COMMIT" != "$NEW_COMMIT" ]; then | |
| echo "has_changes=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "has_changes=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Generate changelog | |
| if: steps.submodule_update.outputs.has_changes == 'true' | |
| run: | | |
| cd tailscale | |
| TAILSCALE_VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo "unknown") | |
| OLD_COMMIT=${{ steps.submodule_update.outputs.old_commit }} | |
| NEW_COMMIT=${{ steps.submodule_update.outputs.new_commit }} | |
| # Get changes between old and new commit | |
| CHANGELOG=$(git log --pretty=format:"- %s (%h)" $OLD_COMMIT..$NEW_COMMIT || echo "No changes") | |
| mkdir -p ../changelogs | |
| CHANGELOG_FILE="../changelogs/$(date +%Y%m%d)-update.md" | |
| echo "# Tailscale Update" > $CHANGELOG_FILE | |
| echo "" >> $CHANGELOG_FILE | |
| echo "**Date**: $(date +%Y-%m-%d)" >> $CHANGELOG_FILE | |
| echo "**Tailscale Version**: $TAILSCALE_VERSION" >> $CHANGELOG_FILE | |
| echo "**Previous Commit**: $OLD_COMMIT" >> $CHANGELOG_FILE | |
| echo "**New Commit**: $NEW_COMMIT" >> $CHANGELOG_FILE | |
| echo "" >> $CHANGELOG_FILE | |
| echo "## Changes" >> $CHANGELOG_FILE | |
| echo "$CHANGELOG" >> $CHANGELOG_FILE | |
| cat $CHANGELOG_FILE | |
| - name: Commit update | |
| run: | | |
| git config --global user.name 'github-actions[bot]' | |
| git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
| git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} | |
| git add -A | |
| git commit -m "chore: auto updated submodule references" && git push || echo "No changes to commit" |