Skip to content

Commit b5484cf

Browse files
committed
feat(ci): add /update-snapshots comment trigger for PRs
- Comment '/update-snapshots' on any PR to update E2E snapshots - Adds rocket reaction to acknowledge the command - Comments back with result (updated or no changes needed) - Removes hardcoded branch trigger - Keeps workflow_dispatch for manual runs
1 parent 3b82522 commit b5484cf

File tree

1 file changed

+59
-9
lines changed

1 file changed

+59
-9
lines changed

.github/workflows/update-snapshots.yml

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,50 @@ on:
77
description: "Branch to update snapshots on"
88
required: true
99
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]
1612

1713
permissions:
1814
contents: write
15+
pull-requests: write
1916

2017
jobs:
2118
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'))
2223
runs-on: ubuntu-latest
2324
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+
2451
- uses: actions/checkout@v4
2552
with:
26-
ref: ${{ github.event.inputs.branch || github.ref }}
53+
ref: ${{ github.event.inputs.branch || steps.pr.outputs.ref || github.ref }}
2754
token: ${{ secrets.GITHUB_TOKEN }}
2855

2956
- uses: oven-sh/setup-bun@v2
@@ -45,9 +72,32 @@ jobs:
4572
run: npx playwright test --update-snapshots --reporter=list
4673

4774
- name: Commit updated snapshots
75+
id: commit
4876
run: |
4977
git config user.name "github-actions[bot]"
5078
git config user.email "github-actions[bot]@users.noreply.github.com"
5179
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

Comments
 (0)