Repository navigation
176 lines (170 loc) · 7.64 KB
/
Copy pathcipher-visual.yml
File metadata and controls
176 lines (170 loc) · 7.64 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
name: Cipher visual check
# Renders the showcase at a baseline ref and a candidate ref, pixel-diffs every snapshot and uploads the
# changed images with a summary. Scoped mode renders only the showcase pages whose examples reach a
# changed source file, and falls back to every page for tokens, global CSS and frame or overlay primitives.
on:
pull_request:
types: [opened, synchronize, reopened, labeled]
paths:
- .github/workflows/cipher-visual.yml
- ci/visual/**
workflow_dispatch:
inputs:
base:
description: Baseline ref (tag, branch or sha). Defaults to the newest release tag.
candidate:
description: Candidate ref
default: main
scope:
description: full or scoped
type: choice
options: [full, scoped]
default: full
permissions:
contents: read
env:
# Any changed pixel counts, antialiasing included. Renders are byte-identical run to run, so a zero
# threshold adds no noise and catches low-contrast fills that pixelmatch's default would miss.
PIXEL_THRESHOLD: "0"
jobs:
prepare:
if: github.event.action != 'labeled' || github.event.label.name == 'cipher-visual:scoped'
runs-on: ubuntu-latest
outputs:
base: ${{ steps.scope.outputs.base }}
candidate: ${{ steps.scope.outputs.candidate }}
pages: ${{ steps.scope.outputs.pages }}
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
fetch-depth: 0
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: 24
- name: Scope
id: scope
env:
BASE: ${{ inputs.base }}
CANDIDATE: ${{ inputs.candidate || 'main' }}
MODE: ${{ inputs.scope || (contains(github.event.pull_request.labels.*.name, 'cipher-visual:scoped') && 'scoped' || 'full') }}
run: |
git fetch -q --tags origin main
[ -n "$BASE" ] || BASE=$(git tag --list 'v*' --sort=-v:refname | head -1)
resolve() { git rev-parse -q --verify "origin/$1^{commit}" 2>/dev/null || git rev-parse "$1^{commit}"; }
base=$(resolve "$BASE")
candidate=$(resolve "$CANDIDATE")
node ci/visual/scope.mjs --cipher . --base "$base" --candidate "$candidate" > /tmp/refs.json
source=$(jq -r .candidate.source /tmp/refs.json)
git worktree add -q --detach /tmp/cand "$source"
node -e '
const fs = require("fs");
const catalog = JSON.parse(fs.readFileSync("/tmp/cand/site/src/catalog.json", "utf8"));
fs.writeFileSync("/tmp/pages.json", JSON.stringify({
alias: { "@infisical/cipher/": "/tmp/cand/src/" },
pages: catalog.map((e) => ({ id: e.id, entries: e.examples.map((x) => "/tmp/cand/site/src/examples/" + x.module + ".tsx") }))
}));'
node ci/visual/scope.mjs --cipher /tmp/cand --base "$base" --candidate "$source" --pages /tmp/pages.json --showcase \
| jq --arg mode "$MODE" --arg b "$BASE" --arg c "$CANDIDATE" '.mode = $mode | .base.ref = $b | .candidate.ref = $c' > scope.json
pages=""
if [ "$MODE" = scoped ] && [ "$(jq .full scope.json)" = false ]; then
pages=$(jq -r '[.pages[].id] | join(",")' scope.json)
[ -n "$pages" ] || pages="none"
fi
echo "base=$(jq -r .base.source scope.json)" >> "$GITHUB_OUTPUT"
echo "candidate=$source" >> "$GITHUB_OUTPUT"
echo "pages=$pages" >> "$GITHUB_OUTPUT"
jq -c '{mode, full, fullReasons, changed, icons, pages: (.pages | length)}' scope.json
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: cipher-visual-scope
path: scope.json
capture:
needs: prepare
if: needs.prepare.outputs.pages != 'none'
runs-on: ubuntu-latest
container:
image: mcr.microsoft.com/playwright:v1.65.0-noble@sha256:9beb546099e11f52d62e505537914870e01a67e0e6b00ae41da4775324e73dbe
options: --ipc=host
strategy:
fail-fast: false
matrix:
side: [base, candidate]
shard: [1, 2, 3, 4, 5, 6, 7, 8]
env:
CI: "1"
HOME: /root
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
ref: ${{ needs.prepare.outputs[matrix.side] }}
path: side
- uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: /root/.npm
key: npm2-${{ hashFiles('package-lock.json', 'side/package-lock.json') }}
restore-keys: npm2-
- name: Install
run: |
npm ci --no-audit --no-fund --prefer-offline
cd side && npm ci --no-audit --no-fund --prefer-offline
- name: Build
run: |
for file in site/visual.html site/src/visual.tsx site/vite.visual.config.ts; do cp "$file" "side/$file"; done
cd side && npx vite build --config site/vite.visual.config.ts --logLevel error
- name: Capture
env:
VISUAL_PAGES: ${{ needs.prepare.outputs.pages }}
VISUAL_CATALOG: ${{ github.workspace }}/side/site/src/catalog.json
VISUAL_SNAPSHOTS: ${{ github.workspace }}/snapshots
VISUAL_URL: http://127.0.0.1:4173/
run: |
[ -n "$VISUAL_PAGES" ] || unset VISUAL_PAGES
(cd side && npx vite preview --config site/vite.visual.config.ts --host 127.0.0.1 --port 4173 --strictPort > /tmp/preview.log 2>&1 &)
for _ in $(seq 60); do curl -sf http://127.0.0.1:4173/visual.html > /dev/null && break; sleep 1; done
npx playwright test visual/visual.spec.ts --shard=${{ matrix.shard }}/8 --update-snapshots=all --pass-with-no-tests --reporter=dot
echo "$(find snapshots -name '*.png' | wc -l) snapshots"
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: snapshots-${{ matrix.side }}-${{ matrix.shard }}
path: snapshots
if-no-files-found: ignore
retention-days: 7
diff:
needs: [prepare, capture]
if: always() && needs.prepare.result == 'success' && (needs.capture.result == 'success' || needs.capture.result == 'skipped')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
with:
sparse-checkout: ci/visual
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: 24
cache: npm
cache-dependency-path: ci/visual/package-lock.json
- if: needs.capture.result == 'success'
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
with:
pattern: snapshots-base-*
path: before
merge-multiple: true
- if: needs.capture.result == 'success'
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
with:
pattern: snapshots-candidate-*
path: after
merge-multiple: true
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0
with:
name: cipher-visual-scope
- name: Diff
run: |
npm ci --prefix ci/visual --no-audit --no-fund
node ci/visual/compare.mjs before after report scope.json >> "$GITHUB_STEP_SUMMARY"
cp scope.json report/
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: cipher-visual-report
path: report
retention-days: 14