-
Notifications
You must be signed in to change notification settings - Fork 38.5k
149 lines (130 loc) · 5.34 KB
/
screenshot-test.yml
File metadata and controls
149 lines (130 loc) · 5.34 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
name: Checking Component Screenshots
on:
push:
branches: [main]
pull_request:
branches:
- main
- 'release/*'
permissions:
contents: read
statuses: write
concurrency:
group: screenshots-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true
jobs:
screenshots:
name: Checking Component Screenshots
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
with:
lfs: true
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version-file: .nvmrc
- name: Install dependencies
run: npm ci --ignore-scripts
env:
ELECTRON_SKIP_BINARY_DOWNLOAD: 1
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Install build dependencies
run: npm ci
working-directory: build
- name: Install build/vite dependencies
run: rm -f package-lock.json && npm install
working-directory: build/vite
- name: Build vite
run: npm run build
working-directory: build/vite
- name: Install Playwright Chromium
run: npx playwright install chromium
- name: Capture screenshots
run: ./node_modules/.bin/component-explorer screenshot --project ./test/componentFixtures/component-explorer.json
- name: Compare screenshots
id: compare
run: |
./node_modules/.bin/component-explorer screenshot:compare \
--project ./test/componentFixtures \
--report ./test/componentFixtures/.screenshots/report
continue-on-error: true
- name: Prepare explorer artifact
run: |
mkdir -p /tmp/explorer-artifact/screenshot-report
cp -r build/vite/dist/* /tmp/explorer-artifact/
if [ -d test/componentFixtures/.screenshots/report ]; then
cp -r test/componentFixtures/.screenshots/report/* /tmp/explorer-artifact/screenshot-report/
fi
- name: Upload explorer artifact
uses: actions/upload-artifact@v7
with:
name: component-explorer
path: /tmp/explorer-artifact/
- name: Upload screenshot report
if: steps.compare.outcome == 'failure'
uses: actions/upload-artifact@v7
with:
name: screenshot-diff
path: |
test/componentFixtures/.screenshots/current/
test/componentFixtures/.screenshots/report/
- name: Set check title
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
REPORT="test/componentFixtures/.screenshots/report/report.json"
STATE="success"
if [ -f "$REPORT" ]; then
CHANGED=$(node -e "const r = require('./$REPORT'); console.log(r.summary.added + r.summary.removed + r.summary.changed)")
TITLE="⚠ ${CHANGED} screenshots changed"
BLOCKS_CI=$(node -e "
const r = require('./$REPORT');
const blocking = Object.entries(r.fixtures).filter(([, f]) =>
f.status !== 'unchanged' && (f.labels || []).includes('blocks-ci')
);
if (blocking.length > 0) {
console.log(blocking.map(([name]) => name).join(', '));
}
")
if [ -n "$BLOCKS_CI" ]; then
STATE="failure"
TITLE="❌ ${CHANGED} screenshots changed (blocks CI: ${BLOCKS_CI})"
fi
else
TITLE="✅ Screenshots match"
fi
SHA="${{ github.event.pull_request.head.sha || github.sha }}"
DETAILS_URL="https://hediet-ghartifactpreview.azurewebsites.net/${{ github.repository }}/run/${{ github.run_id }}/component-explorer/___explorer.html?report=./screenshot-report/report.json&search=changed"
gh api "repos/${{ github.repository }}/statuses/$SHA" \
--input - <<EOF || echo "::warning::Could not create commit status (expected for fork PRs)"
{"state":"$STATE","target_url":"$DETAILS_URL","description":"$TITLE","context":"Component Screenshots"}
EOF
# - name: Post PR comment
# if: github.event_name == 'pull_request'
# env:
# GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# run: |
# COMMENT_MARKER="<!-- screenshot-report -->"
# BODY="$COMMENT_MARKER"$'\n'
#
# if [ -f test/componentFixtures/.screenshots/report.md ]; then
# BODY+=$(cat test/componentFixtures/.screenshots/report.md)
# BODY+=$'\n\n'
# BODY+="📦 [Download the \`screenshot-diff\` artifact](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) to review images."
# else
# BODY+="## Screenshots ✅"$'\n\n'
# BODY+="No visual changes detected."
# fi
#
# # Find existing comment
# EXISTING=$(gh api "repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments" \
# --paginate --jq ".[] | select(.body | startswith(\"$COMMENT_MARKER\")) | .id" | head -1)
#
# if [ -n "$EXISTING" ]; then
# gh api "repos/${{ github.repository }}/issues/comments/$EXISTING" -X PATCH -f body="$BODY"
# else
# gh pr comment "${{ github.event.pull_request.number }}" --body "$BODY"
# fi