Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions .github/workflows/visual-compare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
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

- 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 dist

- 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/
Loading