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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 0.9.1 (Next)

- [#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).
- Your contribution here.

## 0.9.0 (2026/11/20)
Expand Down
2 changes: 1 addition & 1 deletion RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Rerun with the same source commit and inputs, including the release date. Each t

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.

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.
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.

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.

Expand Down
4 changes: 4 additions & 0 deletions docs/changelog/base.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ Default validation requires an existing selected release or pending notes; other

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.

## Notes

`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.

## Prepare Next

`prepare_next!(release)` delegates the released version and the version for the next development iteration to the concrete format implementation.
Expand Down
2 changes: 1 addition & 1 deletion docs/changelog/notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ notes = RubyGemRelease::Changelog::Notes.new(

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.

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.
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.
2 changes: 1 addition & 1 deletion docs/hosting/github_release.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The optional `repository:` argument identifies the target as `'OWNER/REPO'`. It

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.

`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`.
`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`.

## Package

Expand Down
2 changes: 1 addition & 1 deletion docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,4 @@ Source control objects manage release history independently of the repository's

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.

- [`Hosting::GitHubRelease`](hosting/github_release.md): GitHub Releases with generated notes and the exact gem attached.
- [`Hosting::GitHubRelease`](hosting/github_release.md): GitHub Releases with changelog or generated notes and the exact gem attached.
2 changes: 1 addition & 1 deletion docs/workflow/ruby_gem.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ The optional `provider:` defaults to [`ExecutionProvider.current`](../execution_

## Hosting

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.
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.

## Install Tasks

Expand Down
7 changes: 7 additions & 0 deletions lib/ruby-gem-release/changelog/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require 'date'
require_relative '../markdown/source'
require_relative 'notes'

module RubyGemRelease
module Changelog
Expand Down Expand Up @@ -29,6 +30,12 @@ def released?(version)
matches.one?
end

# Released section body with reference links expanded, for hosted release notes.
def notes(version)
validate_version(version)
Notes.new(path: @path, heading: method(:release_pattern), expand_references: true).read(version)
end

def prepare_next!(release)
update_next(version: release.next_version, released_version: release.version)
end
Expand Down
11 changes: 10 additions & 1 deletion lib/ruby-gem-release/changelog/notes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ module Changelog
class Notes
include Markdown::Source

DEFINITION = /\A {0,3}\[[^\]\r\n]+\]:[ \t]*\S[^\r\n]*\z/

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

@expand_references ? expanded_section(content, first, last).strip : section.strip
@expand_references ? without_definitions(expanded_section(content, first, last)) : section.strip
end

private

# Expanded notes no longer need link reference definitions; drops those trailing the section, as at the end of a file.
def without_definitions(section)
lines = section.strip.lines
lines.pop while lines.any? && (lines.last.strip.empty? || DEFINITION.match?(lines.last.chomp))
lines.join.strip
end

def expanded_section(content, first, last)
edits = section_edits(content, first, last)
edits.reverse_each { |range, replacement| content[range] = replacement }
Expand Down
4 changes: 4 additions & 0 deletions lib/ruby-gem-release/release.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ def with_next_version(version)
self.class.new(version: @version, gemspec_version: @gemspec_version, date: @date, next_version: version, notes: @notes)
end

def with_notes(notes)
self.class.new(version: @version, gemspec_version: @gemspec_version, date: @date, next_version: @next_version, notes: notes)
end

private

def validate_metadata(date, notes)
Expand Down
10 changes: 9 additions & 1 deletion lib/ruby-gem-release/workflow/ruby_gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,18 @@ def prepare_publication(ctx)
end

def publish(ctx)
hosted = hosted_release(ctx.release) if @hosting
prepare_publication(ctx)
run_stage(:publish_registry, ctx) { @destination.publish!(ctx.release, package: @package) }
run_stage(:push_release, ctx) { @git.push!(ctx.release) }
run_stage(:publish_hosted_release, ctx) { @hosting.publish!(ctx.release, package: @package) } if @hosting
run_stage(:publish_hosted_release, ctx) { @hosting.publish!(hosted, package: @package) } if @hosting
end

# Reads changelog notes before any publication, so a missing section fails before the gem is pushed.
def hosted_release(release)
return release if release.notes || !@changelog.respond_to?(:notes)

release.with_notes(@changelog.notes(release.version))
end

def prepare_next(ctx)
Expand Down
12 changes: 7 additions & 5 deletions spec/fixtures/github_release_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -319,11 +319,13 @@ def validation_command
expect(run_git('-C', checkout, 'status', '--porcelain')).to eq('')
artifact = File.join(directory, 'example-0.1.0.gem')
publications = File.readlines(File.join(directory, 'publication.jsonl')).map { |line| JSON.parse(line) }
expect(publications).to eq([
[Gem.ruby, '-S', 'gem', 'push', artifact],
['gh', 'release', 'create', 'v0.1.0', '--repo', 'owner/example', '--verify-tag',
'--title', 'v0.1.0', '--generate-notes', artifact]
])
expect(publications).to match([
[Gem.ruby, '-S', 'gem', 'push', artifact],
['gh', 'release', 'create', 'v0.1.0', '--repo', 'owner/example', '--verify-tag',
'--title', 'v0.1.0', '--notes-file', a_string_ending_with('.md'), artifact]
])
hosted = JSON.parse(File.read(File.join(environment.fetch('RELEASE_TEST_SERVICE_DIRECTORY'), 'hosting.json')))
expect(hosted.fetch('body')).to eq("### Added\n\n- Initial functionality.")
end
end

Expand Down
10 changes: 10 additions & 0 deletions spec/ruby_gem_release/changelog/intridea_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,14 @@
File.write(path, "### 1.0.0 (2026/11/07)\n\n- Change.\n\n### 1.0.0 (2026-11-07)\n\n- Change.\n")
expect { described_class.new(path: path).released?('1.0.0') }.to raise_error(ArgumentError, /duplicate release headings/)
end

describe '#notes' do
it 'reads a released section with reference links expanded and rejects unreleased or invalid versions', :aggregate_failures do
File.write(path, "# Changelog\n\n## 1.3.0 (Next)\n\n- Your contribution here.\n\n## 1.2.3 (2026/11/07)\n\n- [#1][pr]: Fix.\n\n## 1.2.2 (2026/11/06)\n\n- Older.\n\n[pr]: https://example.com/pull/1\n")
changelog = described_class.new(path: path)
expect(changelog.notes('1.2.3')).to eq('- [#1](<https://example.com/pull/1>): Fix.')
expect { changelog.notes('1.3.0') }.to raise_error(ArgumentError)
expect { changelog.notes('1.2') }.to raise_error(ArgumentError, /invalid version/)
end
end
end
8 changes: 8 additions & 0 deletions spec/ruby_gem_release/changelog/keep_a_changelog_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,12 @@
expect { described_class.new(path: path).release!(release) }.to raise_error(ArgumentError, /duplicate/)
expect(File.read(path)).to eq(content)
end

describe '#notes' do
it 'reads the newest released section without the file-level comparison links' do
File.write(path, "# Changelog\n\n## [Unreleased]\n\n## [1.2.3] - 2026-11-07\n\n### Fixed\n\n- Fix.\n\n" \
"[Unreleased]: https://example.com/compare/v1.2.3...HEAD\n[1.2.3]: https://example.com/compare/v1.2.2...v1.2.3\n")
expect(described_class.new(path: path).notes('1.2.3')).to eq("### Fixed\n\n- Fix.")
end
end
end
7 changes: 7 additions & 0 deletions spec/ruby_gem_release/changelog/notes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,11 @@
File.write(path, "## 1.2.3 (2026/11/07)\n\n### Changes\n\n<!-- comment -->\n")
expect { reader.read('1.2.3') }.to raise_error(ArgumentError, /empty release notes/)
end

it 'drops link definitions trailing an expanded section but keeps them otherwise' do
content = "## 1.0.0 (2026/11/07)\n\n- [Fix][1].\n\n[1]: https://example.com/1\n[Unreleased]: https://example.com/compare\n"
File.write(path, content)
expect(described_class.new(path: path, expand_references: true).read('1.0.0')).to eq('- [Fix](<https://example.com/1>).')
expect(described_class.new(path: path).read('1.0.0')).to eq("- [Fix][1].\n\n[1]: https://example.com/1\n[Unreleased]: https://example.com/compare")
end
end
31 changes: 31 additions & 0 deletions spec/ruby_gem_release/workflow/ruby_gem_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,37 @@ def run_callbacks
%w[validate prepare publish bump].each { |phase| Rake::Task["release:#{phase}"].invoke }
end

it 'publishes the released changelog section as hosted release notes, read before any publication', :aggregate_failures do
allow(objects.fetch(:changelog)).to receive(:notes).with('2.0.0') do
events << %i[changelog notes]
'- Released notes.'
end
install
Rake::Task['release:publish'].invoke
expect(events.index(%i[changelog notes])).to be < events.index(%i[destination publish!])
expect(objects.fetch(:destination)).to have_received(:publish!).with(have_attributes(notes: nil), package: objects.fetch(:package))
expect(objects.fetch(:hosting)).to have_received(:publish!).with(have_attributes(version: '2.0.0', notes: '- Released notes.'), package: objects.fetch(:package))
end

it 'fails before publishing anything when the released changelog section cannot be read' do
allow(objects.fetch(:changelog)).to receive(:notes).and_raise(ArgumentError, 'empty release notes in CHANGELOG.md')
install
expect { Rake::Task['release:publish'].invoke }.to raise_error(ArgumentError, /empty release notes/)
expect(objects.fetch(:destination)).not_to have_received(:publish!)
expect(objects.fetch(:git)).not_to have_received(:commit!)
end

it 'keeps platform-generated notes for changelogs without readable notes and skips reading without hosting', :aggregate_failures do
install
Rake::Task['release:publish'].invoke
expect(objects.fetch(:hosting)).to have_received(:publish!).with(have_attributes(notes: nil), package: objects.fetch(:package))
Rake.application = Rake::Application.new
allow(objects.fetch(:changelog)).to receive(:notes)
install(hosting: nil)
Rake::Task['release:publish'].invoke
expect(objects.fetch(:changelog)).not_to have_received(:notes)
end

it 'rejects empty pending notes without invoking release operations' do
allow(objects.fetch(:changelog)).to receive(:pending?).and_return(false)
install
Expand Down
Loading