-
Notifications
You must be signed in to change notification settings - Fork 640
83 lines (75 loc) · 3.28 KB
/
update-snapshots.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# This workflow's goal is forcing an update of the reference snapshots used
# by Playwright tests. It runs whenever you post a new pull request comment
# that strictly matches the "/update-snapshots".
# From a high-level perspective, it works like this:
# 1. Because of a GitHub Action limitation, this workflow is triggered on every
# comment posted on a issue or pull request. We manually interrupt it unless
# the comment content strictly matches "/update-snapshots" and we're in a
# pull request.
# 2. Use the GitHub API to grab the information about the branch name of the current pull request.
# 3. Update the Playwright reference snapshots based on the UI of this branch.
# 4. Create the pull request into this branch.
name: Update Snapshots
on:
# It looks like you can't target PRs-only comments:
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_comment-use-issue_comment
# So we must run this workflow every time a new comment is added to issues
# and pull requests
issue_comment:
types: [created]
jobs:
updatesnapshots:
# Run this job only on comments of pull requests that strictly match
# the "/update-snapshots" string
if: ${{ github.event.issue.pull_request && github.event.comment.body == '/update-snapshots'}}
timeout-minutes: 60
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]
steps:
# Get the branch name of the comment's pull request
# We must use the GitHub API to retrieve these information because they're
# not accessibile within workflows triggered by "issue_comment"
- name: Get branch name
id: branch_name
uses: actions/github-script@v7
with:
result-encoding: string
script: |
const { data: pullRequest } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: ${{ github.event.issue.number }},
});
return pullRequest.head.ref;
# Checkout the comment's branch
- uses: actions/checkout@v4
with:
ref: ${{ steps.branch_name.outputs.result }}
# Setup testing environment
- name: Install dependencies
uses: ./.github/actions/prepare-install
with:
node-version: ${{ matrix.node-version }}
- name: Install Playwright chromium browser
run: pnpm exec playwright install --with-deps chromium
# Update the snapshots based on the current UI
- name: Update snapshots
run: pnpm test:integration --updateSnapshot
# Create the pull request into branch
- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v6
with:
commit-message: 'chore: update snapshots by CI'
branch: ${{ steps.branch_name.outputs.result }}-update-snapshots
delete-branch: true
title: 'chore(CI): update snapshots'
body: |
Update Snapshots
- Generated integration test expected images
- Auto-generated by [create-pull-request][1]
[1]: https://github.com/peter-evans/create-pull-request
assignees: ${{ github.event.comment.user.name }}
reviewers: ${{ github.event.comment.user.name }}