Skip to content

Commit 8e219a1

Browse files
committed
chore: add a release notes script and the release steps to AGENTS.md
1 parent b875737 commit 8e219a1

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

‎AGENTS.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ Node, which is how the tests run.
8282
breaks the page API or the package layout with `!` (`feat!: ...`). PRs merge
8383
by squash, so the PR title becomes the commit on `master`. PR bodies follow
8484
`.github/pull_request_template.md`
85+
- A release is a `chore: release X.Y.Z` PR that bumps `package.json`, then
86+
`gh release create vX.Y.Z --target <its commit on master>`. The notes are a
87+
few sentences for users, then the output of
88+
`node scripts/release-notes.ts vPREVIOUS vX.Y.Z`: the merged PRs by type,
89+
linked, and a compare link. The release workflow publishes to npm
8590

8691
## Glossary
8792

‎scripts/release-notes.ts‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Prints the change list of a release as Markdown: the squash-merged pull
2+
// requests on master since the last tag, grouped by Conventional Commit type.
3+
// Write a few sentences for users above it.
4+
//
5+
// node scripts/release-notes.ts [<since-tag> [<next-tag>]] (since: the newest tag before HEAD)
6+
7+
import { execFileSync } from "node:child_process";
8+
9+
const REPO = "https://github.com/Project516/java-web";
10+
const git = (...args: string[]) => execFileSync("git", args, { encoding: "utf8" }).trim();
11+
12+
const since = process.argv[2] ?? git("describe", "--tags", "--abbrev=0");
13+
const next = process.argv[3];
14+
const titles = git("log", "--first-parent", "--format=%s", `${since}..HEAD`).split("\n").filter(Boolean);
15+
16+
interface Entry { type?: string; scope?: string; breaking?: boolean; summary: string; pr?: string }
17+
const sections: [string, (e: Entry) => boolean][] = [
18+
["Breaking changes", (e) => !!e.breaking],
19+
["Features", (e) => e.type === "feat"],
20+
["Performance", (e) => e.type === "perf"],
21+
["Fixes", (e) => e.type === "fix"],
22+
["Dependencies", (e) => e.scope === "deps"],
23+
["Build and CI", (e) => e.type === "build" || e.type === "ci"],
24+
["Documentation", (e) => e.type === "docs"],
25+
["Other", () => true],
26+
];
27+
28+
const groups = new Map<string, string[]>(sections.map(([name]) => [name, []]));
29+
for (const title of titles) {
30+
// the version bump is the release itself
31+
if (/^chore: release \S+( \(#\d+\))?$/.test(title)) continue;
32+
const m = /^(\w+)(?:\(([^)]+)\))?(!)?: (.*?)(?: \(#(\d+)\))?$/.exec(title);
33+
const e: Entry = m ? { type: m[1], scope: m[2], breaking: !!m[3], summary: m[4], pr: m[5] } : { summary: title };
34+
const [name] = sections.find(([, matches]) => matches(e))!;
35+
const scope = e.scope && e.scope !== "deps" ? `**${e.scope}:** ` : "";
36+
groups.get(name)!.push(`- ${scope}${e.summary}${e.pr ? ` ([#${e.pr}](${REPO}/pull/${e.pr}))` : ""}`);
37+
}
38+
39+
const out: string[] = [];
40+
for (const [name, lines] of groups) if (lines.length) out.push(`## ${name}\n\n${lines.join("\n")}\n`);
41+
if (next) out.push(`**Full list:** ${REPO}/compare/${since}...${next}`);
42+
console.log(out.join("\n"));

0 commit comments

Comments
 (0)