fix(ci): never render a budget FAIL for a run that measured nothing - #3198
Merged
Merged
Conversation
A cancelled Bundle Analysis run posted "❌ Console Performance Budget / Status: FAIL" with all three metrics empty. `cancel-in-progress` kills the first run on every second push, so every PR pushed twice within one build got a fake budget alarm — run 30699128418 (cancelled) said FAIL while 30699202638 (success, same commit) measured 28.1 KB against a 350 KB budget. Cause: the comment step was gated on `always()`, which fires on cancellation too, and its renderer treated "not pass" as FAIL — so an absent measurement became a verdict. - Gate the comment on `!cancelled()`, not `always()`: a cancelled run posts nothing, because the superseding run posts the real verdict moments later. - Render FAIL only when the bundle was measured AND over budget. A run that produced nothing measurable gets a neutral "not measured" note that states it is not a budget violation. - Make the budget step declare `budget_status=error` on its two "nothing to measure" exits instead of leaving every output empty, so the renderer reads an outcome rather than inferring one from silence. - Generate the package size report only from a complete package build. Under `always()` it ran against a partially built `packages/*/dist` and emitted a report that was silently missing 7 packages, which made the fake FAIL look like a complete, credible report. Rendering moves out of the YAML into scripts/render-budget-comment.mjs so it can be unit tested — the bug was purely a rendering bug, and logic inlined in a `script:` block cannot be covered by any test. Fixes #3152 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PRJtkgUAaVG11FsJQbvZWA
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3152
问题
.github/workflows/performance-budget.yml在运行被取消时仍会发一条 ❌ FAIL 评论,而预算从未被测量过。工作流设了concurrency: cancel-in-progress: true,这意味着每个连推两次提交的 PR 都会收到这条假警报。同一份代码上的对照:运行
30699128418(cancelled)判 FAIL 且三项指标全空;运行30699202638(success)判 PASS,实测 28.1 KB / 350 KB —— 只用掉预算的 8%。两处机制:
if: ... && always()。always()在运行被取消时照样触发;而渲染逻辑把「非 pass」等同于 FAIL(status === 'pass' ? '✅' : '❌'),于是「没测到」被渲染成了「测到了且超标」。Generate package size report同样是if: always(),取消时它对着只构建了一部分的packages/*/dist跑完并输出 —— 报告少了 7 个包(app-shell、plugin-calendar、plugin-designer、plugin-gantt、plugin-kanban、plugin-report、plugin-view)却看不出缺失,让那条假 FAIL 更像一份可信的完整报告。改动
门禁语义:FAIL 必须带着数字。
!cancelled()而不是always()。被取消的运行不再发任何评论 —— 取代它的那次运行几十秒后就会给出真实结论。budget_status是pass/fail,并且 gzip 大小、预算、入口文件名三项都在。真实超标必然带着这三个数字,这正是 issue 里点出的可判别信号。让生产者声明结果,而不是让消费者从「空」去猜。
budget步骤原本有两条退出路径(dist 目录不存在、找不到 JS 文件)什么 output 都不写。现在它们显式写budget_status=error和一条budget_message。消费者读到的是一个声明过的结果,而不是靠空字符串反推。同理,渲染器用的是显式白名单MEASURED_STATUSES,而不是status !== 'pass'那个取反 —— 正是那个取反把「没有数据」变成了「FAIL」。半截报告。
Generate package size report改成if: !cancelled() && steps.build_packages.outcome == 'success',只在包全部构建完成后才生成。生成不出来时评论里会写明「没有体积报告」,而不是静默省略 —— 因为一份被截断的报告读起来和完整的一模一样。渲染逻辑搬出 YAML。
scripts/render-budget-comment.mjs,评论步骤改为node scripts/render-budget-comment.mjs > budget-comment.md,step outputs 经env:传入而不是插值进 JS 字符串字面量。这个 bug 本身就是一个渲染 bug,而内联在script:块里的逻辑没有任何测试能覆盖它。现在它由scripts/__tests__/render-budget-comment.test.ts覆盖(17 个用例),其中 6 个是钉住工作流本身的 pin test(禁止always()、!cancelled()的三处、报告的构建门、env 契约、budget_status的三种取值)。每条退出路径的预期行为
errorerrorpassfail验证
1. YAML 可解析,步骤条件符合预期
2. 把
budget步骤的 shell 原样从 YAML 里抽出来执行,逐条验证 output3. 把 PATH D 的 output 原样喂给渲染器(端到端):真实超标信号完全保留
4. 取消 / 未测量路径:不再有 ❌,也不再有 FAIL
5. 测试与静态检查
注:本 PR 只改动
.github/**、scripts/**、vitest.config.mts和 docs,不匹配performance-budget.yml自己的 paths 过滤器(packages/**、apps/console/**、pnpm-lock.yaml),所以这个工作流不会在本 PR 上运行。这也正是为什么渲染逻辑被搬进了可单测的文件,而不是留在 YAML 里靠 CI 碰运气。关于 changeset
按 AGENTS.md §9「纯 bug 修复不需要 changeset」,且本次改动不触及任何已发布包的源码(只有 CI 工作流、仓库级 CI 脚本、vitest 配置和文档),没有版本需要 bump。仓库里唯一的 changeset 门禁
scripts/check-changeset-fixed.mjs校验的是 fixed group 成员资格,不要求每个 PR 都带 changeset,已通过。顺带发现(未在本 PR 修)
content/docs/guide/ci-cd-pipeline.md把 console 主入口预算写成 60 KB(实际 350 KB),记录了一个已不存在的size-check.yml,并把三档「建议值」标成了 Enforced limits。按 Prime Directive [WIP] Enhance every detail of the designer #10 单独立 issue,未夹带进本 PR。本 PR 只改了同一节里描述 PR 评论行为的那条 bullet —— 那正是本次改掉的行为。🤖 Generated with Claude Code
https://claude.ai/code/session_01PRJtkgUAaVG11FsJQbvZWA
Generated by Claude Code