|
7 | 7 | description: "Branch to update snapshots on" |
8 | 8 | required: true |
9 | 9 | default: "main" |
10 | | - # Temporary: auto-run on this branch to update snapshots |
11 | | - push: |
12 | | - branches: |
13 | | - - "ochafik/fix-e2e-flaky-tests" |
14 | | - paths: |
15 | | - - ".github/workflows/update-snapshots.yml" |
| 10 | + issue_comment: |
| 11 | + types: [created] |
16 | 12 |
|
17 | 13 | permissions: |
18 | 14 | contents: write |
| 15 | + pull-requests: write |
19 | 16 |
|
20 | 17 | jobs: |
21 | 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')) |
22 | 23 | runs-on: ubuntu-latest |
23 | 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 | +
|
24 | 51 | - uses: actions/checkout@v4 |
25 | 52 | with: |
26 | | - ref: ${{ github.event.inputs.branch || github.ref }} |
| 53 | + ref: ${{ github.event.inputs.branch || steps.pr.outputs.ref || github.ref }} |
27 | 54 | token: ${{ secrets.GITHUB_TOKEN }} |
28 | 55 |
|
29 | 56 | - uses: oven-sh/setup-bun@v2 |
|
45 | 72 | run: npx playwright test --update-snapshots --reporter=list |
46 | 73 |
|
47 | 74 | - name: Commit updated snapshots |
| 75 | + id: commit |
48 | 76 | run: | |
49 | 77 | git config user.name "github-actions[bot]" |
50 | 78 | git config user.email "github-actions[bot]@users.noreply.github.com" |
51 | 79 | git add tests/e2e/**/*.png |
52 | | - git diff --staged --quiet || git commit -m "chore: update e2e snapshots [skip ci]" |
53 | | - git push |
| 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