Skip to content

Commit 3bbb1f1

Browse files
dblockclaude
andcommitted
Publish changelog sections as GitHub Release notes
Changelog formats gain notes(version), which reads the released section with the format's own heading, expands reference links, and drops link definitions trailing the section. The standard workflow reads it before any publication and passes it to hosting, so GitHub Releases carry the reviewed changelog instead of generated notes, and a missing section fails before the gem is pushed. Releases that already carry notes and changelogs without notes keep their current behavior. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011Gr21hZDQo5axDMuFgzL6s
1 parent 42180fa commit 3bbb1f1

16 files changed

Lines changed: 103 additions & 12 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## 0.9.1 (Next)
44

5+
- [#90](https://github.com/dblock/ruby-gem-release/pull/90): Publish the released changelog section as GitHub Release notes in the standard workflow instead of generated notes, read before any publication - [@dblock](https://github.com/dblock).
56
- Your contribution here.
67

78
## 0.9.0 (2026/11/20)

‎RELEASING.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Rerun with the same source commit and inputs, including the release date. Each t
7272

7373
Builds overwrite local artifacts reproducibly. Capture exports the committer timestamp of the source commit as `SOURCE_DATE_EPOCH`, unless explicitly supplied; it controls the gemspec date and archive timestamps. Generated release commits do not change it. Stable toolchains, gemspecs, generated files, and signing inputs remain the caller's responsibility. RubyGems accepts an existing version only when its SHA256 matches; a differing or unavailable checksum fails.
7474

75-
Git reuses matching release and development trees without moving tags or rewinding remote descendants. Development bumps calculate from the supplied release version, so repetition does not increment twice. GitHub replaces differing release metadata and assets; unspecified platform-generated notes are retained.
75+
Git reuses matching release and development trees without moving tags or rewinding remote descendants. Development bumps calculate from the supplied release version, so repetition does not increment twice. GitHub replaces differing release metadata, notes read from the changelog, and assets; unspecified platform-generated notes are retained.
7676

7777
Actions preserves `release.gem`, its name/version/digest manifest `release.json`, and `release.bundle` before publication for 30 days. These are for manual inspection, not automatic restoration. Conflicting checksums or tags and unrelated branch advancement require investigation; do not overwrite immutable releases.
7878

‎docs/changelog/base.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ Default validation requires an existing selected release or pending notes; other
1818

1919
New releases require nonempty notes. Only the current section counts, ending at the next heading of equal or shallower depth. Blank lines, category headings, HTML comments or blocks, reference definitions, and the configured `Intridea` contribution placeholder are not notes. Text, lists, quotes, and code with content count. Errors identify the version and changelog path.
2020

21+
## Notes
22+
23+
`notes(version)` returns the released section for that version, read without editing the file. It uses the format's own release heading, expands reference links inline, and drops link definitions trailing the section, as [read-only notes](notes.md) do with `expand_references: true`. Unreleased, missing, duplicate, or empty sections raise. The [standard workflow](../workflow/ruby_gem.md#hosting) passes the result to hosting.
24+
2125
## Prepare Next
2226

2327
`prepare_next!(release)` delegates the released version and the version for the next development iteration to the concrete format implementation.

‎docs/changelog/notes.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ notes = RubyGemRelease::Changelog::Notes.new(
1414

1515
Parsing requires the optional Commonmarker dependency. Exactly one real Markdown heading must match; fenced examples do not count. Extraction stops at the next heading of the same or higher level and rejects empty notes. Original line endings and subsection formatting are retained; surrounding whitespace is stripped.
1616

17-
With `expand_references: true`, resolved reference links and images become inline links, including definitions elsewhere in the source. Code, unresolved references, and existing inline links remain unchanged. The source file is never written. Pass the resulting string as the release's `notes:` for hosted publication.
17+
With `expand_references: true`, resolved reference links and images become inline links, including definitions elsewhere in the source. Code, unresolved references, and existing inline links remain unchanged. Link reference definitions trailing the section, such as Keep a Changelog comparison links at the end of the file, are dropped. The source file is never written. Pass the resulting string as the release's `notes:` for hosted publication.

‎docs/hosting/github_release.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ The optional `repository:` argument identifies the target as `'OWNER/REPO'`. It
1717

1818
Pass `latest: true` or `latest: false` to the constructor to set the latest-release policy during creation and metadata updates. Existing releases are compared with GitHub's latest release before changing that status. The default `nil` retains GitHub's automatic selection and does not change matching existing releases. Use `latest: false` for maintenance branches to avoid temporarily promoting an older release.
1919

20-
`publish!(release, package: nil, artifacts: [])` creates a release with tag and title `vVERSION`, using the numeric version from the [Release](../release.md) context. It verifies that the tag exists remotely and never creates a tag automatically. With `release.notes`, it supplies that nonempty body through a private temporary `--notes-file` and removes the file afterward; otherwise it retains GitHub's `--generate-notes`. It returns the release URL printed by `gh`.
20+
`publish!(release, package: nil, artifacts: [])` creates a release with tag and title `vVERSION`, using the numeric version from the [Release](../release.md) context. It verifies that the tag exists remotely and never creates a tag automatically. With `release.notes`, it supplies that nonempty body through a private temporary `--notes-file` and removes the file afterward; otherwise it retains GitHub's `--generate-notes`. The standard workflow supplies the released changelog section when the changelog can read it. It returns the release URL printed by `gh`.
2121

2222
## Package
2323

‎docs/usage.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,4 +195,4 @@ Source control objects manage release history independently of the repository's
195195

196196
Hosting objects publish release notes and attach package artifacts after the release tag is pushed. Set `hosting: nil` in the standard workflow, or omit the hosting publication call in custom callbacks, to disable hosted releases without disabling package publication.
197197

198-
- [`Hosting::GitHubRelease`](hosting/github_release.md): GitHub Releases with generated notes and the exact gem attached.
198+
- [`Hosting::GitHubRelease`](hosting/github_release.md): GitHub Releases with changelog or generated notes and the exact gem attached.

‎docs/workflow/ruby_gem.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ The optional `provider:` defaults to [`ExecutionProvider.current`](../execution_
3636

3737
## Hosting
3838

39-
The optional `hosting:` defaults to [`Hosting::GitHubRelease`](../hosting/github_release.md). Custom objects implement idempotent `publish!(release, package:)`. Set `hosting: nil` to disable hosting without disabling registry publication or Git.
39+
The optional `hosting:` defaults to [`Hosting::GitHubRelease`](../hosting/github_release.md). Custom objects implement idempotent `publish!(release, package:)`. When the changelog implements `notes(version)`, as the built-in formats do, the hosted release receives the released section as its notes, read before any publication so a missing or empty section fails before the gem is pushed. Releases that already carry notes, such as semantic releases, keep them; changelogs without `notes` and `changelog: nil` keep platform-generated notes. Set `hosting: nil` to disable hosting without disabling registry publication or Git.
4040

4141
## Install Tasks
4242

‎lib/ruby-gem-release/changelog/base.rb‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
require 'date'
44
require_relative '../markdown/source'
5+
require_relative 'notes'
56

67
module RubyGemRelease
78
module Changelog
@@ -29,6 +30,12 @@ def released?(version)
2930
matches.one?
3031
end
3132

33+
# Released section body with reference links expanded, for hosted release notes.
34+
def notes(version)
35+
validate_version(version)
36+
Notes.new(path: @path, heading: method(:release_pattern), expand_references: true).read(version)
37+
end
38+
3239
def prepare_next!(release)
3340
update_next(version: release.next_version, released_version: release.version)
3441
end

‎lib/ruby-gem-release/changelog/notes.rb‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ module Changelog
77
class Notes
88
include Markdown::Source
99

10+
DEFINITION = /\A {0,3}\[[^\]\r\n]+\]:[ \t]*\S[^\r\n]*\z/
11+
1012
def initialize(path: 'CHANGELOG.md', heading: nil, expand_references: false)
1113
@path = path
1214
@heading = heading || ->(version) { /\A\#{1,6} #{Regexp.escape(version)} \((?!Next\))[^\r\n]*\d[^\r\n]*\)\z/ }
@@ -21,11 +23,18 @@ def read(version)
2123
section = content[first...last]
2224
raise ArgumentError, "empty release notes in #{@path}" unless notes?(document(section))
2325

24-
@expand_references ? expanded_section(content, first, last).strip : section.strip
26+
@expand_references ? without_definitions(expanded_section(content, first, last)) : section.strip
2527
end
2628

2729
private
2830

31+
# Expanded notes no longer need link reference definitions; drops those trailing the section, as at the end of a file.
32+
def without_definitions(section)
33+
lines = section.strip.lines
34+
lines.pop while lines.any? && (lines.last.strip.empty? || DEFINITION.match?(lines.last.chomp))
35+
lines.join.strip
36+
end
37+
2938
def expanded_section(content, first, last)
3039
edits = section_edits(content, first, last)
3140
edits.reverse_each { |range, replacement| content[range] = replacement }

‎lib/ruby-gem-release/release.rb‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ def with_next_version(version)
2626
self.class.new(version: @version, gemspec_version: @gemspec_version, date: @date, next_version: version, notes: @notes)
2727
end
2828

29+
def with_notes(notes)
30+
self.class.new(version: @version, gemspec_version: @gemspec_version, date: @date, next_version: @next_version, notes: notes)
31+
end
32+
2933
private
3034

3135
def validate_metadata(date, notes)

0 commit comments

Comments
 (0)