The repository had two tags and no releases, so the only way to find out what a version changed was to open CHANGELOG.md and scroll to the right heading. The release page is where people who do not read changelogs look, and a repository with tags and no releases reads as abandoned. Notes come from CHANGELOG.md rather than from the commit range. The section was written for humans and already exists by the time a tag is cut; generated notes would restate merge subjects nobody chose. `scripts/changelog-section.mjs` extracts one version's section and makes its relative links absolute against the tag — a release body resolves them against the release page, not the repository, so `./BENCHMARKS.md` would have 404'd. That script is a parser writing text that cannot be corrected quietly once it is published, so its boundaries are pinned by a test rather than checked by eye at release time. Both of the bugs it caught while being written are in there: a section swallowing the `[label]: url` block that follows the oldest version, and a relative link surviving into a body. The step is idempotent like the publishes before it, so a re-run finishes what is left instead of stopping here, and `--verify-tag` keeps it from inventing a tag — it attaches to the one that triggered the run and cannot move it. A prerelease is marked as one, which is what keeps the "Latest" badge off a beta. Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
39 lines
1.6 KiB
JavaScript
39 lines
1.6 KiB
JavaScript
#!/usr/bin/env node
|
|
// Prints one version's section of CHANGELOG.md, for a GitHub release body.
|
|
//
|
|
// Reads the current file rather than the tag's copy on purpose: the changelog is the record, so a
|
|
// correction to an old entry should reach the release that describes it.
|
|
//
|
|
// Usage: node scripts/changelog-section.mjs <version> [tag]
|
|
// The optional tag makes relative links absolute — a release body resolves them against the release
|
|
// page, not the repository, and pinning to the tag keeps the link on the file as that version had it.
|
|
import { readFileSync } from 'node:fs';
|
|
|
|
const REPO = 'Expressive-Tea/green-tea';
|
|
const [version, tag] = process.argv.slice(2);
|
|
if (!version) {
|
|
console.error('usage: changelog-section.mjs <version> [tag]');
|
|
process.exit(2);
|
|
}
|
|
|
|
const lines = readFileSync(new URL('../CHANGELOG.md', import.meta.url), 'utf8').split('\n');
|
|
const isHeading = (l) => l.startsWith('## [');
|
|
// The `[label]: url` block at the bottom of the file belongs to no section. Without this the last
|
|
// section swallows it, since nothing else comes after.
|
|
const isLinkRef = (l) => /^\[[^\]]+\]:\s+\S/.test(l);
|
|
|
|
const start = lines.findIndex((l) => l.startsWith(`## [${version}]`));
|
|
if (start === -1) {
|
|
console.error(`no section for ${version}. Headings in CHANGELOG.md:\n${lines.filter(isHeading).join('\n')}`);
|
|
process.exit(1);
|
|
}
|
|
const rest = lines.slice(start + 1);
|
|
const stop = rest.findIndex((l) => isHeading(l) || isLinkRef(l));
|
|
const body = (stop === -1 ? rest : rest.slice(0, stop)).join('\n').trim();
|
|
|
|
const absolute = tag
|
|
? body.replace(/\]\(\.\/([^)\s]+)\)/g, `](https://github.com/${REPO}/blob/${tag}/$1)`)
|
|
: body;
|
|
|
|
console.log(absolute);
|