From 3ca203c7538dd5bdc954b13dad9806502337cc5d Mon Sep 17 00:00:00 2001 From: bbassie <17990055+bbassie@users.noreply.github.com> Date: Sat, 21 Nov 2026 02:56:38 +0000 Subject: [PATCH] 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 --- docs/release-workflow.md | 2 ++ scripts/pr_to_changelog.mts | 14 ++++++++++---- scripts/prepare_release.mts | 20 ++++++++++++++++---- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/docs/release-workflow.md b/docs/release-workflow.md index 20b7ea80..c771973e 100644 --- a/docs/release-workflow.md +++ b/docs/release-workflow.md @@ -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`. Nothing is pushed. 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 node scripts/prepare_release.mts 2.0.2 diff --git a/scripts/pr_to_changelog.mts b/scripts/pr_to_changelog.mts index bcaefd96..2cb52e1e 100644 --- a/scripts/pr_to_changelog.mts +++ b/scripts/pr_to_changelog.mts @@ -195,20 +195,21 @@ export function checkPullRequestBody( function changelogFromPullRequests(pullRequests: Issue[], issues: Issue[]) { const mergedChangelog: Changelog = Object.create(null); + const problems: string[] = []; for (const pr of pullRequests) { const { changelog, error, warnings } = checkPullRequestBody(pr.body, pr, issues); 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; } 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)) { mergedChangelog[section] = [...mergedChangelog[section] ?? [], ...items]; } } - return mergedChangelog; + return [mergedChangelog, problems] as const; } async function fetchLastRelease() { @@ -316,11 +317,13 @@ export async function generateReleaseNotes() { && 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 statistics = await fetchStatistics(lastRelease, pullRequests); return { + /** Errors and warnings from the pull request changelogs. */ + problems, github: formatMarkdown(changelog, issues, users, statistics, issue => `${repository}#${issue.number}`, user => `@${user.login}`, @@ -334,6 +337,9 @@ export async function generateReleaseNotes() { async function main() { const notes = await generateReleaseNotes(); + for (const problem of notes.problems) { + console.warn(problem); + } console.log(); console.log("=== Github Release Markdown ==="); diff --git a/scripts/prepare_release.mts b/scripts/prepare_release.mts index a48cbc85..a052120f 100644 --- a/scripts/prepare_release.mts +++ b/scripts/prepare_release.mts @@ -1,5 +1,6 @@ // Bumps the package versions, adds the release notes to CHANGELOG.md, then commits and tags the release. -// Usage: node scripts/prepare_release.mts +// Usage: node scripts/prepare_release.mts [--force] +// --force continues when pull request changelogs have errors or warnings. import { execFile } from "node:child_process"; import fs from "node:fs/promises"; import path from "node:path"; @@ -46,9 +47,11 @@ async function packageFiles() { } async function main() { - const version = process.argv[2]; - if (!version || !versionPattern.test(version)) { - console.error("Usage: node scripts/prepare_release.mts , e.g. 2.1.2"); + const args = process.argv.slice(2); + const force = args.includes("--force"); + const [version, ...rest] = args.filter(arg => arg !== "--force"); + if (!version || rest.length || !versionPattern.test(version)) { + console.error("Usage: node scripts/prepare_release.mts [--force] , e.g. 2.1.2"); process.exitCode = 1; return; } @@ -61,6 +64,15 @@ async function main() { // Done first so a GitHub API failure leaves the working tree untouched. 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 changelog = addChangelogEntry(await fs.readFile(changelogPath, "utf8"), version, notes.changelog);