Skip to content

Commit 5e89289

Browse files
committed
ci: 撤回 CI/发版线的 badge job——bot 推不进受保护的 main
两个 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(徽章 + 两处命令注释 + 目录注释), 由脚本写入,非手改
1 parent 360f7c8 commit 5e89289

5 files changed

Lines changed: 30 additions & 102 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ name: CI
66
# 2. 新增 src/↔lib/ 一致性守门(scripts/check-sync.js,v0.7.9 引入的发布前校验前置到 CI)。
77
# 3. Codecov 只在 ubuntu+node24 一个分片跑一次(覆盖率无需每个组合都传)。
88
# 4. node_modules 缓存(cache-dependency-path 指向子目录的 lockfile)。
9-
# 5. main 徽章对齐 job:把双 README 的 tests 徽章刷成最新全量 pass 数——
10-
# 复用发版线的 badge:sync(脚本自带「测试不绿不刷徽章」),让数字不再
11-
# 只在发版时才追平。仅 push 到 main 时跑(PR 上没有可写回的对象)。
129
# ⚠️ 需要 package.json 配合一处小改(跨平台通配符):
1310
# dsh-mneme/package.json 的 "test": "node --test test/*.test.js" 在 Windows 的 cmd 下
1411
# 不展开 glob。建议改为 "test": "node --test test/"(目录模式,全平台等价),
@@ -66,42 +63,3 @@ jobs:
6663
token: ${{ secrets.CODECOV_TOKEN }}
6764
files: dsh-mneme/coverage/lcov.info
6865
fail_ci_if_error: false
69-
70-
# 双 README 的 tests 徽章自动对齐最新全量 pass 数(复用发版线的 badge:sync,
71-
# 脚本自带「测试不绿不刷徽章」)。只在 push 到 main 时跑:PR 上跑也刷不回
72-
# 基分支,反而拖慢每个 PR;已同步时脚本零改动、job 零提交。
73-
badge:
74-
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
75-
runs-on: ubuntu-latest
76-
permissions:
77-
contents: write
78-
steps:
79-
- uses: actions/checkout@v4
80-
with:
81-
ref: main
82-
83-
- uses: actions/setup-node@v4
84-
with:
85-
node-version: 24
86-
cache: npm
87-
cache-dependency-path: dsh-mneme/package-lock.json
88-
89-
- name: Install dependencies
90-
working-directory: dsh-mneme
91-
run: npm ci
92-
93-
- name: Sync test badge & counts (runs full suite)
94-
working-directory: dsh-mneme
95-
run: npm run badge:sync
96-
97-
- name: Commit & push if changed
98-
run: |
99-
if git diff --quiet; then
100-
echo "badge already in sync — nothing to commit"
101-
else
102-
git config user.name "github-actions[bot]"
103-
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
104-
git add README.md dsh-mneme/README.md
105-
git commit -m "chore(readme): 测试徽章自动对齐(CI main,pass 数追平)"
106-
git push origin main
107-
fi

‎.github/workflows/release.yml‎

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -178,48 +178,13 @@ jobs:
178178
gh release create "v${VERSION}" --title "v${VERSION}" --notes-file notes/body.md
179179
fi
180180
181-
# ── 5. 徽章对齐:跑一遍全量测试,把双 README 的 tests 徽章与计数注释 ──────
182-
# 自动刷成当前 pass 数并提交回 main——发版后徽章不再靠手工追平。
183-
# checkout main(徽章是对 main 的持续承诺,不属于 tag 快照);测试没跑绿
184-
# 时脚本以非零退出且不改任何文件。幂等:已同步则零提交。
185-
badge:
186-
needs: [verify, test]
187-
if: github.event_name == 'push'
188-
runs-on: ubuntu-latest
189-
steps:
190-
- uses: actions/checkout@v4
191-
with:
192-
ref: main
193-
194-
- uses: actions/setup-node@v4
195-
with:
196-
node-version: 24
197-
cache: npm
198-
cache-dependency-path: dsh-mneme/package-lock.json
199-
200-
- name: Install dependencies
201-
working-directory: dsh-mneme
202-
run: npm ci
203-
204-
- name: Sync test badge & counts (runs full suite)
205-
working-directory: dsh-mneme
206-
run: npm run badge:sync
207-
208-
- name: Commit & push if changed
209-
run: |
210-
if git diff --quiet; then
211-
echo "badge already in sync — nothing to commit"
212-
else
213-
git config user.name "github-actions[bot]"
214-
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
215-
git add README.md dsh-mneme/README.md
216-
git commit -m "chore(readme): 测试徽章自动对齐 v${{ needs.verify.outputs.version }}(release 流水线)"
217-
git push origin main
218-
fi
219-
220-
# ── 6. 通知与运行摘要(接入外部通知时往这里加一步 webhook 即可)────────────
181+
# ── 5. 通知与运行摘要(接入外部通知时往这里加一步 webhook 即可)────────────
182+
# 徽章对齐不在流水线里做:main 受保护(4 个必过检查 + strict + 线性历史),
183+
# github-actions[bot] 的 GITHUB_TOKEN 绕过不了 required status checks,
184+
# push 必被 GH006 拒(v0.8.3 实测),改由发版前本地跑 npm run badge:sync,
185+
# 与人工发布同一次提交带上。
221186
notify:
222-
needs: [verify, test, publish, release, badge]
187+
needs: [verify, test, publish, release]
223188
if: always()
224189
runs-on: ubuntu-latest
225190
steps:
@@ -234,7 +199,6 @@ jobs:
234199
echo "| test (win/linux × node 22/24) | ${{ needs.test.result }} |"
235200
echo "| publish (npm) | ${{ needs.publish.result }} |"
236201
echo "| release (GitHub) | ${{ needs.release.result }} |"
237-
echo "| badge (auto-sync) | ${{ needs.badge.result }} |"
238202
} >> "$GITHUB_STEP_SUMMARY"
239203
# 可选:企业微信/Telegram/邮件 webhook。配置 secret(如 NOTIFY_WEBHOOK)后取消注释:
240204
# - name: Notify webhook

‎README.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-3E63DD?style=flat-square" alt="license"></a>
1111
<a href="https://github.com/slow-stack/dsh-mneme/actions"><img src="https://img.shields.io/github/actions/workflow/status/slow-stack/dsh-mneme/ci.yml?style=flat-square&label=CI" alt="CI"></a>
1212
<a href="https://nodejs.org"><img src="https://img.shields.io/badge/node-22%2B-3E63DD?style=flat-square&logo=nodedotjs&logoColor=white" alt="node"></a>
13-
<a href="https://github.com/slow-stack/dsh-mneme"><img src="https://img.shields.io/badge/tests-1242%20passed-3E63DD?style=flat-square" alt="tests"></a>
13+
<a href="https://github.com/slow-stack/dsh-mneme"><img src="https://img.shields.io/badge/tests-1247%20passed-3E63DD?style=flat-square" alt="tests"></a>
1414
<a href="https://codecov.io/gh/slow-stack/dsh-mneme"><img src="https://img.shields.io/codecov/c/github/slow-stack/dsh-mneme/main?style=flat-square" alt="coverage"></a>
1515
<a href="https://github.com/awesome-dsh-plugin/awesome-dsh-plugin"><img src="https://awesome-dsh-plugin.com/badge.svg" alt="Awesome"></a>
1616
</p>
@@ -161,7 +161,7 @@ dsh web
161161

162162
```bash
163163
cd dsh-mneme && npm install
164-
npm test # 1242 个测试
164+
npm test # 1247 个测试
165165
npm run stress # 三轴线压测
166166
npm run sync # src → lib 同步
167167
```
@@ -322,7 +322,7 @@ It works out of the box. To feel its value in five minutes:
322322

323323
```bash
324324
cd dsh-mneme && npm install
325-
npm test # 1242 tests
325+
npm test # 1247 tests
326326
npm run stress # three-axis stress test
327327
npm run sync # src → lib sync
328328
```

‎dsh-mneme/README.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[![npm version](https://img.shields.io/npm/v/@modusensus/dsh-mneme?color=blue&label=npm)](https://www.npmjs.com/package/@modusensus/dsh-mneme)
66
[![license](https://img.shields.io/badge/license-MIT-green)](LICENSE)
77
[![Awesome](https://awesome-dsh-plugin.com/badge.svg)](https://github.com/awesome-dsh-plugin/awesome-dsh-plugin)
8-
[![tests](https://img.shields.io/badge/tests-1242%20passed-success)](https://github.com/slow-stack/dsh-mneme)
8+
[![tests](https://img.shields.io/badge/tests-1247%20passed-success)](https://github.com/slow-stack/dsh-mneme)
99
[![CI](https://img.shields.io/github/actions/workflow/status/slow-stack/dsh-mneme/ci.yml)](https://github.com/slow-stack/dsh-mneme/actions)
1010
[![node](https://img.shields.io/badge/node-22%2B-blue)](https://nodejs.org)
1111
[![npm downloads](https://img.shields.io/npm/d18m/@modusensus/dsh-mneme.svg?color=blue&label=downloads)](https://www.npmjs.com/package/@modusensus/dsh-mneme)
@@ -683,7 +683,7 @@ src/
683683
├── api.js # HTTP 路由(Web 面板数据通道,含 /conflicts 冲突队列)
684684
└── index.js # 插件接线
685685
lib/ # src 的同步分发产物(npm run sync;发布前由 root prepack 的 check-sync.js 校验一致性;唯一手写例外 lib/client.js——Web 面板 bundle,sync 不覆盖)
686-
test/ # 1160 个 node:test 测试(审计与三轴线压测不变量;src↔lib 一致性由 scripts/check-sync.js 发布闸门校验)
686+
test/ # 1247 个 node:test 测试(审计与三轴线压测不变量;src↔lib 一致性由 scripts/check-sync.js 发布闸门校验)
687687
scripts/ # e2e-dsh.js 端到端演示 · stress-dsh.js 三轴线压测 · sync-lib.js 同步 · check-sync.js 发布闸门 · benchmark-recall.js / benchmark-embed.js / benchmark-rerank.js 基准 · sync-test-badge.mjs 测试徽章 · build-runtime-manifest.mjs 运行时清单
688688
```
689689
@@ -692,7 +692,7 @@ scripts/ # e2e-dsh.js 端到端演示 · stress-dsh.js 三轴线压
692692
```bash
693693
cd dsh-mneme
694694
npm install # 安装 peer 依赖(以 devDependencies 形式,用于本地测试)
695-
npm test # 运行 1160 个测试
695+
npm test # 运行 1247 个测试
696696
npm run stress # 三轴线压测:长会话检索 / 冲突仲裁 / 多 Agent 并发(离线 mock LLM)
697697
npm run sync # 把 src/ 同步到 lib/(发布时由 prepack 钩子自动执行)
698698
```

‎dsh-mneme/scripts/sync-test-badge.mjs‎

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
// 发版流水线的徽章对齐(release.yml 的 badge job 调用;手动可跑 npm run badge:sync)。
1+
// 发版前对齐徽章(手动跑 npm run badge:sync;release.yml 不再有 badge job ——
2+
// main 受保护,github-actions[bot] 的 GITHUB_TOKEN 绕过不了 required status
3+
// checks,push 必被 GH006 拒)。
24
//
35
// 做三件事:
4-
// 1. 跑一遍全量测试(npm test),取最后的 `pass N` 汇总数;
6+
// 1. 跑一遍全量测试(npm test),取套件总数(`ℹ tests N` 汇总行);
57
// 2. 把双 README 的 tests 徽章(img.shields.io/badge/tests-N%20passed)与
6-
// 开发命令注释(# N 个测试 / # N tests)刷成该数字;
8+
// 开发命令注释(# N 个测试 / # 运行 N 个测试 / # N 个 node:test 测试 /
9+
// # N tests)刷成该数字;
710
// 3. 有变化就写回文件(由调用方决定是否 commit/push),无变化静默退出。
811
//
912
// 测试失败(fail>0 或进程非零退出)时以非零退出且不改任何文件——徽章永远
@@ -32,11 +35,14 @@ try {
3235
process.exit(1);
3336
}
3437

35-
// 2) 取汇总 pass 数(spec reporter 的 `ℹ pass N`;取最后一处防逐用例行干扰)
36-
const matches = [...output.matchAll(/pass (\d+)/g)];
37-
const pass = matches.length ? Number(matches[matches.length - 1][1]) : 0;
38-
if (!pass) {
39-
console.error("无法从测试输出解析 pass 数,徽章不更新");
38+
// 2) 取套件总数(spec reporter 的 `ℹ tests N`;取最后一处防逐用例行干扰)
39+
// 用总数而非 `pass N`:平台条件跳过的用例(如 Windows 未开开发者模式时的
40+
// 符号链接断言)在 pass 里不计、在 tests 里计入,而徽章报的是 CI(ubuntu)
41+
// 口径 —— 用总数则本地在 Windows 跑也得到同一个数,不必手工修。
42+
const matches = [...output.matchAll(/ℹ tests (\d+)/g)];
43+
const count = matches.length ? Number(matches[matches.length - 1][1]) : 0;
44+
if (!count) {
45+
console.error("无法从测试输出解析套件总数,徽章不更新");
4046
process.exit(1);
4147
}
4248

@@ -49,13 +55,13 @@ let changed = 0;
4955
for (const file of targets) {
5056
let text = readFileSync(file, "utf8");
5157
const next = text
52-
.replace(/tests-\d+%20passed-/g, `tests-${pass}%20passed-`)
53-
.replace(/(#\s*)\d+( 个测试)/g, `$1${pass}$2`)
54-
.replace(/(#\s*)\d+( tests)/g, `$1${pass}$2`);
58+
.replace(/tests-\d+%20passed-/g, `tests-${count}%20passed-`)
59+
.replace(/(#\s*(?:运行\s*)?)\d+( 个(?:\s*node:test)?\s*测试)/g, `$1${count}$2`)
60+
.replace(/(#\s*)\d+( tests)/g, `$1${count}$2`);
5561
if (next !== text) {
5662
writeFileSync(file, next);
5763
changed += 1;
5864
console.log(`updated: ${file}`);
5965
}
6066
}
61-
console.log(`pass=${pass}, files changed=${changed}`);
67+
console.log(`tests=${count}, files changed=${changed}`);

0 commit comments

Comments
 (0)