Skip to content

ci: 撤回 CI/发版线的 badge job——bot 推不进受保护的 main - #281

Merged
modusensus merged 1 commit into
mainfrom
fix/ci-badge-job
Sep 21, 2026
Merged

modusensus merged 1 commit into
mainfrom
fix/ci-badge-job

Conversation

@modusensus

@modusensus modusensus commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator

背景:main 上的红过一次都不是测试挂的

main 每个 push 都会红一次,红的不是测试——是 badge job。它把双 README 的 tests 徽章刷完后要直推 main,被分支保护拒了:

remote: error: GH006: Protected branch update failed for refs/heads/main.
remote: - 4 of 4 required status checks are expected.
 ! [remote rejected] main -> main (protected branch hook declined)

main 的规则是「4 个必过检查 + 要求分支 up-to-date + 线性历史」,而 job 用的是 GITHUB_TOKENgithub-actions[bot]),不是分支保护的豁免对象,绕过不了 required status checks —— 徽章数字一旦与 README 里的值不一致就必然推送失败。近两次失败 run:

run head 4 个 test 分片 badge job
35498148141 main @9089a71(#273 合并) 全 success failure
35574523739 main @360f7c8(#274 合并) 全 success failure

发版线上那个同类 job 更早就撞了同样的墙:v0.8.3 的 release run(35183572919)里 badge 同因 GH006 失败,整个 release 流程因此被判成 failure。

也就是说这不是偶发,而是「bot 推受保护分支」的结构性不可行:只要 worker 没有分支保护的豁免身份,这个 job 就永远红的。而 README 的 CI 徽章(workflow/status/.../ci.yml)读的正是 main 最新一次 run 的结论,所以它显示红是如实的——删徽章只是把红点藏起来,Actions 页每次 push 照样红一次。

改动

  1. .github/workflows/ci.yml:撤掉 badge job(回到 ci: tests 徽章动态对齐(badge job 进 CI)+ 徽章刷到当前 1242 #273 之前)。job 图回到只有 test,顶层 permissions: contents: read 之外不再有持有 contents: write 的 job —— 顺带把 CI 的写权限面收窄回原状。
  2. .github/workflows/release.yml:同样撤掉 badge job(同一个缺陷面),并把 notifyneeds 与运行摘要表里的 badge 行一并去掉,不留悬空 needs。徽章改为发版前本地 npm run badge:sync 与人工发布同一次提交带上。
  3. dsh-mneme/scripts/sync-test-badge.mjs:徽章计数从 pass N 改为套件总数 tests N。平台条件跳过的用例(test/runtime-adopt.test.js:130,Windows 未开开发者模式时无法 symlinkSync)不计入 pass 但计入 tests,因此本机(Windows)跑出来是 pass 1246、CI(ubuntu)是 pass 1247 —— 取套件总数后两边同值,不再需要「本机数字 + 1」这类手工对齐。同时把 # N 个 node:test 测试 这种注释形状纳入同一处维护(此前只覆盖徽章 / # N 个测试 / # N tests,目录注释里那处漏刷,停在 1160)。
  4. 双 README:tests 计数 1242 / 1160 → 1247(徽章 + 两处命令注释 + 目录注释),全部由 npm run badge:sync 写入,仓库内无手编数字。

前提是同意「徽章追平不再由流水线自动做」。若以后想要自动化,可行路径是让 job 开 PR 而不是直推 main(多一次人工合并),或者给 bot 一个分支保护豁免的 App 身份 —— 都超出「回退缺陷」的范围,需要的话另开 issue 定。

验证

  • npm test(包目录内):ℹ tests 1247 · suites 6 · pass 1246 · fail 0 · skipped 1,唯一跳过项即上面那例平台断言(跨平台全绿口径以 ubuntu 为准)。
  • npm run badge:sync 复跑幂等:tests=1247, files changed=0 —— 第二次运行零改动,说明写入完全由脚本驱动。
  • 两个 workflow 文件 YAML 解析通过,job 图对齐:ci.yml = [test]release.yml = [verify, test, publish, release, notify]notify.needs = [verify, test, publish, release],无残留 needs.badge 引用。
  • 徽章 URL 口径未变(仍是 shields 静态徽章 badge/tests-1247%20passed-…),不引入第三方动态源。

合并后的观察点

main 下一次 push 的 CI 应只剩 test 一个 job 且全绿;README 的 CI 徽章随该 run 回绿,无需额外动作。发版链路的徽章步骤改为发版前本地执行,发布提交里一并带上。

Summary by CodeRabbit

  • 文档

    • 更新中英文 README 中的测试徽章及通过测试数量,由 1242 调整为 1247。
    • 同步更新项目架构和开发说明中的测试数量,确保文档信息一致。
  • 维护改进

    • 移除 CI 和发布流程中的自动徽章同步步骤,发布通知不再包含徽章同步状态。
    • 测试徽章同步现支持手动执行,并改进测试总数识别及异常处理。

两个 badge job 都要把徽章改动直推 main,而 main 的规则是「4 个必过检查 +
要求分支 up-to-date + 线性历史」,job 用的 GITHUB_TOKEN(github-actions[bot])
不是分支保护的豁免对象,绕过不了 required status checks——数字一与 README
不一致就必被拒:

    remote: error: GH006: Protected branch update failed for refs/heads/main.
    remote: - 4 of 4 required status checks are expected.

结果:每次 push 到 main 都红一次,而 4 个 test 分片全绿(test 不是红的那个);
发版线的同类 job 更早就在 v0.8.3 的 release run 里同因失败,把整个 release
判成 failed。徽章改回发版前本地 `npm run badge:sync`,与人工发布同一次提交
带上。

- ci.yml:撤掉 badge job(回到 900400e 之前)——job 图只剩 test,顶层
  permissions: contents: read 之外不再有持有 contents: write 的 job
- release.yml:同样撤掉 badge job,并去掉 notify 的 needs 里的 badge 与
  运行摘要表里的对应行(无悬空 needs)
- scripts/sync-test-badge.mjs:徽章计数从 `pass N` 改为套件总数 `tests N`
  ——平台条件跳过的用例(Windows 未开开发者模式时的符号链接断言)不计入
  pass 但计入 tests,取总数即与 CI(ubuntu)口径一致,不必手工修数字;
  顺带把 `# N 个 node:test 测试` 注释形状纳入同一处维护(此前漏刷,停在 1160)
- 双 README:tests 计数 1242 / 1160 → 1247(徽章 + 两处命令注释 + 目录注释),
  由脚本写入,非手改
Copilot AI lite review requested due to automatic review settings September 21, 2026 14:50

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Sep 21, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

Understand this PR’s impact

Explore downstream dependencies and potential security impact with Blast Radius.

View blast radius →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: slow-stack/dsh-mneme/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 649af497-9d37-41ca-96a3-e0c5b71e230b

📥 Commits

Reviewing files that changed from the base of the PR and between 360f7c8 and 5e89289.

📒 Files selected for processing (5)
  • .github/workflows/ci.yml
  • .github/workflows/release.yml
  • README.md
  • dsh-mneme/README.md
  • dsh-mneme/scripts/sync-test-badge.mjs
💤 Files with no reviewable changes (1)
  • .github/workflows/ci.yml

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

本次变更将徽章同步从 CI 和发布流程中移除,改为手动执行。同步脚本改用测试总数解析,并更新两个 README 中的测试数量。

Changes

徽章同步流程调整

Layer / File(s) Summary
手动徽章同步脚本
dsh-mneme/scripts/sync-test-badge.mjs
脚本解析最后一个 ℹ tests N 作为测试总数,支持更多注释格式,并在解析失败或测试未通过时返回非零状态。
工作流自动同步移除
.github/workflows/ci.yml, .github/workflows/release.yml
CI 和发布工作流移除 badge job。发布通知任务不再依赖该 job,也不再显示其状态。
README 测试数量更新
README.md, dsh-mneme/README.md
两个 README 的徽章和测试说明中的数量从旧值更新为 1247。

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~15 minutes

Change: Bug fix

Suggested reviewers: anans-ivresse

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了主要变更:撤回 CI 和发版流程中的 badge job,并说明了受保护 main 阻止 bot 推送的原因。标题简洁、具体,符合变更内容。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Sep 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@modusensus
modusensus merged commit b381dbd into main Sep 21, 2026
11 of 12 checks passed
@modusensus
modusensus deleted the fix/ci-badge-job branch September 21, 2026 15:03
modusensus added a commit that referenced this pull request Sep 21, 2026
CHANGELOG 的 [Unreleased] 转为 v0.8.6 小节,并补上三份未登账的改动:
工具暴露开关与描述纪律(#276)、蒸馏游标持久化(#229/#274)与旧宿主降级路径
(#279)、能力说明第 5 条文案精确性(#277)、CI 与徽章口径收敛(#281/#273/#272)。
两个 README 的 v0.8.6 占位行补描述(版本历史 + 路线图),测试徽章与注释数按
badge:sync 对齐到 1275。
modusensus added a commit that referenced this pull request Sep 21, 2026
* chore: v0.8.6 发布准备(版本号 + 测试徽章 + CHANGELOG/路线图占位行)

请在 CHANGELOG 与两个 README 的占位行补描述后再合并。

* chore(release): v0.8.6 发布说明与路线图补齐

CHANGELOG 的 [Unreleased] 转为 v0.8.6 小节,并补上三份未登账的改动:
工具暴露开关与描述纪律(#276)、蒸馏游标持久化(#229/#274)与旧宿主降级路径
(#279)、能力说明第 5 条文案精确性(#277)、CI 与徽章口径收敛(#281/#273/#272)。
两个 README 的 v0.8.6 占位行补描述(版本历史 + 路线图),测试徽章与注释数按
badge:sync 对齐到 1275。

---------

Co-authored-by: modusensus <modusensus@users.noreply.github.com>
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.

2 participants