Skip to content

Commit 91cbb84

Browse files
ci: 测试矩阵扩展为 windows/linux × node 22/24,发布改为完整流水线 (#75)
* ci: 测试矩阵扩展为 windows/linux × node 22/24,发布改为完整流水线 - test.yml → ci.yml:双平台(ubuntu/windows)× 双版本(node 22/24)矩阵, fail-fast 关闭;src↔lib 一致性校验(scripts/check-sync.js)前置到 CI; Codecov 只在 ubuntu+node24 分片上报;新增 npm 依赖缓存 - publish.yml → release.yml:v* tag 触发完整流水线 verify(tag↔package.json↔CHANGELOG 三方一致性)→ test(双平台全量) → publish(沿用 root 版本同步 + skip-if-exists 幂等守卫) → release(GitHub Release,说明自动抽取 dsh-mneme/CHANGELOG.md 对应小节) → notify(Step Summary + webhook 预留位);workflow_dispatch 支持 dry_run - dsh-mneme/package.json:test 脚本 test/*.test.js → test/(目录模式), Windows cmd 不展开 glob,跨平台矩阵需要目录模式 * fix(ci): 还原 test 脚本为 test/*.test.js —— node --test 自带 glob 展开(≥22),目录形式 test/ 反而在 22/24 上被当作模块路径 require 而全平台失败(实测 node 24 win/cmd 612 全过) * fix(ci): release.yml 在 dsh-mneme/ 子目录发布,不碰 root 壳版本 - Publish job 加 working-directory: dsh-mneme(发布根 = dsh-mneme/package.json, 真实版本 + prepack 自动 npm run sync 同步 src→lib,与 v0.7.12/0.7.13 本机发布包结构一致) - 删除「Sync root version from dsh-mneme」步骤:root package.json 是编排壳 (版本停在 0.7.2),不参与 npm 发布,root 与子目录版本无需同步 - 顶部注释更新为子目录发布说明 Co-Authored-By: Anans-Ivresse <[email protected]> * chore(ci): 恢复 check-sync.js(v0.7.12 重写删除,但 CI/发布闸门仍引用) v0.7.12(dd0ed78)重写时误删了 scripts/check-sync.js,而 ci.yml 的 「Sync check (src↔lib)」步骤、release.yml 的 test job 都引用它(node scripts/check-sync.js)。 历史教训 PR #60 → issue #65:只改 src 忘同步 lib,发布包跑旧代码。此脚本是发布前 src/↔lib/ 一致性守门,v0.7.9 引入(f5e6cbe),本 PR 恢复并纳入新 CI 流水线。 Co-Authored-By: Anans-Ivresse <[email protected]> * fix(test): peer-C Windows 清理加 maxRetries —— rmSync 偶发 EPERM Windows 上 8 个 SQLite 子进程退出后 -shm/-wal 句柄延迟释放, finally 里 rmSync 删临时目录偶发 EPERM(Linux 不触发)。测试逻辑本身 全通过(generation==80 断言绿),仅清理环节挂。Node fs.rmSync 的 maxRetries 对 EPERM/EBUSY 自动重试,一行修复,不动并发逻辑。 Co-Authored-By: Anans-Ivresse <[email protected]> --------- Co-authored-by: modusensus <[email protected]> Co-authored-by: Anans-Ivresse <[email protected]>
1 parent 3d48786 commit 91cbb84

6 files changed

Lines changed: 314 additions & 91 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: CI
2+
3+
# 优化版(对比原 test.yml):
4+
# 1. 测试矩阵扩展为 OS(ubuntu/windows)× Node(22/24)——插件用 node:sqlite(≥22),
5+
# 且 npm publish 前要求双平台全量通过;fail-fast: false 保证一个平台的失败不掩盖另一个。
6+
# 2. 新增 src/↔lib/ 一致性守门(scripts/check-sync.js,v0.7.9 引入的发布前校验前置到 CI)。
7+
# 3. Codecov 只在 ubuntu+node24 一个分片跑一次(覆盖率无需每个组合都传)。
8+
# 4. node_modules 缓存(cache-dependency-path 指向子目录的 lockfile)。
9+
# ⚠️ 需要 package.json 配合一处小改(跨平台通配符):
10+
# dsh-mneme/package.json 的 "test": "node --test test/*.test.js" 在 Windows 的 cmd 下
11+
# 不展开 glob。建议改为 "test": "node --test test/"(目录模式,全平台等价),
12+
# "test:coverage" 同理(c8 node --test test/)。改动只影响脚本调用方式,用例不变。
13+
14+
on:
15+
push:
16+
branches: [main, master]
17+
pull_request:
18+
branches: [main, master]
19+
workflow_dispatch:
20+
21+
permissions:
22+
contents: read
23+
24+
jobs:
25+
test:
26+
strategy:
27+
fail-fast: false
28+
matrix:
29+
os: [ubuntu-latest, windows-latest]
30+
node-version: [22, 24]
31+
runs-on: ${{ matrix.os }}
32+
defaults:
33+
run:
34+
working-directory: dsh-mneme
35+
steps:
36+
- uses: actions/checkout@v4
37+
38+
- uses: actions/setup-node@v4
39+
with:
40+
node-version: ${{ matrix.node-version }}
41+
cache: npm
42+
cache-dependency-path: dsh-mneme/package-lock.json
43+
44+
- name: Install dependencies
45+
run: npm ci
46+
47+
# 发布守门前置:src/↔lib/ 漂移直接红(原来只在 prepack 时校验,PR 阶段发现不了)
48+
- name: Sync check (src ↔ lib)
49+
run: node scripts/check-sync.js
50+
51+
- name: Run full tests
52+
run: npm test
53+
54+
# 覆盖率与 Codecov 只跑一个代表分片,避免四份重复上报
55+
- name: Coverage (ubuntu + node 24 shard only)
56+
if: matrix.os == 'ubuntu-latest' && matrix.node-version == 24
57+
run: npm run test:coverage
58+
59+
- name: Upload coverage to Codecov
60+
if: matrix.os == 'ubuntu-latest' && matrix.node-version == 24
61+
uses: codecov/codecov-action@v4
62+
with:
63+
token: ${{ secrets.CODECOV_TOKEN }}
64+
files: dsh-mneme/coverage/lcov.info
65+
fail_ci_if_error: false

‎.github/workflows/publish.yml‎

Lines changed: 0 additions & 58 deletions
This file was deleted.

‎.github/workflows/release.yml‎

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
name: Release
2+
3+
# 优化版(对比原 publish.yml):原流程只做「同步 root 版本 → npm publish」,测试要靠
4+
# test.yml 恰好绿着。本流程把一次 v* tag 推送变成完整发布流水线:
5+
#
6+
# verify(版本号管理)→ test(双平台全量测试,矩阵同 CI)→ publish(npm)→ release(GitHub Release)→ notify(结果摘要)
7+
#
8+
# 沿用 publish.yml 的血泪教训并固化成步骤:
9+
# 1. 发布根是 dsh-mneme/ 子目录(真实版本在 dsh-mneme/package.json,prepack 自动
10+
# npm run sync 同步 src→lib)——npm publish 在 dsh-mneme/ 下跑,包结构与
11+
# v0.7.12/0.7.13 本机发布一致;root package.json 是编排壳(版本停在 0.7.2,不参与发布)。
12+
# 2. 「skip if exists」幂等守卫:同一版本重复推 tag 不会重复发布。
13+
#
14+
# 新增的版本号管理规则:
15+
# - tag 必须与 dsh-mneme/package.json version 完全一致(vX.Y.Z ↔ X.Y.Z),否则直接失败;
16+
# - tag 对应版本必须在 dsh-mneme/CHANGELOG.md 里有小节(文档先行,发布时自动抽取作 Release 说明)。
17+
#
18+
# 手动触发(workflow_dispatch)支持 dry_run:只跑 verify + test,不发布不建 Release。
19+
20+
on:
21+
push:
22+
tags:
23+
- 'v*'
24+
workflow_dispatch:
25+
inputs:
26+
dry_run:
27+
description: '只验证 + 测试,不发布(dry run)'
28+
type: boolean
29+
default: false
30+
31+
permissions:
32+
contents: write
33+
34+
jobs:
35+
# ── 1. 版本号管理:tag ↔ package.json ↔ CHANGELOG 三方一致 ──────────────
36+
verify:
37+
runs-on: ubuntu-latest
38+
outputs:
39+
version: ${{ steps.ver.outputs.version }}
40+
steps:
41+
- uses: actions/checkout@v4
42+
43+
- uses: actions/setup-node@v4
44+
with:
45+
node-version: 24
46+
47+
- name: Resolve version (tag push or package.json)
48+
id: ver
49+
run: |
50+
PKG_V="$(node -p "require('./dsh-mneme/package.json').version")"
51+
if [ "$GITHUB_REF_TYPE" = "tag" ]; then
52+
TAG_V="${GITHUB_REF_NAME#v}"
53+
echo "tag=v$TAG_V, package.json=$PKG_V"
54+
if [ "$TAG_V" != "$PKG_V" ]; then
55+
echo "::error::tag v$TAG_V 与 dsh-mneme/package.json 版本 $PKG_V 不一致"
56+
exit 1
57+
fi
58+
echo "version=$PKG_V" >> "$GITHUB_OUTPUT"
59+
else
60+
echo "version=$PKG_V" >> "$GITHUB_OUTPUT"
61+
fi
62+
63+
# 文档更新守门:CHANGELOG 缺该版本小节 → 说明发布说明没写,阻断并提示
64+
- name: CHANGELOG has a section for this version
65+
run: |
66+
V="${{ steps.ver.outputs.version }}"
67+
if ! grep -qE "^## \[${V}\]" dsh-mneme/CHANGELOG.md; then
68+
echo "::error::dsh-mneme/CHANGELOG.md 缺少 ## [${V}] 小节——请先补发布说明"
69+
exit 1
70+
fi
71+
echo "CHANGELOG section found for ${V}"
72+
73+
# ── 2. 双平台全量测试(Windows + Linux × Node 22/24,与 CI 同矩阵)────────
74+
test:
75+
needs: verify
76+
strategy:
77+
fail-fast: false
78+
matrix:
79+
os: [ubuntu-latest, windows-latest]
80+
node-version: [22, 24]
81+
runs-on: ${{ matrix.os }}
82+
defaults:
83+
run:
84+
working-directory: dsh-mneme
85+
steps:
86+
- uses: actions/checkout@v4
87+
88+
- uses: actions/setup-node@v4
89+
with:
90+
node-version: ${{ matrix.node-version }}
91+
cache: npm
92+
cache-dependency-path: dsh-mneme/package-lock.json
93+
94+
- name: Install dependencies
95+
run: npm ci
96+
97+
- name: Sync check (src ↔ lib)
98+
run: node scripts/check-sync.js
99+
100+
- name: Full test suite
101+
run: npm test
102+
103+
# ── 3. 发布到 npm(沿用原 publish.yml 的同步与幂等守卫)──────────────────
104+
publish:
105+
needs: [verify, test]
106+
if: github.event_name == 'push' || inputs.dry_run != true
107+
runs-on: ubuntu-latest
108+
steps:
109+
- uses: actions/checkout@v4
110+
111+
- uses: actions/setup-node@v4
112+
with:
113+
node-version: 24
114+
registry-url: https://registry.npmjs.org/
115+
116+
- name: Registry current state (diagnostic)
117+
run: |
118+
npm view @modusensus/dsh-mneme versions --json || true
119+
npm view @modusensus/dsh-mneme time --json || true
120+
121+
# 发布根 = dsh-mneme/(dsh-mneme/package.json 是真实版本 + prepack `npm run sync` 自动同步
122+
# src→lib),与 v0.7.12/0.7.13 本机发布包结构一致;root 壳不参与发布,无需 root 版本同步
123+
- name: Publish @modusensus/dsh-mneme (skip if exists)
124+
working-directory: dsh-mneme
125+
run: |
126+
V="${{ needs.verify.outputs.version }}"
127+
if npm view "@modusensus/dsh-mneme@${V}" version >/dev/null 2>&1; then
128+
echo "v${V} already published on registry — skipping"
129+
else
130+
npm publish --access public
131+
fi
132+
env:
133+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
134+
135+
- name: Verify published version
136+
run: |
137+
V="${{ needs.verify.outputs.version }}"
138+
echo "Published: $(npm view "@modusensus/dsh-mneme@${V}" version)"
139+
140+
# ── 4. GitHub Release(按 v0.7.9 / v0.7.10 的既定格式,说明自动取自 CHANGELOG)──
141+
release:
142+
needs: [verify, test]
143+
if: github.event_name == 'push' || inputs.dry_run != true
144+
runs-on: ubuntu-latest
145+
steps:
146+
- uses: actions/checkout@v4
147+
148+
# 从 dsh-mneme/CHANGELOG.md 抽取本版本小节作为 Release 说明(verify 已保证存在)
149+
- name: Extract release notes from CHANGELOG
150+
run: |
151+
V="${{ needs.verify.outputs.version }}"
152+
node -e '
153+
const fs = require("fs");
154+
const v = process.argv[1];
155+
const md = fs.readFileSync("dsh-mneme/CHANGELOG.md", "utf8");
156+
const re = new RegExp("^## \\[" + v.replace(/\./g, "\\.") + "\\][^\\n]*\\n", "m");
157+
const start = md.search(re);
158+
if (start === -1) { console.error("changelog section not found: " + v); process.exit(1); }
159+
const rest = md.slice(start + md.slice(start).indexOf("\n") + 1);
160+
const next = rest.search(/^## \[/m);
161+
const body = (next === -1 ? rest : rest.slice(0, next)).trim();
162+
fs.mkdirSync("notes", { recursive: true });
163+
fs.writeFileSync("notes/body.md", body + "\n");
164+
console.log("--- extracted notes ---\n" + body.slice(0, 400));
165+
' "$V"
166+
167+
- name: Create / update GitHub Release
168+
env:
169+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
170+
VERSION: ${{ needs.verify.outputs.version }}
171+
run: |
172+
TITLE="$(head -1 notes/body.md | sed -E 's/^#+ *//; s/^\*\*//; s/\*\*$//')"
173+
if [ -z "$TITLE" ]; then TITLE="v${VERSION}"; fi
174+
if gh release view "v${VERSION}" >/dev/null 2>&1; then
175+
gh release edit "v${VERSION}" --title "v${VERSION} · ${TITLE}" --notes-file notes/body.md
176+
else
177+
gh release create "v${VERSION}" --title "v${VERSION} · ${TITLE}" --notes-file notes/body.md
178+
fi
179+
180+
# ── 5. 通知与运行摘要(接入外部通知时往这里加一步 webhook 即可)────────────
181+
notify:
182+
needs: [verify, test, publish, release]
183+
if: always()
184+
runs-on: ubuntu-latest
185+
steps:
186+
- name: Job summary
187+
run: |
188+
{
189+
echo "## Release pipeline — ${{ needs.verify.outputs.version }}"
190+
echo ""
191+
echo "| job | result |"
192+
echo "|-----|--------|"
193+
echo "| verify | ${{ needs.verify.result }} |"
194+
echo "| test (win/linux × node 22/24) | ${{ needs.test.result }} |"
195+
echo "| publish (npm) | ${{ needs.publish.result }} |"
196+
echo "| release (GitHub) | ${{ needs.release.result }} |"
197+
} >> "$GITHUB_STEP_SUMMARY"
198+
# 可选:企业微信/Telegram/邮件 webhook。配置 secret(如 NOTIFY_WEBHOOK)后取消注释:
199+
# - name: Notify webhook
200+
# if: needs.publish.result == 'success'
201+
# run: |
202+
# curl -sf -X POST "${{ secrets.NOTIFY_WEBHOOK }}" \
203+
# -H 'Content-Type: application/json' \
204+
# -d '{"msgtype":"text","text":{"content":"dsh-mneme ${{ needs.verify.outputs.version }} 已发布"}}'

‎.github/workflows/test.yml‎

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)