Stop prepare_release on changelog problems unless --force

generateReleaseNotes() returns the errors and warnings from the pull
request changelogs instead of printing them. prepare_release.mts lists
them and aborts before touching any file, --force continues anyway.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bbassieandClaude Opus 5.5 committed 2026-11-21 02:56:38 +00:00
1 parent 8e01a96df9
commit 3ca203c753
3 files changed
+28 -8

No files matched your search

+2
View File
@@ -38,6 +38,8 @@ The steps below describe publishing npm packages manually instead.
It sets the version in the `package.json` files under `packages/` and `plugins/`, adds the changelog from merged pull requests to the top of CHANGELOG.md, commits it as "Prepare 2.0.2" and tags that commit `v2.0.2`. It sets the version in the `package.json` files under `packages/` and `plugins/`, adds the changelog from merged pull requests to the top of CHANGELOG.md, commits it as "Prepare 2.0.2" and tags that commit `v2.0.2`.
Nothing is pushed. Nothing is pushed.
It also prints the GitHub Release Markdown for the release notes. It also prints the GitHub Release Markdown for the release notes.
If a merged pull request has a missing or malformed changelog section, the script lists the problems and stops before changing anything.
Fix the pull request description and run it again, or pass `--force` to continue anyway. Entries with warnings are kept, pull requests whose changelog section could not be read are left out.
```sh ```sh
node scripts/prepare_release.mts 2.0.2 node scripts/prepare_release.mts 2.0.2
+10 -4
View File
@@ -195,20 +195,21 @@ export function checkPullRequestBody(
function changelogFromPullRequests(pullRequests: Issue[], issues: Issue[]) { function changelogFromPullRequests(pullRequests: Issue[], issues: Issue[]) {
const mergedChangelog: Changelog = Object.create(null); const mergedChangelog: Changelog = Object.create(null);
const problems: string[] = [];
for (const pr of pullRequests) { for (const pr of pullRequests) {
const { changelog, error, warnings } = checkPullRequestBody(pr.body, pr, issues); const { changelog, error, warnings } = checkPullRequestBody(pr.body, pr, issues);
if (error) { if (error) {
console.error(`Failed to extract changelog in ${pr.html_url}: ${error}`) problems.push(`Failed to extract changelog in ${pr.html_url}: ${error}`);
continue; continue;
} }
for (const warning of warnings) { for (const warning of warnings) {
console.warn(`Warning in changelog for ${pr.html_url}: ${warning}`) problems.push(`Warning in changelog for ${pr.html_url}: ${warning}`);
} }
for (const [section, items] of Object.entries(changelog)) { for (const [section, items] of Object.entries(changelog)) {
mergedChangelog[section] = [...mergedChangelog[section] ?? [], ...items]; mergedChangelog[section] = [...mergedChangelog[section] ?? [], ...items];
} }
} }
return mergedChangelog; return [mergedChangelog, problems] as const;
} }
async function fetchLastRelease() { async function fetchLastRelease() {
@@ -316,11 +317,13 @@ export async function generateReleaseNotes() {
&& issue.pull_request.merged_at > lastRelease.created_at && issue.pull_request.merged_at > lastRelease.created_at
)); ));
const changelog = changelogFromPullRequests(pullRequests, issues); const [changelog, problems] = changelogFromPullRequests(pullRequests, issues);
const users = [...new Map(pullRequests.map(issue => [issue.user.login, issue.user])).values()]; const users = [...new Map(pullRequests.map(issue => [issue.user.login, issue.user])).values()];
const statistics = await fetchStatistics(lastRelease, pullRequests); const statistics = await fetchStatistics(lastRelease, pullRequests);
return { return {
/** Errors and warnings from the pull request changelogs. */
problems,
github: formatMarkdown(changelog, issues, users, statistics, github: formatMarkdown(changelog, issues, users, statistics,
issue => `${repository}#${issue.number}`, issue => `${repository}#${issue.number}`,
user => `@${user.login}`, user => `@${user.login}`,
@@ -334,6 +337,9 @@ export async function generateReleaseNotes() {
async function main() { async function main() {
const notes = await generateReleaseNotes(); const notes = await generateReleaseNotes();
for (const problem of notes.problems) {
console.warn(problem);
}
console.log(); console.log();
console.log("=== Github Release Markdown ==="); console.log("=== Github Release Markdown ===");
+16 -4
View File
@@ -1,5 +1,6 @@
// Bumps the package versions, adds the release notes to CHANGELOG.md, then commits and tags the release. // Bumps the package versions, adds the release notes to CHANGELOG.md, then commits and tags the release.
// Usage: node scripts/prepare_release.mts <version> // Usage: node scripts/prepare_release.mts [--force] <version>
// --force continues when pull request changelogs have errors or warnings.
import { execFile } from "node:child_process"; import { execFile } from "node:child_process";
import fs from "node:fs/promises"; import fs from "node:fs/promises";
import path from "node:path"; import path from "node:path";
@@ -46,9 +47,11 @@ async function packageFiles() {
} }
async function main() { async function main() {
const version = process.argv[2]; const args = process.argv.slice(2);
if (!version || !versionPattern.test(version)) { const force = args.includes("--force");
console.error("Usage: node scripts/prepare_release.mts <version>, e.g. 2.1.2"); const [version, ...rest] = args.filter(arg => arg !== "--force");
if (!version || rest.length || !versionPattern.test(version)) {
console.error("Usage: node scripts/prepare_release.mts [--force] <version>, e.g. 2.1.2");
process.exitCode = 1; process.exitCode = 1;
return; return;
} }
@@ -61,6 +64,15 @@ async function main() {
// Done first so a GitHub API failure leaves the working tree untouched. // Done first so a GitHub API failure leaves the working tree untouched.
const notes = await generateReleaseNotes(); const notes = await generateReleaseNotes();
for (const problem of notes.problems) {
console.warn(problem);
}
if (notes.problems.length && !force) {
throw new Error(
`Found ${notes.problems.length} changelog problem(s) in merged pull requests. ` +
"Fix the pull request descriptions and run it again, or pass --force to continue anyway."
);
}
const changelogPath = path.join(root, "CHANGELOG.md"); const changelogPath = path.join(root, "CHANGELOG.md");
const changelog = addChangelogEntry(await fs.readFile(changelogPath, "utf8"), version, notes.changelog); const changelog = addChangelogEntry(await fs.readFile(changelogPath, "utf8"), version, notes.changelog);