Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

Let a branch behind master's newest release pass check:changelog-headings

garrytan434f89aec5a5
diff --git a/changelog.d/capy-changelog-headings-behind-master.md b/changelog.d/capy-changelog-headings-behind-master.md
new file mode 100644
index 0000000000..0a2db63fd4
--- /dev/null
+++ b/changelog.d/capy-changelog-headings-behind-master.md
@@ -0,0 +1,4 @@
+**A pull request that is behind master's newest release no longer fails `verify`.**
+
+### Fixed
+- `check:changelog-headings` (in `bun run verify`) refused every branch whose CHANGELOG.md lacked a release heading that master has. Since pull requests carry no version and may land without containing current master, every such branch failed `verify` as soon as a release landed. The check now skips the release headings newer than the branch's own VERSION, which the merged tree carries, and still refuses a branch that dropped a heading at or below its VERSION, so a cut-off changelog is still caught.
diff --git a/scripts/check-changelog-headings.ts b/scripts/check-changelog-headings.ts
index acca053d14..3cf7c2138c 100644
--- a/scripts/check-changelog-headings.ts
+++ b/scripts/check-changelog-headings.ts
@@ -4,7 +4,10 @@
*
* A tool or agent that rewrites CHANGELOG.md from a partial read can cut the file
* (a 42k-line changelog written back as its first few hundred lines). Every
- * `## [X]` heading on the base ref must still be in the working tree's file.
+ * `## [X]` heading on the base ref must still be in the working tree's file, except
+ * a release newer than the working tree's VERSION: since PRs carry no version, a
+ * branch that lands without containing master is behind master's newest releases,
+ * and its merged tree carries them.
* Base ref: $GBRAIN_CHANGELOG_BASE_REF, default origin/master; unavailable: fails
* under CI=true, skips locally. Exit 0 ok or skipped, 1 refused.
* Docs: docs/RELEASING.md#release-restamp
@@ -13,6 +16,12 @@ import { spawnSync } from 'node:child_process';
import { existsSync, readFileSync } from 'node:fs';
import { join } from 'node:path';
+const versionParts = (v: string): number[] | null => (/^\d+(\.\d+){2,3}$/.test(v) ? v.split('.').map(Number) : null);
+const compareParts = (a: number[], b: number[]): number => {
+ for (let i = 0; i < Math.max(a.length, b.length); i++) if ((a[i] ?? 0) !== (b[i] ?? 0)) return (a[i] ?? 0) - (b[i] ?? 0);
+ return 0;
+};
+
export function releaseHeadings(text: string): string[] {
return text.split('\n').filter((line) => line.startsWith('## ['));
}
@@ -35,9 +44,16 @@ export function main(opts: { cwd?: string; env?: Record<string, string | undefin
}
const file = join(root, 'CHANGELOG.md');
const have = new Set(existsSync(file) ? releaseHeadings(readFileSync(file, 'utf8')) : []);
- const missing = releaseHeadings(base.stdout).filter((heading) => !have.has(heading));
+ const own = existsSync(join(root, 'VERSION')) ? versionParts(readFileSync(join(root, 'VERSION'), 'utf8').trim()) : null;
+ const absent = releaseHeadings(base.stdout).filter((heading) => !have.has(heading));
+ const newer = absent.filter((heading) => {
+ const v = versionParts(/^## \[([^\]]+)\]/.exec(heading)?.[1] ?? '');
+ return own !== null && v !== null && compareParts(v, own) > 0;
+ });
+ const missing = absent.filter((heading) => !newer.includes(heading));
if (missing.length === 0) {
- log(`check-changelog-headings: ok (every release heading on ${ref} is present)`);
+ const behind = newer.length > 0 ? `; ${newer.length} newer release heading(s) on ${ref} are not on this branch yet` : '';
+ log(`check-changelog-headings: ok (every release heading on ${ref} is present${behind})`);
return 0;
}
log(`FAIL: CHANGELOG.md is missing ${missing.length} release heading(s) that ${ref} has (first: ${missing[0]}).`);
diff --git a/test/scripts/check-changelog-headings.test.ts b/test/scripts/check-changelog-headings.test.ts
index 8a347725e7..7884d8fada 100644
--- a/test/scripts/check-changelog-headings.test.ts
+++ b/test/scripts/check-changelog-headings.test.ts
@@ -52,6 +52,25 @@ describe('check:changelog-headings', () => {
expect(r.out).toContain('Fix: restore it from the base');
});
+ test('a branch behind master skips only the releases newer than its own VERSION', () => {
+ const root = repo();
+ writeFileSync(join(root, 'VERSION'), '0.60.321.0\n');
+ writeFileSync(join(root, 'CHANGELOG.md'), changelog('0.60.321.0', '0.60.46.0'));
+ const r = run(root);
+ expect(r.code).toBe(0);
+ expect(r.out).toContain('1 newer release heading(s) on origin/master are not on this branch yet');
+ });
+
+ test('a branch behind master that cut an older release heading is still refused', () => {
+ const root = repo();
+ writeFileSync(join(root, 'VERSION'), '0.60.321.0\n');
+ writeFileSync(join(root, 'CHANGELOG.md'), changelog('0.60.321.0'));
+ const r = run(root);
+ expect(r.code).toBe(1);
+ expect(r.out).toContain('missing 1 release heading(s)');
+ expect(r.out).toContain('## [0.60.46.0]');
+ });
+
test('without the base ref: refused under CI, skipped locally', () => {
const root = repo();
git(root, 'update-ref', '-d', 'refs/remotes/origin/master');