|
| 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