Skip to content

Commit 4468cf9

Browse files
committed
ci(release): re-extract possibly edited changelog for use in release notes
1 parent 654d9bb commit 4468cf9

File tree

1 file changed

+35
-26
lines changed

1 file changed

+35
-26
lines changed

scripts/release.mjs

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -147,41 +147,48 @@ async function main() {
147147

148148
// 3. Extract release notes from CHANGELOG.md
149149
log.info("Extracting release notes from CHANGELOG.md...");
150-
const changelog = fs.readFileSync(CHANGELOG_PATH, "utf-8");
151-
const lines = changelog.split("\n");
152150

153-
const versionHeader = `## ${tag}`;
154-
const startIndex = lines.findIndex((line) => line.startsWith(versionHeader));
151+
function extractReleaseNotes() {
152+
const changelog = fs.readFileSync(CHANGELOG_PATH, "utf-8");
153+
const lines = changelog.split("\n");
155154

156-
if (startIndex === -1) {
157-
log.error(
158-
`Could not find release notes for version ${tag} in CHANGELOG.md.`,
155+
const versionHeader = `## ${tag}`;
156+
const startIndex = lines.findIndex((line) =>
157+
line.startsWith(versionHeader),
159158
);
160-
process.exit(1);
161-
}
162159

163-
// Find the end of the section for the current version
164-
let endIndex = lines.findIndex(
165-
(line, index) => index > startIndex && line.startsWith("## v"),
166-
);
167-
if (endIndex === -1) {
168-
endIndex = lines.length;
169-
}
160+
if (startIndex === -1) {
161+
log.error(
162+
`Could not find release notes for version ${tag} in CHANGELOG.md.`,
163+
);
164+
process.exit(1);
165+
}
170166

171-
// Find the '[compare changes]' link to start the notes from there
172-
const sectionLines = lines.slice(startIndex, endIndex);
173-
const notesStartIndex = sectionLines.findIndex((line) =>
174-
line.startsWith("[compare changes]"),
175-
);
167+
// Find the end of the section for the current version
168+
let endIndex = lines.findIndex(
169+
(line, index) => index > startIndex && line.startsWith("## v"),
170+
);
171+
if (endIndex === -1) {
172+
endIndex = lines.length;
173+
}
176174

177-
if (notesStartIndex === -1) {
178-
log.error(
179-
`Could not find '[compare changes]' link for version ${tag} in CHANGELOG.md.`,
175+
// Find the '[compare changes]' link to start the notes from there
176+
const sectionLines = lines.slice(startIndex, endIndex);
177+
const notesStartIndex = sectionLines.findIndex((line) =>
178+
line.startsWith("[compare changes]"),
180179
);
181-
process.exit(1);
180+
181+
if (notesStartIndex === -1) {
182+
log.error(
183+
`Could not find '[compare changes]' link for version ${tag} in CHANGELOG.md.`,
184+
);
185+
process.exit(1);
186+
}
187+
188+
return sectionLines.slice(notesStartIndex).join("\n").trim();
182189
}
183190

184-
const releaseNotes = sectionLines.slice(notesStartIndex).join("\n").trim();
191+
let releaseNotes = extractReleaseNotes();
185192

186193
if (!releaseNotes) {
187194
log.error("Extracted release notes are empty.");
@@ -258,6 +265,8 @@ async function main() {
258265

259266
// 10. Create a GitHub release
260267
log.info("Creating GitHub release...");
268+
// Re-extract the changelog, which may have been edited in the review step
269+
releaseNotes = extractReleaseNotes();
261270
await run("gh", [
262271
"release",
263272
"create",

0 commit comments

Comments
 (0)