fix(release): count every pusher of a release, need a second maintainer, date approvals (#8076)

* test(release): a release's approver must not have pushed it, and a second maintainer must have

* fix(release): count every pusher of a release, need a second maintainer, date approvals

* docs(release): who may approve a stable release, and the second maintainer it needs

* test(release): a push the activity log records with no account stops the release

* fix(release): a push recorded with no account stops the release
This commit is contained in:
Miguel Ángel
2026-11-17 16:55:33 +00:00
committed by GitHub
parent 90de9b6196
commit b22ca1a58e
3 changed files with 127 additions and 17 deletions
+96 -12
View File
@@ -74,7 +74,7 @@ test("a push to main publishes only the merge of exactly one approved release PR
const head = "c".repeat(40);
const pull = (overrides = {}) => ({
number: 8000,
user: { login: "releaser" },
user: { login: "releaser", type: "User" },
merged_at: "2026-11-17T02:24:00Z",
merge_commit_sha: sha,
base: { ref: "main" },
@@ -88,8 +88,9 @@ test("a push to main publishes only the merge of exactly one approved release PR
submitted_at: `2026-11-17T0${hour}:00:00Z`,
});
const approved = [review("reviewer", "APPROVED", 1)];
// The fake answers PR 8000's reviews, commits and events, the push from FAKE_COMPARE, each commit's PR lookup from
// FAKE_PULLS_<sha>, and each reviewer's permission from FAKE_PERMISSIONS; the lookup of FAKE_PERMISSION_FAILS fails.
// The fake answers PR 8000, its reviews, commits and events, the branch's activity, the push from FAKE_COMPARE,
// each commit's PR lookup from FAKE_PULLS_<sha>, and each login's permission from FAKE_PERMISSIONS (login=permission
// lines); the lookup of FAKE_PERMISSION_FAILS fails.
writeFileSync(
join(bin, "gh"),
`#!/bin/sh
@@ -97,6 +98,8 @@ case "$*" in
*pulls/8000/reviews*) printf '%s' "$FAKE_REVIEWS" ;;
*pulls/8000/commits*) printf '%s' "$FAKE_COMMITS" ;;
*issues/8000/events*) printf '%s' "$FAKE_EVENTS" ;;
*pulls/8000) printf '%s' "$FAKE_PULL" ;;
*activity\\?ref=refs/heads/release/v0.9.61\\&*) printf '%s' "$FAKE_ACTIVITY" ;;
*compare/*) printf '%s' "$FAKE_COMPARE" ;;
*commits/*/pulls*)
c="$(printf '%s' "$*" | sed 's#.*commits/\\([0-9a-f]*\\)/pulls.*#\\1#')"
@@ -114,7 +117,11 @@ esac
author: { login: author },
committer: { login: committer },
});
const permissions = "releaser=admin\nreviewer=write\nother=admin\noutsider=read";
const permissions = "releaser=admin\nreviewer=write\nother=admin\noutsider=read\nhelper=read";
const pushBy = (login, type = "User", activity_type = "push") => ({
activity_type,
actor: { login, type },
});
chmodSync(join(bin, "gh"), 0o755);
const main = { REF_TYPE: "branch", REF_NAME: "main" };
/** A push of `commits` (oldest first, each `{ sha, message, pulls }`) whose last commit is the run's sha. */
@@ -127,9 +134,20 @@ esac
commits.map(({ sha: c, pulls }) => [`FAKE_PULLS_${c}`, JSON.stringify(pulls)]),
),
});
const run = (pulls, ref = main, reviews = approved, history = {}) => {
/** A release PR's history: one commit and one push by its opener, unless `history` says otherwise. */
const historyOf = (pulls, ref, history) => ({
commits: [commit("releaser", "web-flow")],
push: [{ sha, message: ref.HEAD_MESSAGE ?? "fix: a change", pulls }],
before: "e".repeat(40),
activity: [pushBy("releaser", "User", "branch_creation"), pushBy("releaser")],
events: [],
permissions,
permissionFails: "",
...history,
});
const run = (pulls, ref = main, reviews = approved, given = {}) => {
const history = historyOf(pulls, ref, given);
const out = join(bin, "out");
const commits = history.push ?? [{ sha, message: ref.HEAD_MESSAGE ?? "fix: a change", pulls }];
writeFileSync(out, "");
const result = runStep(step, {
cwd: bin,
@@ -138,13 +156,15 @@ esac
SHA: sha,
RUNNER_TEMP: bin,
GITHUB_OUTPUT: out,
BEFORE: history.before ?? "e".repeat(40),
...push(commits, history.total),
BEFORE: history.before,
...push(history.push, history.total),
FAKE_REVIEWS: JSON.stringify(reviews),
FAKE_COMMITS: JSON.stringify(history.commits ?? [commit("releaser", "web-flow")]),
FAKE_EVENTS: JSON.stringify(history.events ?? []),
FAKE_PERMISSIONS: history.permissions ?? permissions,
FAKE_PERMISSION_FAILS: history.permissionFails ?? "",
FAKE_COMMITS: JSON.stringify(history.commits),
FAKE_PULL: JSON.stringify({ commits: history.listed ?? history.commits.length }),
FAKE_ACTIVITY: JSON.stringify(history.activity),
FAKE_EVENTS: JSON.stringify(history.events),
FAKE_PERMISSIONS: history.permissions,
FAKE_PERMISSION_FAILS: history.permissionFails,
...ref,
},
path: `${bin}:${process.env.PATH}`,
@@ -256,9 +276,73 @@ esac
"the approver force-pushed the branch",
{ events: [{ event: "head_ref_force_pushed", actor: { login: "reviewer" } }] },
],
[
"the approver pushed commits written under another name",
{ activity: [pushBy("releaser", "User", "branch_creation"), pushBy("reviewer")] },
],
[
"the approver pushed commits with no account behind them",
{
commits: [{ author: null, committer: null }],
activity: [pushBy("releaser", "User", "branch_creation"), pushBy("reviewer")],
},
],
[
"the approver created the branch",
{ activity: [pushBy("reviewer", "User", "branch_creation")] },
],
["more commits than GitHub lists", { listed: 251 }],
["no push to the branch was recorded", { activity: [] }],
[
"a push with no recorded account",
{
activity: [
pushBy("releaser", "User", "branch_creation"),
{ activity_type: "push", actor: null },
],
},
],
]) {
assert.equal(run([pull()], main, approved, history).status, 1, why);
}
// A second person with write access opened or pushed the release, besides the approver.
const openedBy = (login, type = "User") => pull({ user: { login, type } });
for (const [why, pulls, history] of [
[
"an opener without write access who pushed",
[openedBy("helper")],
{ activity: [pushBy("helper")] },
],
[
"an app opened and pushed it",
[openedBy("release-app[bot]", "Bot")],
{ activity: [pushBy("release-app[bot]", "Bot")] },
],
[
"an opener without write access and only an app's push",
[openedBy("helper")],
{ activity: [pushBy("ci[bot]", "Bot")] },
],
]) {
assert.equal(run(pulls, main, approved, history).status, 1, why);
}
assert.equal(
run([openedBy("helper")], main, approved, { activity: [pushBy("releaser")] }).status,
0,
"a maintainer's push is the second person when the opener has no write access",
);
// An approval counts only if the base was main when it was given and has not changed since.
const rebased = { events: [{ event: "base_ref_changed", created_at: "2026-11-17T03:00:00Z" }] };
assert.equal(
run([pull()], main, approved, rebased).status,
1,
"an approval given before the base changed to main",
);
assert.equal(
run([pull()], main, [review("reviewer", "APPROVED", 4)], rebased).status,
0,
"an approval given after the last base change",
);
const reapproved = [
review("reviewer", "CHANGES_REQUESTED", 1),
review("reviewer", "APPROVED", 2),