fix(release): publish reviewed release PR merges

This commit is contained in:
morluto
2026-10-09 08:47:00 +08:00
parent 283c82f68c
commit cdddfddf49
6 changed files with 352 additions and 57 deletions
@@ -177,7 +177,7 @@ function verify(
"--stage",
stage,
"--release-branch",
`release/${version}`,
version === "main" ? "main" : `release/${version}`,
"--source-sha",
f.sourceSha,
],
@@ -295,6 +295,90 @@ it("still requires migration notes for breaking minor releases", async () => {
});
});
it.each([
{
notes:
"### ⚠ BREAKING CHANGES\n\n* **contracts:** Use absolute MCP paths. Relative paths are rejected.",
accepted: true,
},
{
notes:
"### ⚠ BREAKING CHANGES\n\n* **contracts:** Use absolute MCP paths.\n Relative paths are rejected.",
accepted: true,
},
{
notes: "### ⚠ BREAKING CHANGES\n\n* Use absolute MCP paths.",
accepted: false,
},
{
notes:
"### Bug Fixes\n\n* Use absolute MCP paths. Relative paths are rejected.",
accepted: false,
},
{
notes:
"### ⚠ BREAKING CHANGES\n\n* Use absolute MCP paths. Relative paths are rejected.",
footer:
"BREAKING CHANGE: Use absolute MCP paths. Relative paths are rejected.\n\nBREAKING CHANGE: Rename the old CLI option.",
accepted: false,
},
{
notes:
"### ⚠ BREAKING CHANGES\n\n* Use absolute MCP paths. Relative paths are rejected.\n* Rename the old CLI option.",
footer:
"BREAKING CHANGE: Use absolute MCP paths.\r\nRelative paths are rejected.\r\n\r\nBREAKING CHANGE: Rename the old CLI option.",
accepted: true,
},
])(
"validates generated migration text on a main release merge ($accepted): $notes",
async ({ notes, accepted, footer }) => {
const f = await fixture(
"fix(contracts)!: change path inputs",
footer ??
"BREAKING CHANGE: Use absolute MCP paths.\nRelative paths are rejected.",
{ versioning: "always-bump-minor" },
);
const sourceSha = await candidate(f, "5.1.0", notes);
const result = verify({ ...f, sourceSha }, "main", "publish", "source");
if (!accepted) {
await expect(result).rejects.toMatchObject({
code: 1,
stderr: expect.stringContaining(
"migration notes omit unreleased breaking changes",
),
});
return;
}
const original = JSON.parse((await result).stdout);
const report = reportSchema.parse(original);
expect(report).toMatchObject({
expectedVersion: "5.1.0",
baselineVersion: "5.0.0",
applicationSha: f.sourceSha,
});
await writeFile(join(f.directory, "later-work.txt"), "Later main change\n");
await git(f.directory, ["add", "."]);
await git(f.directory, ["commit", "-m", "fix: unrelated later work"]);
// A moved checkout does not change the selected reviewed merge.
expect(
JSON.parse(
(await verify({ ...f, sourceSha }, "main", "publish", "source")).stdout,
),
).toEqual(original);
await expect(
verify(
{ ...f, sourceSha: await git(f.directory, ["rev-parse", "HEAD"]) },
"main",
"publish",
"source",
),
).rejects.toMatchObject({
code: 1,
stderr: expect.stringContaining("must advance published baseline"),
});
},
);
it("rejects a minor when a GitHub merge commit carries its bang marker in the PR title", async () => {
const f = await fixture("fix(contracts)!: require absolute paths", "", {
mergePullRequest: true,
@@ -528,15 +612,21 @@ it("rejects a candidate from a different source even when versions and notes mat
});
});
it.skipIf(process.platform === "win32").each([true, false])(
"the actual publish preflight admits the next action only for valid metadata (%s)",
async (valid) => {
it.skipIf(process.platform === "win32").each([
{ job: "release-please", valid: true },
{ job: "release-please", valid: false },
{ job: "merged-release", valid: true },
{ job: "merged-release", valid: false },
])(
"the actual $job preflight admits the next action only for valid metadata ($valid)",
async ({ job, valid }) => {
const f = await fixture();
const sourceSha = await candidate(f, valid ? "6.0.0" : "5.1.0");
const workflow = z
.object({
jobs: z.object({
"release-please": z.object({
jobs: z.record(
z.string(),
z.object({
steps: z.array(
z.object({
name: z.string().optional(),
@@ -544,7 +634,7 @@ it.skipIf(process.platform === "win32").each([true, false])(
}),
),
}),
}),
),
})
.parse(
parse(
@@ -557,10 +647,12 @@ it.skipIf(process.platform === "win32").each([true, false])(
const command = z
.string()
.parse(
workflow.jobs["release-please"].steps.find(
workflow.jobs[job]?.steps.find(
(step) =>
step.name ===
"Validate checkpoint version and ancestry before release creation",
(job === "merged-release"
? "Validate reviewed merge before release creation"
: "Validate checkpoint version and ancestry before release creation"),
)?.run,
);
const marker = join(f.directory, "next-release-action");
@@ -582,6 +674,7 @@ it.skipIf(process.platform === "win32").each([true, false])(
RELEASE_PHASE: "publish",
RELEASE_BRANCH: "release/6.0.0",
SOURCE_SHA: sourceSha,
GITHUB_SHA: sourceSha,
NEXT_RELEASE_ACTION_MARKER: marker,
},
},
@@ -592,7 +685,11 @@ it.skipIf(process.platform === "win32").each([true, false])(
} else {
await expect(execution).rejects.toMatchObject({
code: 1,
stderr: expect.stringContaining("release branch requires 6.0.0"),
stderr: expect.stringContaining(
job === "merged-release"
? "contains unreleased breaking markers"
: "release branch requires 6.0.0",
),
});
await expect(readFile(marker)).rejects.toMatchObject({ code: "ENOENT" });
}