Skip to content

ci: 添加 PR 视觉一致性检查 - #34

Merged
flycran merged 1 commit into
mainfrom
ci/visual-compare
Nov 6, 2026
Merged

flycran merged 1 commit into
mainfrom
ci/visual-compare

Conversation

@flycran

@flycran flycran commented Nov 6, 2026

Copy link
Copy Markdown
Owner

目的

为 main 分支添加 PR 视觉一致性检查:PR 合入前自动对比 base 与 PR 的生成产物,视觉回归超阈值则阻止合并。

实现

  • 新增 .github/workflows/visual-compare.yml,在 pull_request 时运行
  • 对比工具来自独立的孤儿分支 tools/svg-compare(与主仓库代码解耦,不参与本仓库构建),checkout 到 svg-compare-tool/ 子目录使用
  • A 侧 = github.event.pull_request.base.sha,B 侧 = HEAD(PR 的 merge commit);fetch-depth: 0 保证两者提交对象都在本地,fork PR 同样适用,无需额外 fetch 或 secrets
  • 判定采用三维度独立阈值,全部通过才放行:
    维度 默认阈值
    总时长偏差 ≤ 0.5%
    平均差异 ≤ 0.2%
    最大差异 ≤ 1%
  • 参数组合取自工具分支的 configs/batch/(可在该分支独立维护,不影响主仓库)

major 版本策略

base 与 head 的 major 版本不一致时(如 3.x → 4.x),说明是有意的破坏性变更:仍执行完整对比、上传报告与 artifact,但不因视觉差异阻止合并。

需要的一次性配置

合并后在仓库设置中把 SVG Visual Consistency 配置为 required status check,才能真正阻止合并:

Settings → Branches → Branch protection rules → main → Require status checks to pass → 勾选 SVG Visual Consistency

验证

  • 本 PR 自身会触发该 workflow(只新增了 workflow 文件,src/ 与 dist/ 未变),预期三维度为 0% 并通过
  • workflow YAML 已用 Bun.YAML.parse 校验结构,步骤顺序、hashFiles 路径与 working-directory 均已核对

依赖

  • tools/svg-compare 分支已推送到远程
  • 工具分支的 CI(lint / typecheck / test / 端到端冒烟)在 push 时运行

PR 合入 main 前,用独立的 tools/svg-compare 工具分支对比 base 与 PR
的生成产物:三维度(总时长偏差 / 平均差异 / 最大差异)各自独立阈值,
全部通过才放行,未通过则 job 失败阻止合并。

- A 侧用 github.event.pull_request.base.sha,B 侧用 HEAD(PR merge
  commit);fetch-depth: 0 保证两者对象都在本地,fork PR 同样适用
- major 版本不一致时仍出完整报告并上传 artifact,但不阻止合并
- 工具分支 checkout 到子目录,依赖与 Playwright 浏览器在该目录安装,
  主仓库代码不做改动
@flycran
flycran merged commit 43e233e into main Nov 6, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant