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

+10 -4
View File
@@ -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 ===");
+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.
// 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 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 <version>, 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] <version>, 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);