-
Notifications
You must be signed in to change notification settings - Fork 24
296 lines (250 loc) · 12.8 KB
/
manage-visual-tests.yml
File metadata and controls
296 lines (250 loc) · 12.8 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
name: Manage Visual Tests
concurrency:
group: visual-tests-${{ github.event.pull_request.number }}
cancel-in-progress: true
on:
pull_request:
types: [synchronize, opened, reopened, closed, labeled, unlabeled]
env:
VISUAL_TESTS_REPORTS_DIR: 'visual-tests-reports'
VISUAL_TESTS_RAW_REPORT_NAME: 'visual-tests-results.json'
VISUAL_TESTS_FINAL_REPORT_NAME: 'visual-tests-report.json'
VISUAL_TESTS_REPORT_COMMENT_ID: 'visual-changes-report-comment-${{ github.event.pull_request.number }}'
VISUAL_TESTS_CELLAR_BUCKET_NAME: ${{ vars.VISUAL_TESTS_CELLAR_BUCKET_NAME }}
BRANCH_NAME: ${{ github.event.pull_request.head.ref }}
BASE_COMMIT_SHA: ${{ github.event.pull_request.base.sha }}
HEAD_COMMIT_SHA: ${{ github.event.pull_request.head.sha }}
PR_NUMBER: ${{ github.event.pull_request.number }}
WORKFLOW_ID: ${{ github.run_id }}
REPOSITORY_NAME: ${{ github.event.repository.name }}
REPOSITORY_OWNER: ${{ github.repository_owner }}
jobs:
split-into-groups:
if: github.event.action != 'closed' && contains(github.event.pull_request.labels.*.name, 'run-visual-tests')
name: Split into groups
runs-on: ubuntu-latest
outputs:
stories-groups: ${{ steps.get-stories-groups.outputs.stories-groups }}
steps:
- name: '[Prepare] Checkout'
uses: actions/checkout@v5
- name: '[Prepare] Setup Node.js'
uses: actions/setup-node@v6
with:
node-version-file: 'package.json'
cache: 'npm'
- name: '[Prepare] Install dependencies'
run: npm ci
# Expected outputs
# - stories-groups=Array<`stories-group-{number}`>
- name: '[Run] Get stories groups'
id: get-stories-groups
run: node ./.github/scripts/get-stories-groups.js
check-for-expectation-update:
if: github.event.action != 'closed' && contains(github.event.pull_request.labels.*.name, 'run-visual-tests')
name: Check for last expectation update
runs-on: ubuntu-latest
outputs:
should-update-expectation: ${{ steps.check-for-expectation-update.outputs.should-update-expectation }}
last-expectation-update-utc: ${{ steps.check-for-expectation-update.outputs.last-expectation-update-utc }}
last-expectation-update-local: ${{ steps.check-for-expectation-update.outputs.last-expectation-update-local }}
steps:
- name: '[Prepare] Checkout'
uses: actions/checkout@v5
- name: '[Prepare] Setup Node.js'
uses: actions/setup-node@v6
with:
node-version-file: 'package.json'
cache: 'npm'
- name: '[Prepare] Install dependencies'
run: npm ci
# Expected outputs:
# - should-update-expectation: boolean - true if expectation should be updated (base commit has changed or no previous report was found)
# - last-expectation-update-utc: string - date as string representing the last update of the expectation screenshots (UTC)
# - last-expectation-update-local: string - date as string representing the last update of the expectation screenshots (Local)
- name: '[Run] Check for last expectation update'
id: check-for-expectation-update
run: node ./tasks/visual-tests/manage-visual-tests-data.js check-for-expectation-update
env:
VISUAL_TESTS_CELLAR_KEY_ID: ${{ secrets.VISUAL_TESTS_CELLAR_KEY_ID }}
VISUAL_TESTS_CELLAR_SECRET_KEY: ${{ secrets.VISUAL_TESTS_CELLAR_SECRET_KEY }}
update-expectation:
if: needs.check-for-expectation-update.outputs.should-update-expectation == 'true' && !contains(github.event.pull_request.labels.*.name, 'skip-visual-changes-tests')
name: Update expectation ${{ matrix.stories-group }}
needs: [split-into-groups, check-for-expectation-update]
runs-on: ubuntu-latest
container:
image: mcr.microsoft.com/playwright:v1.55.0-noble
options: --user 1001
strategy:
matrix:
stories-group: ${{ fromJson(needs.split-into-groups.outputs.stories-groups) }}
steps:
- name: '[Prepare] Checkout base commit'
uses: actions/checkout@v5
with:
ref: ${{ github.event.pull_request.base.sha }}
- name: '[Prepare] Setup Node.js'
uses: actions/setup-node@v6
with:
node-version-file: 'package.json'
cache: 'npm'
- name: '[Prepare] Install dependencies'
run: npm ci
- name: '[Run] Visual Tests (Expectation update) - ${{ matrix.stories-group }}'
run: npm run test:visual:update-expectation -- --group ${{ matrix.stories-group }}
env:
VISUAL_TESTS_CELLAR_KEY_ID: ${{ secrets.VISUAL_TESTS_CELLAR_KEY_ID }}
VISUAL_TESTS_CELLAR_SECRET_KEY: ${{ secrets.VISUAL_TESTS_CELLAR_SECRET_KEY }}
- name: '[Run] Set last-expectation-update output'
id: set-last-expectation-update
run: |
echo "last-expectation-update-utc=$(date +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
echo "last-expectation-update-local=$(TZ="Europe/Paris" date +'%Y-%m-%d %H:%M:%S')" >> $GITHUB_OUTPUT
outputs:
last-expectation-update-utc: ${{ steps.set-last-expectation-update.outputs.last-expectation-update-utc }}
last-expectation-update-local: ${{ steps.set-last-expectation-update.outputs.last-expectation-update-local }}
run-visual-tests:
if: github.event.action != 'closed' && contains(github.event.pull_request.labels.*.name, 'run-visual-tests') && !cancelled()
name: Run visual tests ${{ matrix.stories-group }}
needs: [split-into-groups, check-for-expectation-update, update-expectation]
runs-on: ubuntu-latest
container:
image: mcr.microsoft.com/playwright:v1.55.0-noble
options: --user 1001
strategy:
matrix:
stories-group: ${{ fromJson(needs.split-into-groups.outputs.stories-groups) }}
steps:
- name: '[Prepare] Checkout latest commit'
uses: actions/checkout@v5
with:
ref: ${{ github.event.pull_request.head.ref }}
- name: '[Prepare] Setup Node.js'
uses: actions/setup-node@v6
with:
node-version-file: 'package.json'
cache: 'npm'
- name: '[Prepare] Install dependencies'
run: npm ci
- name: '[Run] Visual Tests (Compare Expectation with Actual) - ${{ matrix.stories-group }}'
run: npm run test:visual -- --group ${{ matrix.stories-group }}
env:
VISUAL_TESTS_CELLAR_KEY_ID: ${{ secrets.VISUAL_TESTS_CELLAR_KEY_ID }}
VISUAL_TESTS_CELLAR_SECRET_KEY: ${{ secrets.VISUAL_TESTS_CELLAR_SECRET_KEY }}
BRANCH_NAME: ${{ github.event.pull_request.head.ref }}
continue-on-error: true
- name: '[Run] set report update date'
id: set-last-actual-update
run: |
echo "last-actual-update-utc=$(date +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
echo "last-actual-update-local=$(TZ=Europe/Paris date +'%Y-%m-%d %H:%M:%S')" >> $GITHUB_OUTPUT
- name: '[Run] Upload report to GitHub Actions Artifacts'
uses: actions/upload-artifact@v5
with:
name: results-${{ matrix.stories-group }}
path: ${{ env.VISUAL_TESTS_REPORTS_DIR }}/${{ env.VISUAL_TESTS_RAW_REPORT_NAME }}
retention-days: 1
outputs:
last-actual-update-utc: ${{ steps.set-last-actual-update.outputs.last-actual-update-utc }}
last-actual-update-local: ${{ steps.set-last-actual-update.outputs.last-actual-update-local }}
generate-final-report:
if: github.event.action != 'closed' && contains(github.event.pull_request.labels.*.name, 'run-visual-tests') && !cancelled()
name: Generate final report
needs: [check-for-expectation-update, update-expectation, run-visual-tests]
runs-on: ubuntu-latest
steps:
- name: '[Prepare] Checkout latest commit'
uses: actions/checkout@v5
with:
ref: ${{ github.event.pull_request.head.ref }}
- name: '[Prepare] Setup Node.js'
uses: actions/setup-node@v6
with:
node-version-file: 'package.json'
cache: 'npm'
- name: '[Prepare] Install dependencies'
run: npm ci
- name: '[Prepare] Download reports from GitHub Actions Artifacts'
uses: actions/download-artifact@v6
with:
path: ${{ env.VISUAL_TESTS_REPORTS_DIR }}
pattern: results-*
# Expected outputs:
# - nb-of-impacted-components: number - number of components with visual changes
# - impacted-components-md: Array<string> - formatted list of impacted components to be inserted as Markdown
- name: '[Run] Merge results & generate final JSON report'
id: merge-results-and-generate-report
run: node ./tasks/visual-tests/generate-visual-tests-json-report.js
env:
LAST_EXPECTATION_UPDATE: ${{ needs.update-expectation.outputs.last-expectation-update-utc || needs.check-for-expectation-update.outputs.last-expectation-update-utc }}
LAST_ACTUAL_UPDATE: ${{ needs.run-visual-tests.outputs.last-actual-update-utc }}
- name: '[Run] Generate HTML report'
if: steps.merge-results-and-generate-report.outputs.nb-of-impacted-components > 0
run: node ./tasks/visual-tests/generate-visual-tests-html-report.js
# Expected outputs:
# - reports_url: url where reports have been uploaded to
- name: '[Run] Upload test reports to Cellar'
id: 'upload-test-reports'
run: node ./tasks/visual-tests/manage-visual-tests-data.js upload
env:
VISUAL_TESTS_CELLAR_KEY_ID: ${{ secrets.VISUAL_TESTS_CELLAR_KEY_ID }}
VISUAL_TESTS_CELLAR_SECRET_KEY: ${{ secrets.VISUAL_TESTS_CELLAR_SECRET_KEY }}
- name: '[Run] Create or edit PR comment'
run: node ./.github/scripts/manage-comment.js create-or-edit
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MARKER: ${{ env.VISUAL_TESTS_REPORT_COMMENT_ID }}
MESSAGE: |
<!-- ${{ env.VISUAL_TESTS_REPORT_COMMENT_ID }} -->
## :monocle_face: Visual tests report for PR #${{ github.event.pull_request.number }}
The latest visual tests report is available. Please review the results.
- ${{ steps.merge-results-and-generate-report.outputs.nb-of-impacted-components > 0 && format('[View HTML Report]({0}/index.html)', steps.upload-test-reports.outputs.reports_url) || '**No visual changes detected**' }}
- Baseline info:
- Commit: ${{ github.event.pull_request.base.sha }}
- Last update: ${{ needs.update-expectation.outputs.last-expectation-update-local || needs.check-for-expectation-update.outputs.last-expectation-update-local }}
- Changes info:
- Commit: ${{ github.event.pull_request.head.sha }}
- Last update: ${{ needs.run-visual-tests.outputs.last-actual-update-local }}
- Workflow run: [${{ github.run_id }}](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
<details>
<summary>${{ steps.merge-results-and-generate-report.outputs.nb-of-impacted-components }} components impacted</summary>
${{ steps.merge-results-and-generate-report.outputs.impacted-components-md }}
</details>
_This comment was generated automatically by the Visual tests workflow._
clean-up:
if: (github.event.action == 'closed' && contains(github.event.pull_request.labels.*.name, 'run-visual-tests')) || (github.event.action == 'unlabeled' && github.event.label.name == 'run-visual-tests')
name: 'Clean up visual tests report data'
runs-on: ubuntu-latest
steps:
- name: '[Prepare] Checkout'
uses: actions/checkout@v5
- name: '[Prepare] Setup Node.js'
uses: actions/setup-node@v6
with:
node-version-file: 'package.json'
cache: 'npm'
- name: '[Prepare] Install dependencies'
run: npm ci
- name: '[Run] Remove report data for current branch'
id: delete-report-and-assets
run: node ./tasks/visual-tests/manage-visual-tests-data.js delete
env:
BRANCH_NAME: ${{ github.event.pull_request.head.ref }}
VISUAL_TESTS_CELLAR_KEY_ID: ${{ secrets.VISUAL_TESTS_CELLAR_KEY_ID }}
VISUAL_TESTS_CELLAR_SECRET_KEY: ${{ secrets.VISUAL_TESTS_CELLAR_SECRET_KEY }}
- name: '[Run] Create clean up comment'
if: github.event.action == 'closed'
run: node ./.github/scripts/manage-comment.js create
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MESSAGE: |
## :broom: Visual Changes Report deleted
The report and its associated data have been deleted because this PR has been closed.
_This comment was generated automatically by the Visual Changes workflow._
- name: '[Run] Delete report comment'
if: github.event.action == 'unlabeled'
run: node ./.github/scripts/manage-comment.js delete
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MARKER: ${{ env.VISUAL_TESTS_REPORT_COMMENT_ID }}