Skip to content

Commit 57938b8

Browse files
authored
Merge pull request #4201 from github/mario-campos/automate-changenotes-assemble
Incorporate change-notes into CHANGELOG.md at release
2 parents ee07b50 + a7700b5 commit 57938b8

2 files changed

Lines changed: 35 additions & 17 deletions

File tree

‎pr-checks/changenotes.ts‎

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,28 @@ function getChangenotes(): ChangenoteFile[] {
5050
});
5151
}
5252

53+
/**
54+
* Populates the '[UNRELEASED]' section of CHANGELOG.md with the contents
55+
* of the changenotes in {@link CHANGENOTES_DIR} and then deletes those changenotes.
56+
* @param contents The contents of CHANGELOG.md
57+
* @returns The updated contents of CHANGELOG.md
58+
*/
59+
export function transferChangenotesToChangelog(contents: string): string {
60+
const changenotes = getChangenotes();
61+
const changenoteBodies = changenotes.map((c) => c.content.trim());
62+
const changenotePaths = changenotes.map((c) => c.absolutePath);
63+
64+
const changelog = parseChangelog(contents);
65+
addBodyLinesToUnreleasedSection(changelog, changenoteBodies);
66+
const updatedChangelog = renderChangelog(changelog);
67+
68+
for (const p of changenotePaths) {
69+
fs.unlinkSync(p);
70+
}
71+
72+
return updatedChangelog;
73+
}
74+
5375
const entryPoint = process.argv[1];
5476
if (entryPoint && import.meta.url === pathToFileURL(entryPoint).href) {
5577
try {
@@ -91,26 +113,13 @@ function usage(): ExitCode {
91113

92114
function assemble(): ExitCode {
93115
try {
94-
const changenotes = getChangenotes();
95-
const changenoteBodies = changenotes.map((c) => c.content);
96-
const changenotePaths = changenotes.map((c) => c.absolutePath);
97-
98116
withChangelog((contents) => {
99-
const changelog = parseChangelog(contents);
100-
addBodyLinesToUnreleasedSection(changelog, changenoteBodies);
101-
return renderChangelog(changelog);
117+
return transferChangenotesToChangelog(contents);
102118
}, {});
103-
104-
// Delete changenotes only after successful processing.
105-
for (const p of changenotePaths) {
106-
fs.unlinkSync(p);
107-
}
108-
109119
return ExitCode.Success;
110120
} catch (e) {
111121
console.error("Failed to assemble changenotes to 'CHANGELOG.md'", e);
112122
}
113-
114123
return ExitCode.Failure;
115124
}
116125

‎pr-checks/update-release-branch.ts‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,13 @@ import { parseArgs } from "node:util";
2323

2424
import { type ApiClient, getApiClient } from "./api-client";
2525
import * as changelog from "./changelog";
26-
import { DryRunOption, REPO_ROOT } from "./config";
26+
import { transferChangenotesToChangelog } from "./changenotes";
27+
import {
28+
CHANGELOG_FILE,
29+
CHANGENOTES_DIR,
30+
DryRunOption,
31+
REPO_ROOT,
32+
} from "./config";
2733
import {
2834
getCurrentVersion,
2935
replaceVersionInPackageJson,
@@ -693,11 +699,14 @@ export async function prepareNewBranch(
693699

694700
console.log("Updating changelog");
695701
changelog.withChangelog(
696-
(contents) => changelog.setVersionAndDate(version, contents),
702+
(contents) => {
703+
const populatedContents = transferChangenotesToChangelog(contents);
704+
return changelog.setVersionAndDate(version, populatedContents);
705+
},
697706
{ ...options, initChangelog: true },
698707
);
699708

700-
runGit(["add", "CHANGELOG.md"], {
709+
runGit(["add", CHANGELOG_FILE, CHANGENOTES_DIR], {
701710
dryRun: options.dryRun,
702711
});
703712
runGit(["commit", "-m", `Update changelog for v${version}`], {

0 commit comments

Comments
 (0)