From 7656fa89a3a964b3b0bb89c9d1aa9c8d6075b2ac Mon Sep 17 00:00:00 2001 From: noelmcloughlin Date: Mon, 16 Nov 2026 00:25:42 +0000 Subject: [PATCH] fix(ci): give each GitHub release its changelog section as its body Signed-off-by: noelmcloughlin --- .github/scripts/changelog-release.mjs | 25 +++++++++++++++++++++---- CHANGELOG.md | 4 ++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/.github/scripts/changelog-release.mjs b/.github/scripts/changelog-release.mjs index 7bd6814..4d3f18e 100644 --- a/.github/scripts/changelog-release.mjs +++ b/.github/scripts/changelog-release.mjs @@ -16,6 +16,10 @@ // also appends `next_version=` to $GITHUB_OUTPUT if that // env var is set (a side channel a caller can read even from a // --dry-run invocation, where nothing else is written anywhere). +// When Unreleased is empty and "## []" exists, it prints +// that section's body instead. semantic-release runs this command a +// second time after @semantic-release/git commits the promoted +// changelog, and the second output becomes the GitHub release body. // // node changelog-release.mjs promote // Retitles "## [Unreleased]" to "## [] - " and @@ -35,10 +39,23 @@ function readUnreleased() { if (start === -1) { throw new Error(`${FILE} has no "${HEADING}" heading - this pipeline expects one.`); } - const bodyStart = start + HEADING.length; + return { text, body: sectionBody(text, start + HEADING.length) }; +} + +// The text from bodyStart to the next "## [" heading, trimmed. +function sectionBody(text, bodyStart) { const next = text.indexOf("\n## [", bodyStart); const bodyEnd = next === -1 ? text.length : next; - return { text, body: text.slice(bodyStart, bodyEnd).trim() }; + return text.slice(bodyStart, bodyEnd).trim(); +} + +// The body of the "## [] - " section, or "" when there is none. +function versionBody(text, version) { + if (!version) return ""; + const start = text.indexOf(`\n## [${version}]`); + if (start === -1) return ""; + const lineEnd = text.indexOf("\n", start + 1); + return lineEnd === -1 ? "" : sectionBody(text, lineEnd); } function writeOutput(line) { @@ -63,9 +80,9 @@ switch (cmd) { case "notes": { const [version] = args; - const { body } = readUnreleased(); + const { text, body } = readUnreleased(); if (version) writeOutput(`next_version=${version}\n`); - process.stdout.write(body + "\n"); + process.stdout.write((body || versionBody(text, version)) + "\n"); break; } diff --git a/CHANGELOG.md b/CHANGELOG.md index 5600eee..aedc12d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ The `v0.0.0` tag is a baseline, not a release: it marks where versioning starts ## [Unreleased] +### Fixed + +- **Each GitHub release carries its changelog section as its body**: semantic-release asks for the notes again after the changelog commit, and `changelog-release.mjs notes` now answers with the promoted section instead of the empty Unreleased one. + ## [0.1.5] - 2026-11-15 ### Changed