Skip to content

Commit 5d2914f

Browse files
fix(ci): a release fails its checks when its notes miss a commit merged after the cut (heygen-com#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
1 parent 234fb1a commit 5d2914f

6 files changed

Lines changed: 142 additions & 18 deletions

File tree

‎.github/actions/release-only-diff/action.yml‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@ description: >-
44
can skip it. Main and the merge queue never skip. Needs a checkout with full history.
55
outputs:
66
release_only:
7-
description: "'true' when every changed file is a version bump, release note or changelog entry."
7+
description: "'true' when a pull request changes only version bumps, release notes and the changelog entry. Always 'false' elsewhere."
8+
value: ${{ github.event_name == 'pull_request' && steps.diff.outputs.release_only || 'false' }}
9+
release_diff:
10+
description: "'true' when the commit changes only a release's own files, in a pull request or the merge queue."
811
value: ${{ steps.diff.outputs.release_only }}
912
runs:
1013
using: composite
1114
steps:
1215
- id: diff
1316
shell: bash
1417
run: |
15-
if [ "${{ github.event_name }}" = pull_request ]; then
18+
if [ "${{ github.event_name }}" = pull_request ] || [ "${{ github.event_name }}" = merge_group ]; then
1619
node scripts/ci/release-only-diff.mjs
1720
else
1821
echo "release_only=false" >> "$GITHUB_OUTPUT"

‎.github/workflows/ci.yml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ jobs:
7373
pull-requests: read
7474
outputs:
7575
release_only: ${{ steps.release.outputs.release_only }}
76+
release_diff: ${{ steps.release.outputs.release_diff }}
7677
code: ${{ (github.event_name == 'workflow_dispatch' && inputs.catalog_publish) && 'true' || steps.release.outputs.release_only == 'true' && 'false' || steps.filter.outputs.code }}
7778
docs_catalog: ${{ steps.filter.outputs.docs_catalog }}
7879
cli: ${{ steps.release.outputs.release_only == 'true' && 'false' || steps.filter.outputs.cli }}
@@ -272,7 +273,8 @@ jobs:
272273
release-checks:
273274
name: Release checks
274275
needs: changes
275-
if: ${{ needs.changes.outputs.release_only == 'true' }}
276+
# The queue also runs this on a release, so a commit merged after the notes were drafted fails here.
277+
if: ${{ (github.event_name == 'merge_group' && needs.changes.outputs.release_diff == 'true') || needs.changes.outputs.release_only == 'true' }}
276278
runs-on: ubuntu-latest
277279
timeout-minutes: 4
278280
steps:

‎scripts/changelog-skip.mjs‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const RELEASE = "chore(?:\\(release\\))?: (?:release|cut) v(\\d+\\.\\d+\\.\\d+)";
2+
3+
/** The version a release commit's subject names, or null for any other subject. */
4+
export function releaseVersionOf(subject) {
5+
return new RegExp(`^${RELEASE}(?: \\(#\\d+\\))?$`).exec(subject)?.[1] ?? null;
6+
}
7+
8+
/** Whether a commit subject stays out of release notes: a release, a version bump, or an explicit skip. */
9+
export function skipsChangelog(subject) {
10+
const lower = subject.toLowerCase();
11+
return (
12+
lower.includes("[skip changelog]") ||
13+
new RegExp(`^${RELEASE}`).test(lower) ||
14+
/^chore: bump version/.test(lower)
15+
);
16+
}

‎scripts/ci/release-only-diff.mjs‎

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { execFileSync } from "node:child_process";
66
import { appendFileSync } from "node:fs";
77
import { basename } from "node:path";
88
import { pathToFileURL } from "node:url";
9+
import { releaseVersionOf, skipsChangelog } from "../changelog-skip.mjs";
910

1011
const MANIFESTS = new Set(["package.json", "plugin.json", "gemini-extension.json"]);
1112
const RELEASE_NOTES = /^releases\/v\d+\.\d+\.\d+[^/]*\.md$/;
@@ -44,8 +45,13 @@ export function classify(paths, before, after) {
4445
return { releaseOnly: paths.length > 0 && other.length === 0, other, versions };
4546
}
4647

48+
/** The commits in `commits` ({ sha, subject }) that release notes should list but do not link. */
49+
export function unlistedCommits(commits, notes) {
50+
return commits.filter(({ sha, subject }) => !skipsChangelog(subject) && !notes.includes(sha));
51+
}
52+
4753
/** Problems with a release that is otherwise only versions and notes; empty when it is consistent. */
48-
export function verifyRelease({ versions }, after) {
54+
export function verifyRelease({ versions }, after, commits = []) {
4955
const problems = [];
5056
const distinct = new Set(versions.values());
5157
if (distinct.size !== 1) {
@@ -57,8 +63,17 @@ export function verifyRelease({ versions }, after) {
5763
const [version] = distinct;
5864
const notes = after(`releases/v${version}.md`);
5965
if (notes === null) problems.push(`releases/v${version}.md is missing`);
60-
else if (UNREVIEWED.some((marker) => notes.includes(marker)))
61-
problems.push(`releases/v${version}.md still has the generated TODO or style note`);
66+
else {
67+
if (UNREVIEWED.some((marker) => notes.includes(marker)))
68+
problems.push(`releases/v${version}.md still has the generated TODO or style note`);
69+
const unlisted = unlistedCommits(commits, notes);
70+
if (unlisted.length)
71+
problems.push(
72+
`releases/v${version}.md misses ${unlisted.length} commit(s) merged since the notes were drafted: ` +
73+
unlisted.map(({ sha, subject }) => `${sha.slice(0, 9)} ${subject}`).join("; ") +
74+
". Link each in the notes, or rebase on main and rerun `bun run release:prepare` if main moved.",
75+
);
76+
}
6277
const changelog = after(CHANGELOG);
6378
if (changelog === null || !changelog.includes(`label="HyperFrames v${version}"`))
6479
problems.push(`${CHANGELOG} has no entry for v${version}`);
@@ -76,6 +91,22 @@ const show = (ref) => (path) => {
7691
}
7792
};
7893

94+
/** The commits between the last release commit and `base`; empty when `base` holds no earlier release. */
95+
function commitsSinceLastRelease(base) {
96+
const last = git("log", "--format=%H%x09%s", base)
97+
.split("\n")
98+
.find((line) => releaseVersionOf(line.split("\t").slice(1).join("\t")) !== null)
99+
?.split("\t")[0];
100+
if (!last) return [];
101+
return git("log", "--no-merges", "--format=%H%x09%s", `${last}..${base}`)
102+
.split("\n")
103+
.filter(Boolean)
104+
.map((line) => {
105+
const [sha, ...subject] = line.split("\t");
106+
return { sha, subject: subject.join("\t") };
107+
});
108+
}
109+
79110
function main(argv) {
80111
const at = argv.indexOf("--base");
81112
const base = at >= 0 ? argv[at + 1] : "HEAD^1";
@@ -97,7 +128,7 @@ function main(argv) {
97128
);
98129
return 1;
99130
}
100-
const problems = verifyRelease(result, show("HEAD"));
131+
const problems = verifyRelease(result, show("HEAD"), commitsSinceLastRelease(base));
101132
for (const problem of problems) console.error(`::error::${problem}`);
102133
return problems.length ? 1 : 0;
103134
}

‎scripts/ci/release-only-diff.test.mjs‎

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const CHANGELOG = (v, body = "Faster renders.") =>
1414
`<Update\n label="HyperFrames v${v}"\n>\n${body}\n</Update>\n`;
1515

1616
/** A repo whose HEAD~1 is the base: `change` edits the worktree, then it is committed as the "release". */
17-
function repo(change) {
17+
function repo(change, between) {
1818
const root = mkdtempSync(join(tmpdir(), "release-only-"));
1919
const git = (...args) => execFileSync("git", args, { cwd: root, encoding: "utf8" });
2020
const write = (path, text) => {
@@ -31,6 +31,7 @@ function repo(change) {
3131
write("docs/changelog.mdx", CHANGELOG("0.8.1"));
3232
git("add", "-A");
3333
git("commit", "-qm", "base");
34+
if (between) between(write, git);
3435
change(write);
3536
git("add", "-A");
3637
git("commit", "-qm", "release", "--allow-empty");
@@ -134,6 +135,84 @@ test("--verify refuses mixed versions, a missing note, an unreviewed note and a
134135
assert.match(run(noEntry, "--verify").stderr, /no entry for v0\.8\.2/);
135136
});
136137

138+
/** A release v0.8.1 commit, then one feature commit on main; returns the repo and the feature commit's sha. */
139+
function repoWithLateCommit(notesFor) {
140+
let sha = "";
141+
const root = repo(
142+
(write) => {
143+
bump("0.8.2")(write);
144+
write("releases/v0.8.2.md", notesFor(sha));
145+
},
146+
(write, git) => {
147+
git("commit", "-q", "--allow-empty", "-m", "chore: release v0.8.1 (#1)");
148+
write("packages/core/src/late.ts", "export const late = 1;\n");
149+
git("add", "-A");
150+
git("commit", "-qm", "fix(core): a change merged after the notes were drafted (#2)");
151+
sha = git("rev-parse", "HEAD").trim();
152+
},
153+
);
154+
return { root, sha: () => sha };
155+
}
156+
157+
test("--verify fails a release whose notes miss a commit merged since the last release", () => {
158+
const { root, sha } = repoWithLateCommit(() => NOTES("0.8.2", "Nothing listed."));
159+
const result = run(root, "--verify");
160+
assert.equal(result.code, 1);
161+
assert.match(result.stderr, /misses 1 commit\(s\)/);
162+
assert.ok(result.stderr.includes(sha().slice(0, 9)));
163+
});
164+
165+
test("--verify passes once the notes link that commit", () => {
166+
const { root } = repoWithLateCommit((sha) => NOTES("0.8.2", `- late ([x](/commit/${sha})).`));
167+
assert.equal(run(root, "--verify").code, 0);
168+
});
169+
170+
test("commits that release notes leave out never count as missing", () => {
171+
const root = repo(bump("0.8.2"), (write, git) => {
172+
git("commit", "-q", "--allow-empty", "-m", "chore: release v0.8.1 (#1)");
173+
git("commit", "-q", "--allow-empty", "-m", "chore: bump version to 0.8.1-x");
174+
git("commit", "-q", "--allow-empty", "-m", "docs: x [skip changelog]");
175+
});
176+
assert.equal(run(root, "--verify").code, 0);
177+
});
178+
179+
test("the last release is found by its subject, not by a line in another commit's body", () => {
180+
const { root } = (() => {
181+
let sha = "";
182+
const r = repo(
183+
(write) => {
184+
bump("0.8.2")(write);
185+
write("releases/v0.8.2.md", NOTES("0.8.2", "Nothing listed."));
186+
},
187+
(write, git) => {
188+
git("commit", "-q", "--allow-empty", "-m", "chore(release): cut v0.8.1 (#1)");
189+
write("packages/core/src/early.ts", "export const early = 1;\n");
190+
git("add", "-A");
191+
git("commit", "-qm", "fix(core): before the body line (#2)");
192+
git(
193+
"commit",
194+
"-q",
195+
"--allow-empty",
196+
"-m",
197+
"fix(core): squash body (#3)",
198+
"-m",
199+
"chore: release v9.9.9",
200+
);
201+
sha = git("rev-parse", "HEAD~1").trim();
202+
},
203+
);
204+
return { root: r, sha };
205+
})();
206+
const result = run(root, "--verify");
207+
assert.equal(result.code, 1);
208+
assert.match(result.stderr, /misses 2 commit\(s\)/);
209+
});
210+
211+
test("the merge queue runs the release checks on a release diff", () => {
212+
const ci = readFileSync(new URL("../../.github/workflows/ci.yml", import.meta.url), "utf8");
213+
assert.match(ci, /release-checks:[\s\S]*merge_group[\s\S]*release_diff/);
214+
});
215+
137216
test("classify works on plain data", () => {
138217
const files = { "a/package.json": manifest("1"), "plugin.json": manifest("1") };
139218
const after = { "a/package.json": manifest("2"), "plugin.json": manifest("2") };

‎scripts/draft-changelog.ts‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
validateCliVersion,
1212
type InlineValueOption,
1313
} from "./cli-options.ts";
14+
import { releaseVersionOf, skipsChangelog } from "./changelog-skip.mjs";
1415
import { CHANGELOG_REVIEW_TODO, CHANGELOG_STYLE_NOTE, compareSemver } from "./set-version.ts";
1516

1617
/**
@@ -262,10 +263,7 @@ function listStableTags(): string[] {
262263

263264
/** Versions of the `chore: release vX.Y.Z` commits in `subjects`, tagged here or not. */
264265
export function releaseVersionsInSubjects(subjects: string[]): string[] {
265-
return subjects.flatMap((subject) => {
266-
const match = /^chore: release v(\d+\.\d+\.\d+)(?: \(#\d+\))?$/.exec(subject);
267-
return match ? [match[1]!] : [];
268-
});
266+
return subjects.flatMap((subject) => releaseVersionOf(subject) ?? []);
269267
}
270268

271269
/** 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[] {
304302
}
305303

306304
export function shouldSkipCommit(commit: RawCommit) {
307-
const subject = commit.subject.toLowerCase();
308-
return (
309-
subject.includes("[skip changelog]") ||
310-
/^chore: release v\d+\.\d+\.\d+/.test(subject) ||
311-
/^chore: bump version/.test(subject)
312-
);
305+
return skipsChangelog(commit.subject);
313306
}
314307

315308
export function parseCommit(commit: RawCommit): ParsedCommit {

0 commit comments

Comments
 (0)