|
| 1 | +name: Update E2E Snapshots |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + branch: |
| 7 | + description: "Branch to update snapshots on" |
| 8 | + required: true |
| 9 | + default: "main" |
| 10 | + issue_comment: |
| 11 | + types: [created] |
| 12 | + |
| 13 | +permissions: |
| 14 | + contents: write |
| 15 | + pull-requests: write |
| 16 | + |
| 17 | +jobs: |
| 18 | + update-snapshots: |
| 19 | + # Run on workflow_dispatch OR when someone comments "/update-snapshots" on a PR |
| 20 | + if: > |
| 21 | + github.event_name == 'workflow_dispatch' || |
| 22 | + (github.event.issue.pull_request && contains(github.event.comment.body, '/update-snapshots')) |
| 23 | + runs-on: ubuntu-latest |
| 24 | + steps: |
| 25 | + - name: Get PR branch |
| 26 | + if: github.event_name == 'issue_comment' |
| 27 | + id: pr |
| 28 | + uses: actions/github-script@v7 |
| 29 | + with: |
| 30 | + script: | |
| 31 | + const pr = await github.rest.pulls.get({ |
| 32 | + owner: context.repo.owner, |
| 33 | + repo: context.repo.repo, |
| 34 | + pull_number: context.issue.number |
| 35 | + }); |
| 36 | + core.setOutput('ref', pr.data.head.ref); |
| 37 | + core.setOutput('sha', pr.data.head.sha); |
| 38 | +
|
| 39 | + - name: Add reaction to comment |
| 40 | + if: github.event_name == 'issue_comment' |
| 41 | + uses: actions/github-script@v7 |
| 42 | + with: |
| 43 | + script: | |
| 44 | + await github.rest.reactions.createForIssueComment({ |
| 45 | + owner: context.repo.owner, |
| 46 | + repo: context.repo.repo, |
| 47 | + comment_id: context.payload.comment.id, |
| 48 | + content: 'rocket' |
| 49 | + }); |
| 50 | +
|
| 51 | + - uses: actions/checkout@v4 |
| 52 | + with: |
| 53 | + ref: ${{ github.event.inputs.branch || steps.pr.outputs.ref || github.ref }} |
| 54 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 55 | + |
| 56 | + - uses: oven-sh/setup-bun@v2 |
| 57 | + with: |
| 58 | + bun-version: latest |
| 59 | + |
| 60 | + - uses: actions/setup-node@v4 |
| 61 | + with: |
| 62 | + node-version: "20" |
| 63 | + |
| 64 | + - uses: astral-sh/setup-uv@v5 |
| 65 | + |
| 66 | + - run: npm ci |
| 67 | + |
| 68 | + - name: Install Playwright browsers |
| 69 | + run: npx playwright install --with-deps chromium |
| 70 | + |
| 71 | + - name: Update snapshots |
| 72 | + run: npx playwright test --update-snapshots --reporter=list |
| 73 | + |
| 74 | + - name: Commit updated snapshots |
| 75 | + id: commit |
| 76 | + run: | |
| 77 | + git config user.name "github-actions[bot]" |
| 78 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 79 | + git add tests/e2e/**/*.png |
| 80 | + if git diff --staged --quiet; then |
| 81 | + echo "changed=false" >> $GITHUB_OUTPUT |
| 82 | + echo "No snapshot changes to commit" |
| 83 | + else |
| 84 | + git commit -m "chore: update e2e snapshots [skip ci]" |
| 85 | + git push |
| 86 | + echo "changed=true" >> $GITHUB_OUTPUT |
| 87 | + fi |
| 88 | +
|
| 89 | + - name: Comment on PR |
| 90 | + if: github.event_name == 'issue_comment' |
| 91 | + uses: actions/github-script@v7 |
| 92 | + with: |
| 93 | + script: | |
| 94 | + const changed = '${{ steps.commit.outputs.changed }}' === 'true'; |
| 95 | + const body = changed |
| 96 | + ? '✅ Snapshots updated and pushed to this branch.' |
| 97 | + : '✅ No snapshot changes needed - all snapshots are up to date.'; |
| 98 | + await github.rest.issues.createComment({ |
| 99 | + owner: context.repo.owner, |
| 100 | + repo: context.repo.repo, |
| 101 | + issue_number: context.issue.number, |
| 102 | + body |
| 103 | + }); |
0 commit comments