Repository navigation
269 lines (262 loc) · 8.41 KB
/
Copy pathvisual_diff.yml
File metadata and controls
269 lines (262 loc) · 8.41 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
name: Visual Diff
permissions:
contents: read
on:
pull_request:
types: [labeled, unlabeled, opened, synchronize, reopened]
concurrency:
group: visual-diff-${{ github.head_ref || github.ref }}
cancel-in-progress: true
env:
SW_DISABLED: true
EMBER_EXAM_CONCURRENCY: 3
jobs:
baseline:
name: Baseline (${{ matrix.name }}, ${{ matrix.mode }})
runs-on: ubuntu-latest
strategy:
matrix:
include:
- name: phone
width: 399
mode: light
- name: phone
width: 399
mode: dark
- name: tablet
width: 768
mode: light
- name: tablet
width: 768
mode: dark
- name: laptop
width: 1200
mode: light
- name: laptop
width: 1200
mode: dark
- name: desktop
width: 1920
mode: light
- name: desktop
width: 1920
mode: dark
env:
MOZ_HEADLESS_WIDTH: ${{ matrix.width }}
outputs:
ref: ${{ steps.ref.outputs.ref }}
steps:
- uses: actions/checkout@v7
with:
ref: "master"
- id: ref
run: |
echo "$(git rev-parse HEAD)"
echo "ref=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
- name: Get cache date
id: cache-date
run: echo "date=$(date -u +%Y-%m-%d)" >> "$GITHUB_OUTPUT"
- name: Cache Screenshots
id: screenshot-cache
uses: actions/cache@v6
with:
path: build
key: screenshots-${{ steps.cache-date.outputs.date }}-${{ steps.ref.outputs.ref }}-${{ matrix.name }}-${{ matrix.mode }}
- uses: pnpm/action-setup@v6
- uses: actions/setup-node@v7
with:
node-version: 24
cache: pnpm
- name: Install Dependencies
if: steps.screenshot-cache.outputs.cache-hit != 'true'
run: pnpm install
- name: Capture Screenshots
continue-on-error: true
if: steps.screenshot-cache.outputs.cache-hit != 'true'
run: |
if [ "${{ matrix.mode }}" = "dark" ]; then
pnpm run test:darkmode-screenshots
else
pnpm run test:screenshots
fi
- name: Rename screenshots
if: steps.screenshot-cache.outputs.cache-hit != 'true'
run: |
mkdir -p build/storage
cd build/screenshots
for file in *; do
mv "$file" "../storage/${{ matrix.name }}-$file"
done
- name: Consolidate Screenshots
if: steps.screenshot-cache.outputs.cache-hit != 'true'
run: |
rm -rf build/screenshots
mv build/storage build/screenshots
- uses: actions/upload-artifact@v7
with:
name: baseline-frontend-${{ matrix.name }}-${{ matrix.mode }}
path: build/screenshots
candidate:
name: Candidate (${{ matrix.name }}, ${{ matrix.mode }})
runs-on: ubuntu-latest
strategy:
matrix:
include:
- name: phone
width: 399
mode: light
- name: phone
width: 399
mode: dark
- name: tablet
width: 768
mode: light
- name: tablet
width: 768
mode: dark
- name: laptop
width: 1200
mode: light
- name: laptop
width: 1200
mode: dark
- name: desktop
width: 1920
mode: light
- name: desktop
width: 1920
mode: dark
env:
MOZ_HEADLESS_WIDTH: ${{ matrix.width }}
outputs:
ref: ${{ steps.ref.outputs.ref }}
steps:
- uses: actions/checkout@v7
- id: ref
run: |
echo "$(git rev-parse HEAD)"
echo "ref=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
- name: Get cache date
id: cache-date
run: echo "date=$(date -u +%Y-%m-%d)" >> "$GITHUB_OUTPUT"
- name: Cache Screenshots
id: screenshot-cache
uses: actions/cache@v6
with:
path: build
key: screenshots-${{ steps.cache-date.outputs.date }}-${{ steps.ref.outputs.ref }}-${{ matrix.name }}-${{ matrix.mode }}
- uses: pnpm/action-setup@v6
- uses: actions/setup-node@v7
with:
node-version: 24
cache: pnpm
- name: Install Dependencies
if: steps.screenshot-cache.outputs.cache-hit != 'true'
run: pnpm install
- name: Capture Screenshots
continue-on-error: true
if: steps.screenshot-cache.outputs.cache-hit != 'true'
run: |
if [ "${{ matrix.mode }}" = "dark" ]; then
pnpm run test:darkmode-screenshots
else
pnpm run test:screenshots
fi
- name: Rename screenshots
if: steps.screenshot-cache.outputs.cache-hit != 'true'
run: |
mkdir -p build/storage
cd build/screenshots
for file in *; do
mv "$file" "../storage/${{ matrix.name }}-$file"
done
- name: Consolidate Screenshots
if: steps.screenshot-cache.outputs.cache-hit != 'true'
run: |
rm -rf build/screenshots
mv build/storage build/screenshots
- uses: actions/upload-artifact@v7
with:
name: candidate-frontend-${{ matrix.name }}-${{ matrix.mode }}
path: build/screenshots
compare:
name: Visual Diff
needs: [baseline, candidate]
runs-on: ubuntu-latest
env:
OUTPUT_DIR: visual-diff-${{ github.event.pull_request.number }}
BASELINE_REF: ${{needs.baseline.outputs.ref}}
CANDIDATE_REF: ${{needs.candidate.outputs.ref}}
steps:
- name: Restore Comparison Cache
id: comparison-cache
uses: actions/cache/restore@v6
with:
path: |
${{ env.OUTPUT_DIR }}
results
key: comparison-${{ env.BASELINE_REF }}-${{ env.CANDIDATE_REF }}
- uses: actions/download-artifact@v8
if: steps.comparison-cache.outputs.cache-hit != 'true'
with:
pattern: baseline-frontend-*
path: baseline-frontend
merge-multiple: true
- uses: actions/download-artifact@v8
if: steps.comparison-cache.outputs.cache-hit != 'true'
with:
pattern: candidate-frontend-*
path: candidate-frontend
merge-multiple: true
- run: ls -lh baseline-frontend candidate-frontend 2>/dev/null || true
- uses: actions/upload-artifact@v7
with:
name: combined-screenshots
path: |
baseline-frontend
candidate-frontend
- uses: actions/setup-node@v7
with:
node-version: 24
- run: |
mkdir -p ./results
echo ${{ github.event.pull_request.number }} > ./results/pr_number
- name: Create Visual Diff
if: steps.comparison-cache.outputs.cache-hit != 'true'
run: |
set +e
npx visual-differ --threshold=0.25 baseline-frontend candidate-frontend ${{ env.OUTPUT_DIR }} > results/visual-diff.txt
exit_code=$?
echo $exit_code > ./results/exit_code
cp ${{ env.OUTPUT_DIR }}/report.md results/
cat results/report.md results/visual-diff.txt
- uses: actions/upload-artifact@v7
id: upload-output
with:
name: ${{ env.OUTPUT_DIR }}
path: ${{ env.OUTPUT_DIR }}
- run: |
echo ${{ steps.upload-output.outputs.artifact-url }} > ./results/artifact_url
echo ${{ contains(github.event.pull_request.labels.*.name, 'approve visual diff') }} > ./results/approved
- name: Save Comparison Cache
if: steps.comparison-cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v6
with:
path: |
${{ env.OUTPUT_DIR }}
results
key: ${{ steps.comparison-cache.outputs.cache-primary-key }}
- uses: actions/upload-artifact@v7
with:
name: results
path: results
- name: Check Status
run: |
exitCode=$(cat ./results/exit_code)
approved=$(cat ./results/approved)
echo "visual-differ exit code: $exitCode"
echo "approve visual diff label present: $approved"
if [ "$exitCode" != "0" ] && [ "$approved" != "true" ]; then
echo "Visual diff detected and 'approve visual diff' label not present."
exit 1
fi