mirror of
https://github.com/sinanyuntu/trade-message-center.git
synced 2026-09-17 13:22:11 +08:00
fix(release): allow preparation on main
This commit is contained in:
+2
-5
@@ -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);
|
||||
|
||||
|
||||
@@ -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", () => {
|
||||
|
||||
Reference in New Issue
Block a user