-
Notifications
You must be signed in to change notification settings - Fork 109
160 lines (139 loc) · 5.83 KB
/
Copy pathvisual-regression.yml
File metadata and controls
160 lines (139 loc) · 5.83 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
name: Visual regression
on: [pull_request]
concurrency:
group: gh-pages
cancel-in-progress: false
jobs:
visual-regression:
name: Capture, diff, and publish report
runs-on: ubuntu-latest
container:
image: cypress/browsers:latest
options: --user 1001
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- uses: pnpm/action-setup@v6
- uses: actions/setup-node@v6
with:
node-version: '24'
cache: 'pnpm'
- name: Cache Cypress binary
uses: actions/cache@v5
with:
path: ~/.cache/Cypress
key: ${{ runner.os }}-cypress-${{ hashFiles('regression-test/package-lock.json') }}
- name: Build InstUI
run: pnpm install --frozen-lockfile && pnpm run bootstrap
- name: Install regression-test dependencies
run: npm ci
working-directory: regression-test
- name: Install Cypress binary
run: npx cypress install
working-directory: regression-test
- name: Fetch baselines
run: |
mkdir -p regression-test/.baselines
if git fetch origin visual-baselines 2>/dev/null; then
git worktree add /tmp/baselines-wt origin/visual-baselines
cp -r /tmp/baselines-wt/screenshots/. regression-test/.baselines/ 2>/dev/null || echo "::warning::baselines branch has no screenshots/ dir"
git worktree remove --force /tmp/baselines-wt
else
echo "::warning::visual-baselines branch does not exist — first run, everything will be 'added'"
fi
- name: Run Cypress
id: cypress
uses: cypress-io/github-action@v7
continue-on-error: true
env:
ELECTRON_EXTRA_LAUNCH_ARGS: "--remote-debugging-port=9222"
with:
install: false
build: npm run build
start: npm start
working-directory: regression-test
- name: Flatten screenshots
run: |
mkdir -p regression-test/.actual
find regression-test/cypress/screenshots -name '*.png' -exec cp {} regression-test/.actual/ \;
- name: Diff and generate report
id: diff
working-directory: regression-test
run: >
npx ui-scripts visual-diff
--actual-dir .actual
--baseline-dir .baselines
--output-dir .report
--no-fail-on-missing-baseline
--pr-number ${{ github.event.pull_request.number }}
--pr-url ${{ github.event.pull_request.html_url }}
--meta cypress/meta.json
--source-base-url https://github.com/${{ github.repository }}/blob/${{ github.head_ref }}/regression-test/src/app
continue-on-error: true
- name: Publish report to gh-pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: regression-test/.report
publish_branch: gh-pages
destination_dir: visual-regression/pr-${{ github.event.pull_request.number }}
keep_files: true
commit_message: "visual-regression: PR #${{ github.event.pull_request.number }} (${{ github.sha }})"
- name: Read summary
id: summary
env:
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
node -e "
const fs = require('fs');
const { summary: s, results } = JSON.parse(fs.readFileSync('regression-test/.report/summary.json', 'utf8'));
const base = 'https://instructure.design/visual-regression/pr-' + process.env.PR_NUMBER;
const interesting = results.filter(r => r.status === 'changed' || r.status === 'removed');
let md = '';
if (interesting.length) {
md = '<details>\n<summary>Diff images (' + interesting.length + ')</summary>\n\n';
for (const r of interesting) {
if (r.status === 'changed') {
md += '#### ' + r.name + ' — ' + r.numDiff + ' pixels differ\n\n';
md += '\n\n';
} else {
md += '#### ' + r.name + ' — baseline no longer produced\n\n';
}
}
md += '</details>';
}
const lines = [
'total=' + s.total,
'unchanged=' + s.unchanged,
'changed=' + s.changed,
'added=' + s.added,
'removed=' + s.removed,
'status=' + (s.changed > 0 || s.removed > 0 ? '⚠️ **Changes detected.**' : '✅ **No changes.**')
];
let out = lines.join('\n') + '\n';
out += 'diff_images<<DIFFIMAGES_EOF\n' + md + '\nDIFFIMAGES_EOF\n';
fs.appendFileSync(process.env.GITHUB_OUTPUT, out);
"
- name: Post PR comment
uses: marocchino/sticky-pull-request-comment@v3
with:
header: visual-regression
message: |
## Visual regression report
${{ steps.summary.outputs.status }}
| Status | Count |
|---|---|
| Unchanged | ${{ steps.summary.outputs.unchanged }} |
| Changed | ${{ steps.summary.outputs.changed }} |
| New | ${{ steps.summary.outputs.added }} |
| Removed | ${{ steps.summary.outputs.removed }} |
📊 **[View full report](https://instructure.design/visual-regression/pr-${{ github.event.pull_request.number }}/index.html)**
${{ steps.summary.outputs.diff_images }}
<sub>Baselines come from the `visual-baselines` branch. They refresh on every merge to `master`.</sub>
- name: Fail if regressions or Cypress failed
if: steps.diff.outcome == 'failure' || steps.cypress.outcome == 'failure'
run: exit 1