1
- # This workflow's goal is forcing an update of the reference snapshots used
2
- # by Playwright tests. It runs whenever you post a new pull request comment
3
- # that strictly matches the "/update-snapshots".
4
- # From a high-level perspective, it works like this:
5
- # 1. Because of a GitHub Action limitation, this workflow is triggered on every
6
- # comment posted on a issue or pull request. We manually interrupt it unless
7
- # the comment content strictly matches "/update-snapshots" and we're in a
8
- # pull request.
9
- # 2. Use the GitHub API to grab the information about the branch name and SHA of
10
- # the latest commit of the current pull request.
11
- # 3. Update the Playwright reference snapshots based on the UI of this branch.
12
- # 4. Commit the newly generated Playwright reference snapshots into this branch.
13
1
name : Update Snapshots
14
-
2
+
15
3
on :
16
- # It looks like you can't target PRs-only comments:
17
- # https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_comment-use-issue_comment
18
- # So we must run this workflow every time a new comment is added to issues
19
- # and pull requests
4
+ # Run any time any issue/PR has a new comment
20
5
issue_comment :
21
6
types : [created]
22
7
23
8
jobs :
24
- updatesnapshots :
25
- # Run this job only on comments of pull requests that strictly match
26
- # the "/update-snapshots" string
9
+ slash_command :
10
+ name : slash command
11
+ # This job will only run if the comment was on a pull requests and matches the slash command
27
12
if : ${{ github.event.issue.pull_request && github.event.comment.body == '/update-snapshots'}}
13
+ # Common with standard build
28
14
timeout-minutes : 60
29
15
runs-on : ubuntu-latest
30
16
steps :
31
- # Checkout and do a deep fetch to load all commit IDs
17
+ # Checkout with personal TOKEN
18
+ # and hop on the PR branch
32
19
- uses : actions/checkout@v3
33
20
with :
34
- fetch-depth : 0 # Load all commits
35
- token : ${{ secrets.GITHUB_TOKEN }}
36
- # Get the SHA and branch name of the comment's pull request
37
- # We must use the GitHub API to retrieve these information because they're
38
- # not accessibile within workflows triggered by "issue_comment"
39
- - name : Get SHA and branch name
40
- id : get-branch-and-sha
21
+ fetch-depth : 0
22
+ token : ${{ secrets.GH_ACTION_TOKEN }}
23
+ - name : Get Branch
24
+ id : getbranch
41
25
run : |
42
- sha_and_branch =$(\
26
+ branch =$(\
43
27
curl \
44
28
-H 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \
45
29
https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.issue.number }} \
46
- | jq -r '.head.sha," ",.head.ref');
47
- echo "::set-output name=sha::$(echo $sha_and_branch | cut -d " " -f 1)";
48
- echo "::set-output name=branch::$(echo $sha_and_branch | cut -d " " -f 2)"
49
- # Checkout the comment's branch
30
+ | jq -r '.head.ref')
31
+ echo "::set-output name=branch::$branch"
50
32
- name : Fetch Branch
51
33
run : git fetch
52
34
- name : Checkout Branch
53
- run : git checkout ${{ steps.get-branch-and-sha .outputs.branch }}
54
- # Setup testing environment
35
+ run : git checkout ${{ steps.getbranch .outputs.branch }}
36
+ # Continue with standard build
55
37
- name : Use Node.js
56
38
uses : actions/setup-node@v3
57
39
with :
58
40
node-version : 20
59
- - uses : pnpm/action-setup@v2
60
- - run : pnpm install
61
- - run : npx playwright install --with-deps chromium
62
- - run : pnpm test-ct
63
- # Update the snapshots based on the current UI
41
+ - name : Install dependencies
42
+ run : pnpm install
43
+ - name : Install Playwright
44
+ run : npx playwright install --with-deps
45
+ # Update the snapshots
64
46
- name : Update snapshots
65
- run : pnpm test-ct --update-snapshots
66
- # Commit the changes to the pull request branch
47
+ run : npx playwright test --update-snapshots --reporter=list
48
+ # Commit the changes
67
49
- uses : stefanzweifel/git-auto-commit-action@v4
68
50
with :
69
- commit_message : " [CI] Update Snapshots"
51
+ commit_message : Update Snapshots
0 commit comments