|
| 1 | +name: Visual Compare |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: read |
| 10 | + |
| 11 | +jobs: |
| 12 | + visual-compare: |
| 13 | + name: SVG Visual Consistency |
| 14 | + runs-on: ubuntu-latest |
| 15 | + |
| 16 | + steps: |
| 17 | + - name: Checkout |
| 18 | + id: checkout |
| 19 | + uses: actions/checkout@v6 |
| 20 | + with: |
| 21 | + # 需要 base 与 head 的原始提交对象(PR merge commit 的两个父) |
| 22 | + fetch-depth: 0 |
| 23 | + |
| 24 | + - name: Setup mise |
| 25 | + id: setup-mise |
| 26 | + uses: jdx/mise-action@v2 |
| 27 | + |
| 28 | + # 对比工具维护在独立的孤儿分支上,与主仓库代码解耦 |
| 29 | + - name: Checkout tool branch |
| 30 | + id: checkout-tool |
| 31 | + uses: actions/checkout@v6 |
| 32 | + with: |
| 33 | + ref: tools/svg-compare |
| 34 | + path: svg-compare-tool |
| 35 | + |
| 36 | + - name: Install tool dependencies |
| 37 | + id: tool-install |
| 38 | + working-directory: svg-compare-tool |
| 39 | + run: bun install --frozen-lockfile |
| 40 | + |
| 41 | + # major 版本不一致说明是有意的破坏性变更:仍然出报告,但不阻止合并 |
| 42 | + - name: Check major version |
| 43 | + id: major-gate |
| 44 | + run: | |
| 45 | + base_sha='${{ github.event.pull_request.base.sha }}' |
| 46 | + base_major=$(git show "$base_sha":package.json | jq -r '.version | split(".")[0]') |
| 47 | + head_major=$(jq -r '.version | split(".")[0]' package.json) |
| 48 | + echo "enforce=$([ "$base_major" = "$head_major" ] && echo true || echo false)" >> "$GITHUB_OUTPUT" |
| 49 | + echo "base $base_major.x / head $head_major.x" |
| 50 | +
|
| 51 | + - name: Cache Playwright browsers |
| 52 | + id: playwright-cache |
| 53 | + uses: actions/cache@v4 |
| 54 | + with: |
| 55 | + path: ~/.cache/ms-playwright |
| 56 | + key: playwright-${{ runner.os }}-${{ hashFiles('svg-compare-tool/bun.lock') }} |
| 57 | + |
| 58 | + - name: Install Playwright Chromium |
| 59 | + id: playwright-install |
| 60 | + working-directory: svg-compare-tool |
| 61 | + run: bun x playwright install chromium --with-deps |
| 62 | + |
| 63 | + - name: Compare base and head visually |
| 64 | + id: compare |
| 65 | + continue-on-error: ${{ steps.major-gate.outputs.enforce == 'false' }} |
| 66 | + run: | |
| 67 | + bun svg-compare-tool/cli.ts ci '${{ github.event.pull_request.base.sha }}' HEAD --via dist |
| 68 | +
|
| 69 | + - name: Enforce result |
| 70 | + id: enforce |
| 71 | + if: always() && steps.compare.outcome == 'failure' |
| 72 | + run: | |
| 73 | + if [ "${{ steps.major-gate.outputs.enforce }}" = "true" ]; then |
| 74 | + exit 1 |
| 75 | + fi |
| 76 | + echo "::warning::major 版本不一致,视觉差异仅报告不阻止合并" |
| 77 | +
|
| 78 | + - name: Upload report |
| 79 | + id: upload-report |
| 80 | + if: always() |
| 81 | + uses: actions/upload-artifact@v7 |
| 82 | + with: |
| 83 | + name: svg-compare-report |
| 84 | + path: .svg-compare/ |
0 commit comments