|
| 1 | +name: Commit Regenerated Snapshots |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + components: |
| 7 | + description: "Regenerate snapshots for components" |
| 8 | + required: true |
| 9 | + type: boolean |
| 10 | + foundations: |
| 11 | + description: "Regenerate snapshots for foundations" |
| 12 | + required: true |
| 13 | + type: boolean |
| 14 | + patternhub: |
| 15 | + description: "Regenerate snapshots for patternhub" |
| 16 | + required: true |
| 17 | + type: boolean |
| 18 | + showcases: |
| 19 | + description: "Regenerate snapshots for showcases" |
| 20 | + required: true |
| 21 | + type: boolean |
| 22 | + |
| 23 | +jobs: |
| 24 | + commit-showcases: |
| 25 | + name: 🆙 Commit regenerated snapshots |
| 26 | + if: (inputs.showcases || inputs.components || inputs.foundations || inputs.patternhub) && !contains(github.actor,'[bot]') |
| 27 | + runs-on: ubuntu-24.04 # Use Ubuntu 24.04 explicitly |
| 28 | + permissions: |
| 29 | + contents: write |
| 30 | + pull-requests: write |
| 31 | + env: |
| 32 | + NEW_PR_BRANCH: "${{ github.head_ref }}-auto" |
| 33 | + steps: |
| 34 | + - name: ⏬ Checkout repo |
| 35 | + uses: actions/checkout@v4 |
| 36 | + with: |
| 37 | + ref: ${{ github.head_ref }} |
| 38 | + |
| 39 | + - name: ⏬ Download components |
| 40 | + uses: actions/download-artifact@v4 |
| 41 | + # Only download artifact if the artifact exists |
| 42 | + if: inputs.components |
| 43 | + with: |
| 44 | + name: snapshots-components |
| 45 | + path: ./__snapshots__/ |
| 46 | + |
| 47 | + - name: ⏬ Download foundations |
| 48 | + uses: actions/download-artifact@v4 |
| 49 | + # Only download artifact if the artifact exists |
| 50 | + if: inputs.foundations |
| 51 | + with: |
| 52 | + name: snapshots-foundations |
| 53 | + path: ./__snapshots__/ |
| 54 | + |
| 55 | + - name: ⏬ Download patternhub |
| 56 | + uses: actions/download-artifact@v4 |
| 57 | + if: inputs.patternhub |
| 58 | + with: |
| 59 | + name: snapshots-patternhub |
| 60 | + path: ./__snapshots__/ |
| 61 | + |
| 62 | + - name: ⏬ Download showcase |
| 63 | + uses: actions/download-artifact@v4 |
| 64 | + if: inputs.showcases |
| 65 | + with: |
| 66 | + name: snapshots-showcases |
| 67 | + path: ./__snapshots__/ |
| 68 | + |
| 69 | + # https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/making-authenticated-api-requests-with-a-github-app-in-a-github-actions-workflow |
| 70 | + - name: 🧬 Generate a token |
| 71 | + id: generate-token |
| 72 | + uses: actions/create-github-app-token@v2 |
| 73 | + with: |
| 74 | + app-id: ${{ vars.AUTO_MERGE_APP_ID }} |
| 75 | + private-key: ${{ secrets.AUTO_MERGE_PRIVATE_KEY }} |
| 76 | + |
| 77 | + - name: 🏗️ Create new branch and commit changes |
| 78 | + env: |
| 79 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 80 | + run: | |
| 81 | + git config --global user.name "github-actions[bot]" |
| 82 | + git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 83 | +
|
| 84 | + git checkout -b "$NEW_PR_BRANCH" |
| 85 | + git add __snapshots__/* |
| 86 | +
|
| 87 | + # We can't use semantic commits here because of the if statement in the workflow |
| 88 | + git commit --no-verify -m "auto update snapshots" |
| 89 | + git push -f origin "$NEW_PR_BRANCH" |
| 90 | +
|
| 91 | + - name: 🪗 Create Pull Request |
| 92 | + env: |
| 93 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 94 | + run: | |
| 95 | + gh pr create --base ${{ github.head_ref }} --head "$NEW_PR_BRANCH" --title "Automated PR: Auto update snapshots" --body "This PR was created automatically by a GitHub Action." |
| 96 | +
|
| 97 | + - name: 🤖 Squash the PR |
| 98 | + run: gh pr merge --squash "$NEW_PR_BRANCH" |
| 99 | + env: |
| 100 | + GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }} |
0 commit comments