fix(release): publish reviewed release PR merges
This commit is contained in:
@@ -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