Skip to content

Commit 95a2fee

Browse files
committed
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,跨平台矩阵需要目录模式
1 parent cb5ec63 commit 95a2fee

5 files changed

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

‎dsh-mneme/package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@
6363
"scripts": {
6464
"sync": "node scripts/sync-lib.js",
6565
"prepack": "npm run sync",
66-
"test": "node --test test/*.test.js",
67-
"test:coverage": "c8 node --test test/*.test.js",
66+
"test": "node --test test/",
67+
"test:coverage": "c8 node --test test/",
6868
"e2e": "node scripts/e2e-dsh.js",
6969
"stress": "node scripts/stress-dsh.js"
7070
},

0 commit comments

Comments
 (0)