fix(release): publish reviewed release PR merges
This commit is contained in:
@@ -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" });
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
const execFileAsync = promisify(execFile);
|
||||
const stepSchema = z.object({
|
||||
id: z.string().optional(),
|
||||
name: z.string().optional(),
|
||||
uses: z.string().optional(),
|
||||
run: z.string().optional(),
|
||||
@@ -19,6 +20,7 @@ const stepSchema = z.object({
|
||||
});
|
||||
const jobSchema = z.object({
|
||||
if: z.string().optional(),
|
||||
needs: z.union([z.string(), z.array(z.string())]).optional(),
|
||||
outputs: z.record(z.string(), z.string()).optional(),
|
||||
steps: z.array(stepSchema),
|
||||
});
|
||||
@@ -31,6 +33,7 @@ async function readReleaseWorkflow() {
|
||||
jobs: z.object({
|
||||
"release-proposal": jobSchema,
|
||||
"release-please": jobSchema,
|
||||
"merged-release": jobSchema,
|
||||
publish: jobSchema,
|
||||
"publish-mcp": jobSchema,
|
||||
}),
|
||||
@@ -82,9 +85,13 @@ it("validates the source before release creation and the prepared candidate befo
|
||||
}
|
||||
});
|
||||
|
||||
it("refreshes a release proposal on main pushes without creating or publishing a release", async () => {
|
||||
it("keeps main pushes proposal-only and gates merged-release automation", async () => {
|
||||
const workflow = await readReleaseWorkflow();
|
||||
expect(workflow.on.push).toEqual({ branches: ["main"] });
|
||||
expect(workflow.on.pull_request).toMatchObject({
|
||||
types: ["closed"],
|
||||
branches: ["main"],
|
||||
});
|
||||
const proposal = workflow.jobs["release-proposal"];
|
||||
expect(proposal.if).toBe("github.event_name == 'push'");
|
||||
const action = proposal.steps.find((step) =>
|
||||
@@ -96,17 +103,52 @@ it("refreshes a release proposal on main pushes without creating or publishing a
|
||||
"skip-github-release": true,
|
||||
});
|
||||
expect(action?.with?.["skip-github-pull-request"]).not.toBe(true);
|
||||
const merged = workflow.jobs["merged-release"];
|
||||
expect(merged.if).toContain("github.event.pull_request.merged == true");
|
||||
expect(merged.if).toContain("github.repository");
|
||||
expect(merged.if).toContain("release-please--branches--main--");
|
||||
expect(merged.outputs).toEqual({
|
||||
release_created: "${{ steps.release.outputs.release_created }}",
|
||||
sha: "${{ steps.release.outputs.sha }}",
|
||||
});
|
||||
expect(workflow.jobs["release-please"].if).toBe(
|
||||
"github.event_name == 'workflow_dispatch'",
|
||||
);
|
||||
for (const job of [workflow.jobs.publish, workflow.jobs["publish-mcp"]]) {
|
||||
expect(job.if).toContain("inputs.phase == 'publish'");
|
||||
}
|
||||
expect(workflow.concurrency.group).toBe(
|
||||
"release-${{ inputs.release_branch || github.ref_name }}",
|
||||
"release-${{ inputs.release_branch || github.event.pull_request.merge_commit_sha || github.ref_name }}",
|
||||
);
|
||||
});
|
||||
|
||||
it("validates the reviewed merge before creating its release", async () => {
|
||||
const workflow = await readReleaseWorkflow();
|
||||
const steps = workflow.jobs["merged-release"].steps;
|
||||
const checkout = steps.find((step) =>
|
||||
step.uses?.startsWith("actions/checkout@"),
|
||||
);
|
||||
expect(checkout?.with).toMatchObject({
|
||||
ref: "${{ github.event.pull_request.merge_commit_sha }}",
|
||||
"fetch-depth": 0,
|
||||
});
|
||||
const checkpoint = steps.find((step) =>
|
||||
step.run?.includes("verify-release-checkpoint.mjs"),
|
||||
);
|
||||
expect(checkpoint?.run).toContain("--phase publish --release-branch main");
|
||||
expect(checkpoint?.run).toContain('--source-sha "$SOURCE_SHA"');
|
||||
const release = steps.find((step) => step.id === "release");
|
||||
expect(release?.with).toMatchObject({
|
||||
"target-branch": "main",
|
||||
"skip-github-release": false,
|
||||
"skip-github-pull-request": true,
|
||||
});
|
||||
const bind = steps.find(
|
||||
(step) => step.name === "Bind publication to the reviewed merge",
|
||||
);
|
||||
expect(bind?.env).toMatchObject({
|
||||
SOURCE_SHA: "${{ github.event.pull_request.merge_commit_sha }}",
|
||||
RELEASE_SHA: "${{ steps.release.outputs.sha }}",
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps frozen candidate preparation and publication explicit", async () => {
|
||||
const workflow = await readReleaseWorkflow();
|
||||
expect(workflow.on.workflow_dispatch).toMatchObject({
|
||||
@@ -209,18 +251,21 @@ it("binds npm and MCP publication to the same immutable release SHA", async () =
|
||||
release_created: "${{ steps.release.outputs.release_created }}",
|
||||
sha: "${{ steps.release.outputs.sha }}",
|
||||
});
|
||||
expect(workflow.jobs.publish.if).toBe(
|
||||
"inputs.phase == 'publish' && needs.release-please.outputs.release_created == 'true'",
|
||||
expect(workflow.jobs.publish.if).toContain("inputs.phase == 'publish'");
|
||||
expect(workflow.jobs.publish.if).toContain(
|
||||
"needs.release-please.outputs.release_created",
|
||||
);
|
||||
expect(workflow.jobs["publish-mcp"].if).toBe(
|
||||
"inputs.phase == 'publish' && needs.release-please.outputs.release_created == 'true' && needs.publish.result == 'success'",
|
||||
expect(workflow.jobs["publish-mcp"].if).toContain(
|
||||
"needs.publish.result == 'success'",
|
||||
);
|
||||
expect(workflow.jobs.publish.needs).toContain("merged-release");
|
||||
expect(workflow.jobs["publish-mcp"].needs).toContain("merged-release");
|
||||
for (const job of [workflow.jobs.publish, workflow.jobs["publish-mcp"]]) {
|
||||
const checkout = job.steps.find((step) =>
|
||||
step.uses?.startsWith("actions/checkout@"),
|
||||
);
|
||||
expect(checkout?.with).toMatchObject({
|
||||
ref: "${{ needs.release-please.outputs.sha }}",
|
||||
ref: "${{ needs.merged-release.outputs.sha || needs.release-please.outputs.sha }}",
|
||||
"persist-credentials": false,
|
||||
});
|
||||
}
|
||||
@@ -262,6 +307,58 @@ it("binds npm and MCP publication to the same immutable release SHA", async () =
|
||||
}
|
||||
});
|
||||
|
||||
it.skipIf(process.platform === "win32").each([
|
||||
{
|
||||
created: "false",
|
||||
releaseSha: "1111111111111111111111111111111111111111",
|
||||
succeeds: false,
|
||||
reason: "did not create a release",
|
||||
},
|
||||
{
|
||||
created: "true",
|
||||
releaseSha: "1111111111111111111111111111111111111111",
|
||||
succeeds: true,
|
||||
},
|
||||
{
|
||||
created: "true",
|
||||
releaseSha: "2222222222222222222222222222222222222222",
|
||||
succeeds: false,
|
||||
reason: "refusing mismatched publication provenance",
|
||||
},
|
||||
])(
|
||||
"publishes a merged release only when Release Please creates it at the reviewed SHA: $created/$releaseSha",
|
||||
async ({ created, releaseSha, succeeds, reason }) => {
|
||||
const workflow = await readReleaseWorkflow();
|
||||
const command = z
|
||||
.string()
|
||||
.parse(
|
||||
workflow.jobs["merged-release"].steps.find(
|
||||
(step) => step.name === "Bind publication to the reviewed merge",
|
||||
)?.run,
|
||||
);
|
||||
const result = execFileAsync(
|
||||
"bash",
|
||||
["-e", "-o", "pipefail", "-c", command],
|
||||
{
|
||||
env: {
|
||||
...process.env,
|
||||
SOURCE_SHA: "1111111111111111111111111111111111111111",
|
||||
RELEASE_CREATED: created,
|
||||
RELEASE_SHA: releaseSha,
|
||||
},
|
||||
},
|
||||
);
|
||||
if (succeeds) {
|
||||
await expect(result).resolves.toMatchObject({ stderr: "" });
|
||||
} else {
|
||||
await expect(result).rejects.toMatchObject({
|
||||
code: 1,
|
||||
stderr: expect.stringContaining(z.string().parse(reason)),
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
it
|
||||
.skipIf(process.platform === "win32")
|
||||
.each(["main", "feature/new-work", "release/", "release/../main"])(
|
||||
|
||||
Reference in New Issue
Block a user