Repository navigation
85 lines (72 loc) · 2.68 KB
/
Copy pathvisual-compare.yml
File metadata and controls
85 lines (72 loc) · 2.68 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
name: Visual Compare
on:
pull_request:
branches:
- main
permissions:
contents: read
jobs:
visual-compare:
name: SVG Visual Consistency
runs-on: ubuntu-latest
steps:
- name: Checkout
id: checkout
uses: actions/checkout@v6
with:
# 需要 base 与 head 的原始提交对象(PR merge commit 的两个父)
fetch-depth: 0
- name: Setup mise
id: setup-mise
uses: jdx/mise-action@v2
# 对比工具维护在独立的孤儿分支上,与主仓库代码解耦
- name: Checkout tool branch
id: checkout-tool
uses: actions/checkout@v6
with:
ref: tools/svg-compare
path: svg-compare-tool
- name: Install tool dependencies
id: tool-install
working-directory: svg-compare-tool
run: bun install --frozen-lockfile
# major 版本不一致说明是有意的破坏性变更:仍然出报告,但不阻止合并
- name: Check major version
id: major-gate
run: |
base_sha='${{ github.event.pull_request.base.sha }}'
base_major=$(git show "$base_sha":package.json | jq -r '.version | split(".")[0]')
head_major=$(jq -r '.version | split(".")[0]' package.json)
echo "enforce=$([ "$base_major" = "$head_major" ] && echo true || echo false)" >> "$GITHUB_OUTPUT"
echo "base $base_major.x / head $head_major.x"
- name: Cache Playwright browsers
id: playwright-cache
uses: actions/cache@v4
with:
path: ~/.cache/ms-playwright
key: playwright-${{ runner.os }}-${{ hashFiles('svg-compare-tool/bun.lock') }}
- name: Install Playwright Chromium
id: playwright-install
working-directory: svg-compare-tool
run: bun x playwright install chromium --with-deps
# src 模式依赖 base 支持 calendarList(v3.3.3 起),base 恒为最新 main
- name: Compare base and head visually
id: compare
continue-on-error: ${{ steps.major-gate.outputs.enforce == 'false' }}
run: |
bun svg-compare-tool/cli.ts ci '${{ github.event.pull_request.base.sha }}' HEAD --via src
- name: Enforce result
id: enforce
if: always() && steps.compare.outcome == 'failure'
run: |
if [ "${{ steps.major-gate.outputs.enforce }}" = "true" ]; then
exit 1
fi
echo "::warning::major 版本不一致,视觉差异仅报告不阻止合并"
- name: Upload report
id: upload-report
if: always()
uses: actions/upload-artifact@v7
with:
name: svg-compare-report
path: .svg-compare/