From 451d44af7221420ceaf995e93081d4213ec2e1dc Mon Sep 17 00:00:00 2001 From: jkooe <62494645+jkooe@users.noreply.github.com> Date: Tue, 27 Oct 2026 00:00:26 +0800 Subject: [PATCH] =?UTF-8?q?fix(release):=20=E7=89=88=E6=9C=AC=E5=8F=B7?= =?UTF-8?q?=E5=B7=B2=E9=92=89=E5=9C=A8=E6=A0=91=E4=B8=AD=E6=97=B6=E4=B8=8D?= =?UTF-8?q?=E5=86=8D=E5=8D=A1=E5=9C=A8=E3=80=8Cnothing=20to=20commit?= =?UTF-8?q?=E3=80=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 发版脚本无条件执行 `git commit`。v2.1.0 的流程是先把版本号作为 `chore(release)` 提交进树、之后才发版 —— 此时 `git add -A` 后暂存区为空, `git commit` 以 "nothing to commit" 非零退出,发版停在最后一步,且报错来自 git 而非发布逻辑,容易误判为工作区问题。 改为:暂存区为空则跳过 commit,标签与 Release 照常创建。 向后兼容 —— 版本号需要变更时行为完全不变。 --- scripts/release.mjs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/scripts/release.mjs b/scripts/release.mjs index ff1a864..f8dde94 100644 --- a/scripts/release.mjs +++ b/scripts/release.mjs @@ -267,7 +267,21 @@ if (unexpectedDirty.length > 0) { } sh('git', ['add', '-A', '--', '.', ':(exclude).github']); -sh('git', ['commit', '-m', `chore(release): v${version}`]); +// 版本号可能**早已在树中钉好**(v2.1.0 的流程:先 chore(release) 提交版本号, +// 之后再发版)。此时 add 之后暂存区为空,`git commit` 会以 "nothing to commit" +// 非零退出,把整个发版卡在最后一步 —— 且报错指向 git 而非发布逻辑,极易误判。 +// 故:暂存区为空则跳过 commit(标签与 Release 照常创建)。 +let hasStaged = false; +try { + sh('git', ['diff', '--cached', '--quiet']); +} catch { + hasStaged = true; // diff --quiet 有差异时退出码 1 → execFileSync 抛错 +} +if (hasStaged) { + sh('git', ['commit', '-m', `chore(release): v${version}`]); +} else { + console.log('(版本号已是最新,无需额外提交;直接打标签)'); +} sh('git', ['tag', '-a', `v${version}`, '-m', `nodeagent v${version}`]); netRetry('push main', () => sh('git', ['push', 'origin', 'main'])); netRetry('push tag', () => sh('git', ['push', 'origin', `v${version}`]));