From 5d2914f7ceb626e750b1f08feee7fa2bf628f025 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Thu, 12 Nov 2026 11:39:42 +0000 Subject: [PATCH] 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 --- .github/actions/release-only-diff/action.yml | 7 +- .github/workflows/ci.yml | 4 +- scripts/changelog-skip.mjs | 16 ++++ scripts/ci/release-only-diff.mjs | 39 +++++++++- scripts/ci/release-only-diff.test.mjs | 81 +++++++++++++++++++- scripts/draft-changelog.ts | 13 +--- 6 files changed, 142 insertions(+), 18 deletions(-) create mode 100644 scripts/changelog-skip.mjs diff --git a/.github/actions/release-only-diff/action.yml b/.github/actions/release-only-diff/action.yml index 34109d418a..9d2679e2b7 100644 --- a/.github/actions/release-only-diff/action.yml +++ b/.github/actions/release-only-diff/action.yml @@ -4,7 +4,10 @@ description: >- can skip it. Main and the merge queue never skip. Needs a checkout with full history. outputs: release_only: - description: "'true' when every changed file is a version bump, release note or changelog entry." + description: "'true' when a pull request changes only version bumps, release notes and the changelog entry. Always 'false' elsewhere." + value: ${{ github.event_name == 'pull_request' && steps.diff.outputs.release_only || 'false' }} + release_diff: + description: "'true' when the commit changes only a release's own files, in a pull request or the merge queue." value: ${{ steps.diff.outputs.release_only }} runs: using: composite @@ -12,7 +15,7 @@ runs: - id: diff shell: bash run: | - if [ "${{ github.event_name }}" = pull_request ]; then + if [ "${{ github.event_name }}" = pull_request ] || [ "${{ github.event_name }}" = merge_group ]; then node scripts/ci/release-only-diff.mjs else echo "release_only=false" >> "$GITHUB_OUTPUT" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6ad6e62abd..56cdfa6a74 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -73,6 +73,7 @@ jobs: pull-requests: read outputs: release_only: ${{ steps.release.outputs.release_only }} + release_diff: ${{ steps.release.outputs.release_diff }} code: ${{ (github.event_name == 'workflow_dispatch' && inputs.catalog_publish) && 'true' || steps.release.outputs.release_only == 'true' && 'false' || steps.filter.outputs.code }} docs_catalog: ${{ steps.filter.outputs.docs_catalog }} cli: ${{ steps.release.outputs.release_only == 'true' && 'false' || steps.filter.outputs.cli }} @@ -272,7 +273,8 @@ jobs: release-checks: name: Release checks needs: changes - if: ${{ needs.changes.outputs.release_only == 'true' }} + # The queue also runs this on a release, so a commit merged after the notes were drafted fails here. + if: ${{ (github.event_name == 'merge_group' && needs.changes.outputs.release_diff == 'true') || needs.changes.outputs.release_only == 'true' }} runs-on: ubuntu-latest timeout-minutes: 4 steps: diff --git a/scripts/changelog-skip.mjs b/scripts/changelog-skip.mjs new file mode 100644 index 0000000000..6aaca1c4c5 --- /dev/null +++ b/scripts/changelog-skip.mjs @@ -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) + ); +} diff --git a/scripts/ci/release-only-diff.mjs b/scripts/ci/release-only-diff.mjs index d3d96b9176..57e43761ea 100644 --- a/scripts/ci/release-only-diff.mjs +++ b/scripts/ci/release-only-diff.mjs @@ -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; } diff --git a/scripts/ci/release-only-diff.test.mjs b/scripts/ci/release-only-diff.test.mjs index ec13d2527f..76f29c6269 100644 --- a/scripts/ci/release-only-diff.test.mjs +++ b/scripts/ci/release-only-diff.test.mjs @@ -14,7 +14,7 @@ const CHANGELOG = (v, body = "Faster renders.") => `\n${body}\n\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") }; diff --git a/scripts/draft-changelog.ts b/scripts/draft-changelog.ts index 078536d0dc..b66f5db342 100644 --- a/scripts/draft-changelog.ts +++ b/scripts/draft-changelog.ts @@ -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 {