ci: publish a stable release from the push that merges its release PR (#8020)

* ci: publish a stable release from the push that merges its release PR

* test(ci): read the publish job's own concurrency, where a publish in flight now waits

* ci: a stable release needs another person's approval of its final commit

* ci: only a person's approval counts for a stable release
This commit is contained in:
Miguel Ángel
2026-11-17 05:20:53 +00:00
committed by GitHub
parent f5bb3e5519
commit 5f6007ffc4
6 changed files with 321 additions and 139 deletions
+182 -28
View File
@@ -47,19 +47,168 @@ function runCreateReleaseTag(cwd, version) {
}
test("stable publishing has one reviewed immutable event path", () => {
assert.deepEqual(config.on.push.tags, ["v*-*"]);
assert.equal(config.on.workflow_dispatch, undefined);
assert.equal(
normalizeExpression(publish.if),
"github.event_name == 'push' || (github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'release/v'))",
);
assert.equal(
normalizeExpression(publish.env.EXPECTED_RELEASE_SHA),
"${{ github.event_name == 'pull_request' && github.event.pull_request.merge_commit_sha || github.sha }}",
);
// fails without the fix: a merged release PR's event ran as refs/pull/N/merge, a ref the publish environment refuses.
assert.deepEqual(config.on, { push: { branches: ["main"], tags: ["v*-*"] } });
for (const name of ["lambda-arm64-ffmpeg", "lambda-handler-zip", "pack", "publish"]) {
const job = config.jobs[name];
assert.ok(job.needs.includes("release-source"), `${name} needs release-source`);
assert.equal(normalizeExpression(job.if), "needs.release-source.outputs.sha != ''", name);
assert.equal(job.env.EXPECTED_RELEASE_SHA, "${{ needs.release-source.outputs.sha }}", name);
}
assert.equal(checkout.with.ref, "${{ env.EXPECTED_RELEASE_SHA }}");
});
test("a release run waits behind another run of the same release, never behind main", () => {
// A ref-wide group on main lets any later push cancel a release run that is still pending.
assert.equal(config.concurrency, undefined);
assert.deepEqual(publish.concurrency, {
group: "publish-${{ needs.release-source.outputs.version }}",
"cancel-in-progress": false,
});
});
test("a push to main publishes only the merge of exactly one approved release PR from this repo", () => {
const step = stepOf(config.jobs["release-source"], "Find the release this push publishes");
const bin = mkdtempSync(join(tmpdir(), "hyperframes-fake-gh-"));
const sha = "a".repeat(40);
const head = "c".repeat(40);
const pull = (overrides = {}) => ({
number: 8000,
user: { login: "releaser" },
merged_at: "2026-11-17T02:24:00Z",
merge_commit_sha: sha,
base: { ref: "main" },
head: { ref: "release/v0.9.61", sha: head, repo: { full_name: "heygen-com/hyperframes" } },
...overrides,
});
const review = (login, state, hour, commit = head, type = "User") => ({
user: { login, type },
state,
commit_id: commit,
submitted_at: `2026-11-17T0${hour}:00:00Z`,
});
const approved = [review("reviewer", "APPROVED", 1)];
// The fake answers PR 8000's reviews from FAKE_REVIEWS and the commit's PR lookup from FAKE_PULLS.
writeFileSync(
join(bin, "gh"),
'#!/bin/sh\ncase "$*" in *pulls/8000/reviews*) printf \'%s\' "$FAKE_REVIEWS" ;; *) printf \'%s\' "$FAKE_PULLS" ;; esac\n',
);
chmodSync(join(bin, "gh"), 0o755);
const main = { REF_TYPE: "branch", REF_NAME: "main" };
const run = (pulls, ref = main, reviews = approved) => {
const out = join(bin, "out");
writeFileSync(out, "");
const result = runStep(step, {
cwd: bin,
env: {
REPO: "heygen-com/hyperframes",
SHA: sha,
RUNNER_TEMP: bin,
GITHUB_OUTPUT: out,
FAKE_PULLS: JSON.stringify(pulls),
FAKE_REVIEWS: JSON.stringify(reviews),
...ref,
},
path: `${bin}:${process.env.PATH}`,
});
const outputs = Object.fromEntries(
readFileSync(out, "utf8")
.split("\n")
.filter(Boolean)
.map((line) => line.split(/=(.*)/s).slice(0, 2)),
);
return { status: result.status, outputs };
};
try {
assert.deepEqual(run([pull()]), {
status: 0,
outputs: { sha, version: "0.9.61", source: "release-pr", ref: "release/v0.9.61" },
});
for (const [why, pulls] of [
["no PR", []],
["not merged", [pull({ merged_at: null })]],
["another commit of the PR", [pull({ merge_commit_sha: "b".repeat(40) })]],
["not into main", [pull({ base: { ref: "next" } })]],
[
"from a fork",
[pull({ head: { ref: "release/v0.9.61", repo: { full_name: "x/hyperframes" } } })],
],
["a deleted fork", [pull({ head: { ref: "release/v0.9.61", repo: null } })]],
[
"not a release branch",
[pull({ head: { ref: "fix/x", repo: { full_name: "heygen-com/hyperframes" } } })],
],
[
"a prerelease branch",
[
pull({
head: { ref: "release/v0.9.61-alpha.1", repo: { full_name: "heygen-com/hyperframes" } },
}),
],
],
]) {
assert.deepEqual(run(pulls), { status: 0, outputs: {} }, why);
}
const releaseSubject = {
REF_TYPE: "branch",
REF_NAME: "main",
HEAD_MESSAGE: "chore: release v0.9.61 (#8000)\n\nnotes",
};
assert.equal(
run([], releaseSubject).status,
1,
"a release commit whose PR is not listed yet fails, never skips",
);
assert.equal(
run([], { ...releaseSubject, HEAD_MESSAGE: "fix: name chore: release v1 in the docs" })
.status,
0,
"only the subject's start counts",
);
for (const [why, reviews] of [
["no review", []],
["only the author approved", [review("releaser", "APPROVED", 1)]],
["an earlier commit was approved", [review("reviewer", "APPROVED", 1, "d".repeat(40))]],
["a comment is not an approval", [review("reviewer", "COMMENTED", 1)]],
["a dismissed approval", [review("reviewer", "DISMISSED", 1)]],
["an app's approval", [review("review-app[bot]", "APPROVED", 1, head, "Bot")]],
[
"an app's change request stands",
[...approved, review("review-app[bot]", "CHANGES_REQUESTED", 2, head, "Bot")],
],
[
"another reviewer's change request stands",
[...approved, review("other", "CHANGES_REQUESTED", 2)],
],
[
"the approver later asked for changes",
[...approved, review("reviewer", "CHANGES_REQUESTED", 2)],
],
]) {
assert.equal(run([pull()], main, reviews).status, 1, why);
}
const reapproved = [
review("reviewer", "CHANGES_REQUESTED", 1),
review("reviewer", "APPROVED", 2),
];
assert.equal(
run([pull()], main, reapproved).status,
0,
"a later approval answers its own change request",
);
const second = pull({
head: { ref: "release/v0.9.62", repo: { full_name: "heygen-com/hyperframes" } },
});
assert.equal(run([pull(), second]).status, 1, "two release PRs for one commit");
assert.deepEqual(run([], { REF_TYPE: "tag", REF_NAME: "v0.9.61-alpha.1" }), {
status: 0,
outputs: { sha, version: "0.9.61-alpha.1", source: "tag", ref: "v0.9.61-alpha.1" },
});
} finally {
rmSync(bin, { recursive: true, force: true });
}
});
test("the executable checkout guard cannot be conditionally disabled", () => {
assert.ok(checkoutGuard);
assert.equal(checkoutGuard.if, undefined);
@@ -79,7 +228,7 @@ test("the executable checkout guard cannot be conditionally disabled", () => {
test("stable release tag recovery is idempotent and immutable", () => {
assert.ok(createReleaseTag);
assert.equal(createReleaseTag.if, "github.event_name == 'pull_request'");
assert.equal(createReleaseTag.if, "needs.release-source.outputs.source == 'release-pr'");
assert.equal(
createReleaseTag.run.trim(),
[
@@ -264,7 +413,7 @@ test("release-commit code runs only in a job without secrets", () => {
assert.equal(name, "GH_TOKEN");
}
}
assert.deepEqual(publish.needs, ["pack"]);
assert.deepEqual(publish.needs, ["release-source", "pack"]);
});
test("the publish job runs no code from the release commit", () => {
@@ -287,20 +436,21 @@ test("the publish job runs no code from the release commit", () => {
test("the publish job checks the release channel without repo scripts", () => {
const step = stepOf(publish, "Check release channel");
const check = (EVENT_NAME, VERSION, PRERELEASE, DIST_TAG = "alpha") =>
runStep(step, { cwd: tmpdir(), env: { EVENT_NAME, VERSION, PRERELEASE, DIST_TAG } }).status;
assert.equal(check("push", "0.9.55-alpha.1", "true"), 0);
assert.equal(check("pull_request", "0.9.55", "false"), 0);
assert.equal(check("push", "0.9.55", "false"), 1);
assert.equal(check("pull_request", "0.9.55-alpha.1", "true"), 1);
assert.equal(check("push", "0.9.55-alpha.1;id", "true"), 1);
assert.equal(check("push", "0.9.55-latest.1", "true", "latest"), 1);
assert.equal(check("push", "0.9.55-hdr.1", "true", "hdr"), 0);
assert.equal(check("push", "0.9.55-beta.1", "true", "beta"), 0);
assert.equal(check("push", "0.9.55-LATEST.1", "true", "LATEST"), 1);
assert.equal(check("push", "0.9.55-Latest.1", "true", "Latest"), 1);
assert.equal(check("push", "0.9.55-Alpha.1", "true", "Alpha"), 1);
assert.equal(check("push", "0.9.55-stable.1", "true", "stable"), 1);
const check = (SOURCE, VERSION, PRERELEASE, DIST_TAG = "alpha") =>
runStep(step, { cwd: tmpdir(), env: { SOURCE, VERSION, PRERELEASE, DIST_TAG } }).status;
assert.equal(check("tag", "0.9.55-alpha.1", "true"), 0);
assert.equal(check("release-pr", "0.9.55", "false"), 0);
assert.equal(check("tag", "0.9.55", "false"), 1);
assert.equal(check("release-pr", "0.9.55-alpha.1", "true"), 1);
assert.equal(check("tag", "0.9.55-alpha.1;id", "true"), 1);
assert.equal(check("tag", "0.9.55-latest.1", "true", "latest"), 1);
assert.equal(check("tag", "0.9.55-hdr.1", "true", "hdr"), 0);
assert.equal(check("tag", "0.9.55-beta.1", "true", "beta"), 0);
assert.equal(check("tag", "0.9.55-LATEST.1", "true", "LATEST"), 1);
assert.equal(check("tag", "0.9.55-Latest.1", "true", "Latest"), 1);
assert.equal(check("tag", "0.9.55-Alpha.1", "true", "Alpha"), 1);
assert.equal(check("tag", "0.9.55-stable.1", "true", "stable"), 1);
assert.equal(check("", "0.9.55", "false", "latest"), 1, "no release source");
});
test("the publish job takes only tarballs that npm reads the way the check does", () => {
@@ -717,9 +867,13 @@ test("a tag publishes only a commit already on main, next or alpha, before any j
for (const name of ["lambda-arm64-ffmpeg", "lambda-handler-zip"]) {
assert.deepEqual(config.jobs[name].needs, ["release-source"], name);
}
assert.deepEqual(pack.needs.sort(), ["lambda-arm64-ffmpeg", "lambda-handler-zip"]);
assert.deepEqual([...pack.needs].sort(), [
"lambda-arm64-ffmpeg",
"lambda-handler-zip",
"release-source",
]);
const step = stepOf(source, "Check the tagged commit is on main, next or alpha");
assert.equal(step.if, "github.event_name == 'push'");
assert.equal(step.if, "github.ref_type == 'tag'");
const bin = mkdtempSync(join(tmpdir(), "hyperframes-fake-gh-"));
try {
// The fake answers compare/<branch>...<sha> from FAKE_<branch>; an unset branch answers like a 404.
+1 -1
View File
@@ -306,7 +306,7 @@ test("receipt and bundle persistence precede side effects and do not overwrite p
s.with.path === "${{ runner.temp }}/release-bundle",
);
assert.equal(download.with["artifact-ids"], "${{ needs.pack.outputs.bundle_id }}");
assert.equal(workflow.concurrency["cancel-in-progress"], false);
assert.equal(workflow.jobs.publish.concurrency["cancel-in-progress"], false);
});
// GitHub's implicit bash shell does not enable pipefail; explicit shell: bash does.
+15 -15
View File
@@ -33,11 +33,11 @@ function validateDistTag(version, distTag) {
];
}
function validateMergedReleasePr({ version, prHeadRef }) {
function validateMergedReleasePr({ version, releaseRef }) {
const errors = [];
if (!RELEASE_PR_RE.test(prHeadRef)) {
if (!RELEASE_PR_RE.test(releaseRef)) {
errors.push(
`Merged release PRs must come from release/vX.Y.Z branches, got "${prHeadRef || "<empty>"}".`,
`Merged release PRs must come from release/vX.Y.Z branches, got "${releaseRef || "<empty>"}".`,
);
}
if (expectedDistTag(version) !== "latest") {
@@ -51,7 +51,7 @@ function validateMergedReleasePr({ version, prHeadRef }) {
function validatePrereleaseTagPush({ version, distTag, remoteBranches }) {
if (expectedDistTag(version) === "latest") {
return [
"Stable tag publishing is disabled. Merge a reviewed release/vX.Y.Z PR into main and rerun that immutable merge event for recovery.",
"Stable tag publishing is disabled. Merge a reviewed release/vX.Y.Z PR into main; to recover, rerun the failed jobs of the publish run on that merge.",
];
}
@@ -63,14 +63,14 @@ function validatePrereleaseTagPush({ version, distTag, remoteBranches }) {
];
}
const EVENT_VALIDATORS = new Map([
["pull_request", validateMergedReleasePr],
["push", validatePrereleaseTagPush],
const SOURCE_VALIDATORS = new Map([
["release-pr", validateMergedReleasePr],
["tag", validatePrereleaseTagPush],
]);
function validateReleaseSource(input) {
const validator = EVENT_VALIDATORS.get(input.eventName);
return validator ? validator(input) : [`Unsupported publish event "${input.eventName}".`];
const validator = SOURCE_VALIDATORS.get(input.source);
return validator ? validator(input) : [`Unsupported release source "${input.source}".`];
}
export function validateReleaseChannel(input) {
@@ -93,18 +93,18 @@ function readEnv(name) {
return process.env[name] ?? "";
}
function readRemoteBranchesForEvent(eventName) {
return eventName === "pull_request" ? [] : readRemoteBranchesContainingHead();
function readRemoteBranchesForSource(source) {
return source === "tag" ? readRemoteBranchesContainingHead() : [];
}
function readValidationInput() {
const eventName = readEnv("EVENT_NAME");
const source = readEnv("SOURCE");
return {
version: readEnv("VERSION"),
distTag: readEnv("DIST_TAG"),
eventName,
prHeadRef: readEnv("PR_HEAD_REF"),
remoteBranches: readRemoteBranchesForEvent(eventName),
source,
releaseRef: readEnv("RELEASE_REF"),
remoteBranches: readRemoteBranchesForSource(source),
};
}
+18 -18
View File
@@ -19,8 +19,8 @@ describe("release channel validation", () => {
const errors = validateReleaseChannel({
version: "0.4.24",
distTag: "latest",
eventName: "pull_request",
prHeadRef: "release/v0.4.24",
source: "release-pr",
releaseRef: "release/v0.4.24",
remoteBranches: [],
});
@@ -31,8 +31,8 @@ describe("release channel validation", () => {
const errors = validateReleaseChannel({
version: "0.4.24",
distTag: "latest",
eventName: "push",
prHeadRef: "",
source: "tag",
releaseRef: "",
remoteBranches: ["origin/main", "origin/next"],
});
@@ -44,8 +44,8 @@ describe("release channel validation", () => {
const errors = validateReleaseChannel({
version: "0.4.24",
distTag: "latest",
eventName: "push",
prHeadRef: "",
source: "tag",
releaseRef: "",
remoteBranches: ["origin/release/v0.4.24"],
});
@@ -57,8 +57,8 @@ describe("release channel validation", () => {
const errors = validateReleaseChannel({
version: "0.4.24-alpha.1",
distTag: "alpha",
eventName: "push",
prHeadRef: "",
source: "tag",
releaseRef: "",
remoteBranches: ["origin/next"],
});
@@ -69,8 +69,8 @@ describe("release channel validation", () => {
const errors = validateReleaseChannel({
version: "0.4.24-alpha.1",
distTag: "alpha",
eventName: "push",
prHeadRef: "",
source: "tag",
releaseRef: "",
remoteBranches: ["origin/main"],
});
@@ -82,8 +82,8 @@ describe("release channel validation", () => {
const errors = validateReleaseChannel({
version: "0.4.24-alpha.1",
distTag: "latest",
eventName: "push",
prHeadRef: "",
source: "tag",
releaseRef: "",
remoteBranches: ["origin/next"],
});
@@ -95,8 +95,8 @@ describe("release channel validation", () => {
const errors = validateReleaseChannel({
version: "0.4.24-alpha.1",
distTag: "alpha",
eventName: "pull_request",
prHeadRef: "release/v0.4.24-alpha.1",
source: "release-pr",
releaseRef: "release/v0.4.24-alpha.1",
remoteBranches: [],
});
@@ -105,16 +105,16 @@ describe("release channel validation", () => {
assert.match(errors.join("\n"), /stable releases only/);
});
it("rejects manual publish events", () => {
it("rejects an unknown release source", () => {
const errors = validateReleaseChannel({
version: "0.4.24",
distTag: "latest",
eventName: "workflow_dispatch",
prHeadRef: "",
source: "workflow_dispatch",
releaseRef: "",
remoteBranches: ["origin/main"],
});
assert.deepEqual(errors, ['Unsupported publish event "workflow_dispatch".']);
assert.deepEqual(errors, ['Unsupported release source "workflow_dispatch".']);
});
it("normalizes git branch output", () => {