Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions .github/scripts/changelog-release.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
// also appends `next_version=<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 "## [<version>]" 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 <version> <date>
// Retitles "## [Unreleased]" to "## [<version>] - <date>" and
Expand All @@ -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 "## [<version>] - <date>" 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) {
Expand All @@ -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;
}

Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading