fix(ci): a release fails its checks when its notes miss a commit merged after the cut (#7601)

* fix(ci): a release fails its checks when its notes miss a commit merged after the cut

* fix(ci): shorten the release checks comment

* fix(ci): find the last release by subject and say to link a deliberate omission
This commit is contained in:
Miguel Ángel
2026-11-12 11:39:42 +00:00
committed by GitHub
parent 234fb1aeef
commit 5d2914f7ce
6 changed files with 142 additions and 18 deletions
+16
View File
@@ -0,0 +1,16 @@
const RELEASE = "chore(?:\\(release\\))?: (?:release|cut) v(\\d+\\.\\d+\\.\\d+)";
/** The version a release commit's subject names, or null for any other subject. */
export function releaseVersionOf(subject) {
return new RegExp(`^${RELEASE}(?: \\(#\\d+\\))?$`).exec(subject)?.[1] ?? null;
}
/** Whether a commit subject stays out of release notes: a release, a version bump, or an explicit skip. */
export function skipsChangelog(subject) {
const lower = subject.toLowerCase();
return (
lower.includes("[skip changelog]") ||
new RegExp(`^${RELEASE}`).test(lower) ||
/^chore: bump version/.test(lower)
);
}
+35 -4
View File
@@ -6,6 +6,7 @@ import { execFileSync } from "node:child_process";
import { appendFileSync } from "node:fs";
import { basename } from "node:path";
import { pathToFileURL } from "node:url";
import { releaseVersionOf, skipsChangelog } from "../changelog-skip.mjs";
const MANIFESTS = new Set(["package.json", "plugin.json", "gemini-extension.json"]);
const RELEASE_NOTES = /^releases\/v\d+\.\d+\.\d+[^/]*\.md$/;
@@ -44,8 +45,13 @@ export function classify(paths, before, after) {
return { releaseOnly: paths.length > 0 && other.length === 0, other, versions };
}
/** The commits in `commits` ({ sha, subject }) that release notes should list but do not link. */
export function unlistedCommits(commits, notes) {
return commits.filter(({ sha, subject }) => !skipsChangelog(subject) && !notes.includes(sha));
}
/** Problems with a release that is otherwise only versions and notes; empty when it is consistent. */
export function verifyRelease({ versions }, after) {
export function verifyRelease({ versions }, after, commits = []) {
const problems = [];
const distinct = new Set(versions.values());
if (distinct.size !== 1) {
@@ -57,8 +63,17 @@ export function verifyRelease({ versions }, after) {
const [version] = distinct;
const notes = after(`releases/v${version}.md`);
if (notes === null) problems.push(`releases/v${version}.md is missing`);
else if (UNREVIEWED.some((marker) => notes.includes(marker)))
problems.push(`releases/v${version}.md still has the generated TODO or style note`);
else {
if (UNREVIEWED.some((marker) => notes.includes(marker)))
problems.push(`releases/v${version}.md still has the generated TODO or style note`);
const unlisted = unlistedCommits(commits, notes);
if (unlisted.length)
problems.push(
`releases/v${version}.md misses ${unlisted.length} commit(s) merged since the notes were drafted: ` +
unlisted.map(({ sha, subject }) => `${sha.slice(0, 9)} ${subject}`).join("; ") +
". Link each in the notes, or rebase on main and rerun `bun run release:prepare` if main moved.",
);
}
const changelog = after(CHANGELOG);
if (changelog === null || !changelog.includes(`label="HyperFrames v${version}"`))
problems.push(`${CHANGELOG} has no entry for v${version}`);
@@ -76,6 +91,22 @@ const show = (ref) => (path) => {
}
};
/** The commits between the last release commit and `base`; empty when `base` holds no earlier release. */
function commitsSinceLastRelease(base) {
const last = git("log", "--format=%H%x09%s", base)
.split("\n")
.find((line) => releaseVersionOf(line.split("\t").slice(1).join("\t")) !== null)
?.split("\t")[0];
if (!last) return [];
return git("log", "--no-merges", "--format=%H%x09%s", `${last}..${base}`)
.split("\n")
.filter(Boolean)
.map((line) => {
const [sha, ...subject] = line.split("\t");
return { sha, subject: subject.join("\t") };
});
}
function main(argv) {
const at = argv.indexOf("--base");
const base = at >= 0 ? argv[at + 1] : "HEAD^1";
@@ -97,7 +128,7 @@ function main(argv) {
);
return 1;
}
const problems = verifyRelease(result, show("HEAD"));
const problems = verifyRelease(result, show("HEAD"), commitsSinceLastRelease(base));
for (const problem of problems) console.error(`::error::${problem}`);
return problems.length ? 1 : 0;
}
+80 -1
View File
@@ -14,7 +14,7 @@ const CHANGELOG = (v, body = "Faster renders.") =>
`<Update\n label="HyperFrames v${v}"\n>\n${body}\n</Update>\n`;
/** A repo whose HEAD~1 is the base: `change` edits the worktree, then it is committed as the "release". */
function repo(change) {
function repo(change, between) {
const root = mkdtempSync(join(tmpdir(), "release-only-"));
const git = (...args) => execFileSync("git", args, { cwd: root, encoding: "utf8" });
const write = (path, text) => {
@@ -31,6 +31,7 @@ function repo(change) {
write("docs/changelog.mdx", CHANGELOG("0.8.1"));
git("add", "-A");
git("commit", "-qm", "base");
if (between) between(write, git);
change(write);
git("add", "-A");
git("commit", "-qm", "release", "--allow-empty");
@@ -134,6 +135,84 @@ test("--verify refuses mixed versions, a missing note, an unreviewed note and a
assert.match(run(noEntry, "--verify").stderr, /no entry for v0\.8\.2/);
});
/** A release v0.8.1 commit, then one feature commit on main; returns the repo and the feature commit's sha. */
function repoWithLateCommit(notesFor) {
let sha = "";
const root = repo(
(write) => {
bump("0.8.2")(write);
write("releases/v0.8.2.md", notesFor(sha));
},
(write, git) => {
git("commit", "-q", "--allow-empty", "-m", "chore: release v0.8.1 (#1)");
write("packages/core/src/late.ts", "export const late = 1;\n");
git("add", "-A");
git("commit", "-qm", "fix(core): a change merged after the notes were drafted (#2)");
sha = git("rev-parse", "HEAD").trim();
},
);
return { root, sha: () => sha };
}
test("--verify fails a release whose notes miss a commit merged since the last release", () => {
const { root, sha } = repoWithLateCommit(() => NOTES("0.8.2", "Nothing listed."));
const result = run(root, "--verify");
assert.equal(result.code, 1);
assert.match(result.stderr, /misses 1 commit\(s\)/);
assert.ok(result.stderr.includes(sha().slice(0, 9)));
});
test("--verify passes once the notes link that commit", () => {
const { root } = repoWithLateCommit((sha) => NOTES("0.8.2", `- late ([x](/commit/${sha})).`));
assert.equal(run(root, "--verify").code, 0);
});
test("commits that release notes leave out never count as missing", () => {
const root = repo(bump("0.8.2"), (write, git) => {
git("commit", "-q", "--allow-empty", "-m", "chore: release v0.8.1 (#1)");
git("commit", "-q", "--allow-empty", "-m", "chore: bump version to 0.8.1-x");
git("commit", "-q", "--allow-empty", "-m", "docs: x [skip changelog]");
});
assert.equal(run(root, "--verify").code, 0);
});
test("the last release is found by its subject, not by a line in another commit's body", () => {
const { root } = (() => {
let sha = "";
const r = repo(
(write) => {
bump("0.8.2")(write);
write("releases/v0.8.2.md", NOTES("0.8.2", "Nothing listed."));
},
(write, git) => {
git("commit", "-q", "--allow-empty", "-m", "chore(release): cut v0.8.1 (#1)");
write("packages/core/src/early.ts", "export const early = 1;\n");
git("add", "-A");
git("commit", "-qm", "fix(core): before the body line (#2)");
git(
"commit",
"-q",
"--allow-empty",
"-m",
"fix(core): squash body (#3)",
"-m",
"chore: release v9.9.9",
);
sha = git("rev-parse", "HEAD~1").trim();
},
);
return { root: r, sha };
})();
const result = run(root, "--verify");
assert.equal(result.code, 1);
assert.match(result.stderr, /misses 2 commit\(s\)/);
});
test("the merge queue runs the release checks on a release diff", () => {
const ci = readFileSync(new URL("../../.github/workflows/ci.yml", import.meta.url), "utf8");
assert.match(ci, /release-checks:[\s\S]*merge_group[\s\S]*release_diff/);
});
test("classify works on plain data", () => {
const files = { "a/package.json": manifest("1"), "plugin.json": manifest("1") };
const after = { "a/package.json": manifest("2"), "plugin.json": manifest("2") };
+3 -10
View File
@@ -11,6 +11,7 @@ import {
validateCliVersion,
type InlineValueOption,
} from "./cli-options.ts";
import { releaseVersionOf, skipsChangelog } from "./changelog-skip.mjs";
import { CHANGELOG_REVIEW_TODO, CHANGELOG_STYLE_NOTE, compareSemver } from "./set-version.ts";
/**
@@ -262,10 +263,7 @@ function listStableTags(): string[] {
/** Versions of the `chore: release vX.Y.Z` commits in `subjects`, tagged here or not. */
export function releaseVersionsInSubjects(subjects: string[]): string[] {
return subjects.flatMap((subject) => {
const match = /^chore: release v(\d+\.\d+\.\d+)(?: \(#\d+\))?$/.exec(subject);
return match ? [match[1]!] : [];
});
return subjects.flatMap((subject) => releaseVersionOf(subject) ?? []);
}
/** Releases whose commit is in `from..ref`, so a clone without their tags still sees them. */
@@ -304,12 +302,7 @@ function getCommits(from: string, to: string): RawCommit[] {
}
export function shouldSkipCommit(commit: RawCommit) {
const subject = commit.subject.toLowerCase();
return (
subject.includes("[skip changelog]") ||
/^chore: release v\d+\.\d+\.\d+/.test(subject) ||
/^chore: bump version/.test(subject)
);
return skipsChangelog(commit.subject);
}
export function parseCommit(commit: RawCommit): ParsedCommit {