Upgrade template dependencies #7
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: Upgrade template dependencies | |
| on: | |
| schedule: | |
| - cron: '0 0 * * 1' # Every Monday at midnight UTC | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| upgrade-template-deps: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Generate GitHub App token | |
| id: app-token | |
| uses: actions/create-github-app-token@v1 | |
| with: | |
| app-id: ${{ secrets.APP_ID }} | |
| private-key: ${{ secrets.APP_PRIVATE_KEY }} | |
| - name: Checkout | |
| uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | |
| with: | |
| token: ${{ steps.app-token.outputs.token }} | |
| - name: Setup | |
| uses: ./.github/actions/setup | |
| - name: Run upgrade script | |
| run: node scripts/upgrade-template-deps.mts | |
| - name: Get GitHub App user ID | |
| id: app-user | |
| run: echo "user-id=$(gh api '/users/${{ steps.app-token.outputs.app-slug }}[bot]' --jq .id)" >> "$GITHUB_OUTPUT" | |
| env: | |
| GH_TOKEN: ${{ steps.app-token.outputs.token }} | |
| - name: Create or update pull request | |
| run: | | |
| if [ -z "$(git status --porcelain)" ]; then | |
| echo "No changes to commit." | |
| exit 0 | |
| fi | |
| git config user.name "${{ steps.app-token.outputs.app-slug }}[bot]" | |
| git config user.email "${{ steps.app-user.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com" | |
| branch="upgrade-template-deps" | |
| git checkout -B "$branch" | |
| git add -A | |
| git commit -m "chore: upgrade template dependencies" | |
| git push -u origin "$branch" --force | |
| existing_pr=$(gh pr list --head "$branch" --json number --jq '.[0].number') | |
| if [ -n "$existing_pr" ]; then | |
| echo "Updated existing PR #$existing_pr" | |
| else | |
| gh pr create \ | |
| --title "chore: upgrade template dependencies" \ | |
| --body "Automated upgrade of template dependencies via \`scripts/upgrade-template-deps.mts\`." \ | |
| --label "dependencies" | |
| fi | |
| env: | |
| GH_TOKEN: ${{ steps.app-token.outputs.token }} |