-
Notifications
You must be signed in to change notification settings - Fork 34
103 lines (87 loc) · 4.08 KB
/
snapshots-update.yml
File metadata and controls
103 lines (87 loc) · 4.08 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
name: Update Snapshots on a PR
description: |
Runs previously failed snapshot tests, and commits the changes.
Your PR will receive a commit with the changes so you can manually verify before merging.
on:
workflow_dispatch:
inputs:
pr_number:
description: 'Pull Request Number (Warning: This action will push a commit to the referenced PR)'
required: true
type: number
permissions:
pull-requests: write
contents: write
jobs:
update-pr-with-snapshots:
name: Update PR With Snapshots
runs-on: macos-14
steps:
- uses: actions/checkout@v6
- name: Checkout PR ${{ github.event.inputs.pr_number }}
if: github.event_name == 'workflow_dispatch'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.inputs.pr_number }}
run: gh pr checkout "$PR_NUMBER"
- name: Use Node.js
uses: actions/setup-node@v6
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v5
with:
path: |
node_modules
injected/node_modules
special-pages/node_modules
messaging/node_modules
types-generator/node_modules
key: ${{ runner.os }}-node-modules-${{ hashFiles('.nvmrc') }}-${{ hashFiles('**/package-lock.json') }}
- name: Cache Playwright browsers
uses: actions/cache@v5
with:
path: ~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ hashFiles('**/package-lock.json') }}
- name: Install SF Pro Fonts
run: |
curl -L -o SF-Pro.dmg 'https://devimages-cdn.apple.com/design/resources/download/SF-Pro.dmg'
hdiutil attach SF-Pro.dmg
sudo installer -pkg '/Volumes/SFProFonts/SF Pro Fonts.pkg' -target /
hdiutil detach '/Volumes/SFProFonts'
- name: Install dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: npm ci
- name: Build all
run: npm run build
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Run Screenshot tests
id: screenshot_tests
# Disable retries to fail fast - we just need to identify failing tests
run: npm run test-int-snapshots -- --retries=0
- if: ${{ steps.screenshot_tests.conclusion == 'success' }}
run: |
echo "nothing to update - tests all passed"
- name: Re-Running Playwright to update snapshots
id: screenshot_tests_update
if: ${{ failure() && steps.screenshot_tests.conclusion == 'failure' }}
# Disable retries since we're updating snapshots, not verifying them
run: npm run test-int-snapshots-update -- --retries=0
- name: Commit the updated files to the PR branch
if: ${{ failure() && steps.screenshot_tests_update.conclusion == 'success' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Configure Git with a bot's username and email for committing changes
# This makes it easy to identify in the PR
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Stage all updated PNG files for commit
git add "*.png"
# Commit the changes with a descriptive message
git commit -m "Updated snapshots via workflow"
# Push the changes to the current branch in the PR
git push origin HEAD