fix(release): allow preparation on main

This commit is contained in:
YBF
2026-09-07 19:38:08 +08:00
parent 05d9bb161c
commit 750851a541
2 changed files with 21 additions and 9 deletions
+2 -5
View File
@@ -47,12 +47,9 @@ const assertCleanWorkingTree = (git) => {
if (changes) throw new Error("Release requires a clean working tree");
};
const assertReleaseBranch = (git) => {
const assertNamedBranch = (git) => {
const branch = getCurrentBranch(git);
if (!branch) throw new Error("Release preparation requires a named branch");
if (branch === mainBranch) {
throw new Error("Release preparation must run on a release branch, not main");
}
return branch;
};
@@ -133,7 +130,7 @@ const runQualityGates = (pnpm) => {
export const prepareRelease = ({ rootDir = workspaceDir, releaseType = "patch", execute } = {}) => {
const { git, pnpm } = createCommandRunner(rootDir, execute);
assertCleanWorkingTree(git);
const branch = assertReleaseBranch(git);
const branch = assertNamedBranch(git);
fetchMain(git);
assertBranchIncludesMain(git);
+19 -4
View File
@@ -102,17 +102,32 @@ test("prepares a patch release using only root-derived version mirrors", () => {
);
});
test("refuses to alter main during release preparation", () => {
test("prepares a release directly on main", () => {
const rootDir = createWorkspace();
const { execute } = createRunner(
const { calls, execute } = createRunner(
new Map([
[commandKey("git", ["status", "--porcelain"]), ""],
[commandKey("git", ["branch", "--show-current"]), "main\n"],
[commandKey("git", ["rev-parse", "origin/main"]), "main-sha\n"],
[commandKey("git", ["merge-base", "origin/main", "HEAD"]), "main-sha\n"],
[commandKey("git", ["diff", "--name-only"]), `${expectedFiles.join("\n")}\n`],
[commandKey("git", ["ls-files", "--others", "--exclude-standard"]), ""],
[commandKey("git", ["--no-pager", "diff", "--check"]), ""],
[
commandKey("git", ["diff", "--cached", "--name-only"]),
`${expectedFiles.join("\n")}\n`,
],
]),
);
assert.throws(() => prepareRelease({ rootDir, execute }), /not main/u);
assert.equal(JSON.parse(readFileSync(join(rootDir, "package.json"), "utf8")).version, "0.8.16");
assert.equal(prepareRelease({ rootDir, execute }), "0.8.17");
assert.ok(
calls.some(
({ command, arguments_ }) =>
commandKey(command, arguments_) ===
commandKey("git", ["push", "--set-upstream", "origin", "main"]),
),
);
});
test("restores all version files when staging fails before the release commit", () => {