fix(release): 版本号已钉在树中时不再卡在「nothing to commit」
发版脚本无条件执行 `git commit`。v2.1.0 的流程是先把版本号作为 `chore(release)` 提交进树、之后才发版 —— 此时 `git add -A` 后暂存区为空, `git commit` 以 "nothing to commit" 非零退出,发版停在最后一步,且报错来自 git 而非发布逻辑,容易误判为工作区问题。 改为:暂存区为空则跳过 commit,标签与 Release 照常创建。 向后兼容 —— 版本号需要变更时行为完全不变。
This commit is contained in:
1 parent
2d5be044ee
commit
451d44af72
1 file changed
+15
-1
+15
-1
@@ -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}`]));
|
||||
|
||||
Reference in new issue
Block a user