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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Changelog

## 0.7.1 (Next)
## 0.8.0 (Next)

- [#79](https://github.com/dblock/ruby-gem-release/pull/79): Select the next development version part with `next_version: :minor` or `:major` on `Workflow::RubyGem` and `Workflow::SemanticRubyGem` - [@dblock](https://github.com/dblock).
- [#80](https://github.com/dblock/ruby-gem-release/pull/80): Skip posting empty Danger report comments - [@dblock](https://github.com/dblock).
- Your contribution here.

Expand Down
2 changes: 1 addition & 1 deletion DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Failure callbacks receive the failed phase, captured Ruby exception when availab

## Manual and Semantic Workflows

The manual workflow requires explicit version and changelog choices. Preparation honors an optional version selection; publication retains the initial version separately. After publication, the default bump increments patch, prepares the next changelog section, commits, pushes, and records the next version. `changelog: nil` and `hosting: nil` disable only those components.
The manual workflow requires explicit version and changelog choices. Preparation honors an optional version selection; publication retains the initial version separately. After publication, the default bump increments patch, or the part selected by `next_version:`, prepares the next changelog section, commits, pushes, and records the next version. `changelog: nil` and `hosting: nil` disable only those components.

Semantic releases are opt-in. Validation analyzes commits after the highest reachable stable release tag, records one immutable decision, and binds it to the captured head and explicit input. Later phases consume it without reanalysis. Versions do not derive from development versions; first release defaults to `1.0.0`, and explicit versions must exceed the last release. Generated notes reach the changelog and hosting unchanged.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ RubyGemRelease::Workflow::RubyGem.new(
).install_tasks
```

These defaults select the gemspec and repository, reject empty pending notes, prepare the changelog, publish to RubyGems and GitHub Releases, and increment the patch version for the next development iteration. Dates use UTC.
These defaults select the gemspec and repository, reject empty pending notes, prepare the changelog, publish to RubyGems and GitHub Releases, and increment the patch version for the next development iteration; pass `next_version: :minor` or `:major` to [increment another part](docs/workflow/ruby_gem.md#next-version). Dates use UTC.

### 2. Add the Release Workflow

Expand Down
2 changes: 1 addition & 1 deletion RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Availability depends on visibility and plan; verify these controls before relyin

Both interfaces require the default branch and a clean checkout after dependency installation. Ignore intentional dependency output such as `.bundle/config` or `vendor/bundle`; unexpected tracked, staged, or untracked non-ignored changes fail. Preparation stages trusted edits before testing; publication rejects subsequent changes rather than staging them.

The default manual workflow releases the checked-in version, or honors an explicit `version` input, then increments patch afterward. Semantic workflows select from release history and default to no development bump. Custom commands own their operations and must retain the [documented ordering and guards](docs/usage.md#custom-callbacks).
The default manual workflow releases the checked-in version, or honors an explicit `version` input, then increments patch afterward unless `next_version:` selects another part. Semantic workflows select from release history and default to no development bump. Custom commands own their operations and must retain the [documented ordering and guards](docs/usage.md#custom-callbacks).

Validate and build before authorizing a release:

Expand Down
2 changes: 1 addition & 1 deletion docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ RubyGemRelease::Workflow::RubyGem.new(
).install_tasks
```

This validates and prepares the release, publishes the verified gem, pushes the release commit and tag, creates the hosted release, and prepares the next patch version.
This validates and prepares the release, publishes the verified gem, pushes the release commit and tag, creates the hosted release, and prepares the next patch version, or the part selected by [`next_version:`](workflow/ruby_gem.md#next-version).

The default releases the checked-in version; optional `version` selects another through the version object's `set!`. The initial version remains in the context. Custom preparation callbacks own their file updates.

Expand Down
6 changes: 5 additions & 1 deletion docs/workflow/ruby_gem.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ Installs the standard Ruby gem release sequence through [`Tasks`](../tasks.md),

## Version

The required `version:` object implements `read`, `set!(value)`, and `increment!(from:)`; construction fails when any is missing. Bumps always calculate from `release.version`, so repetition writes the same next version. The default [`RubyConstant`](../version/ruby_constant.md) uses patch increments. The initial gemspec version remains `release.gemspec_version`.
The required `version:` object implements `read`, `set!(value)`, and `increment!(from:)`; construction fails when any is missing. Bumps always calculate from `release.version`, so repetition writes the same next version. The initial gemspec version remains `release.gemspec_version`.

## Next Version

The optional `next_version:` selects the part incremented for the next development iteration: `:patch` (default), `:minor`, or `:major`, as a Symbol or String. For example, `next_version: :minor` starts `1.3.0` after releasing `1.2.0` or `1.2.1`. The default calls `increment!(from:)` unchanged; other parts call `increment!(from:, part:)`, which [`RubyConstant`](../version/ruby_constant.md), [`PlainText`](../version/plain_text.md), and [`References`](../version/references.md) support. Construction rejects other values, and rejects `:minor` or `:major` when the version object's `increment!` does not accept `part:`, so an unsupported selection fails before publication.

## Changelog

Expand Down
2 changes: 1 addition & 1 deletion docs/workflow/semantic_ruby_gem.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ GitHub hosting passes frozen `release.notes` verbatim through a private file; ma

## Development Iterations

With default `bump: false`, the installed bump task does nothing and `release.next_version` stays `nil`. `bump: true` enables the standard patch increment, commit, and push. Future selection still uses released tags. Manual workflows continue to bump automatically.
With default `bump: false`, the installed bump task does nothing and `release.next_version` stays `nil`. `bump: true` enables the standard increment, commit, and push, using patch unless [`next_version:`](ruby_gem.md#next-version) selects another part. Future selection still uses released tags. Manual workflows continue to bump automatically.

## State and Callbacks

Expand Down
2 changes: 1 addition & 1 deletion lib/ruby-gem-release/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module RubyGemRelease
VERSION = '0.7.1'
VERSION = '0.8.0'
end
25 changes: 22 additions & 3 deletions lib/ruby-gem-release/workflow/ruby_gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ module Workflow
class RubyGem
include Lifecycle

NEXT_VERSIONS = %i[major minor patch].freeze

attr_reader :version, :changelog, :package, :destination, :git, :hosting, :provider

def initialize(version:, changelog:, provider: ExecutionProvider.current,
package: Package::RubyGem.new(gemspec: provider.fetch('GEMSPEC_PATH', provider.fetch('INPUT_GEMSPEC_PATH', '')) || '', directory: provider.directory),
destination: Destination::RubyGems.new,
git: SourceControl::Git.new(directory: provider.directory), hosting: Hosting::GitHubRelease.new,
validate: nil, success: nil, failure: nil)
@version = Version::Interface.check!(version)
validate: nil, success: nil, failure: nil, next_version: :patch)
configure_version!(version, next_version)
@changelog = changelog
@package = package
@destination = destination
Expand All @@ -37,6 +39,23 @@ def environment

private

def configure_version!(version, next_version)
@version = Version::Interface.check!(version)
part = next_version.to_sym if next_version.is_a?(String) || next_version.is_a?(Symbol)
raise ArgumentError, 'next_version must be :major, :minor, or :patch' unless NEXT_VERSIONS.include?(part)
raise ArgumentError, "version object's increment! must accept part: to use next_version: #{part.inspect}" unless part == :patch || increment_accepts_part?

@next_version = part
end

def increment_accepts_part?
@version.method(:increment!).parameters.any? { |type, name| %i[keyrest rest].include?(type) || (%i[key keyreq].include?(type) && name == :part) }
end

def increment_options
@next_version == :patch ? {} : { part: @next_version }
end

def install_callbacks(tasks)
tasks.validate { |ctx| validate_with_hooks(ctx) }
tasks.prepare { |ctx| prepare_release(ctx) }
Expand Down Expand Up @@ -89,7 +108,7 @@ def stage_next!(ctx)
next_ctx = ctx
@git.stage_changes! do
run_stage(:prepare_next, ctx, after_context: -> { next_ctx }) do
next_ctx = ctx.with(release: ctx.release.with_next_version(@version.increment!(from: ctx.release.version)))
next_ctx = ctx.with(release: ctx.release.with_next_version(@version.increment!(from: ctx.release.version, **increment_options)))
@changelog&.prepare_next!(next_ctx.release)
end
end
Expand Down
43 changes: 43 additions & 0 deletions spec/ruby_gem_release/workflow/ruby_gem_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'spec_helper'
require 'ruby-gem-release/workflow/ruby_gem'
require 'ruby-gem-release/changelog'
require 'ruby-gem-release/version/references'

RSpec.describe RubyGemRelease::Workflow::RubyGem do
let(:events) { [] }
Expand Down Expand Up @@ -91,6 +92,48 @@ def run_callbacks
expect(objects.fetch(:git)).to have_received(:commit_next!).twice
end

it 'increments the configured next version part from the release version', :aggregate_failures do
install(next_version: :minor)
Rake::Task['release:bump'].invoke
expect(version).to have_received(:increment!).with(from: '2.0.0', part: :minor)
expect(objects.fetch(:git)).to have_received(:commit_next!).with(having_attributes(next_version: '2.0.1'))
end

it 'accepts next version parts as strings' do
install(next_version: 'major')
Rake::Task['release:bump'].invoke
expect(version).to have_received(:increment!).with(from: '2.0.0', part: :major)
end

it 'rejects unknown next version parts at construction', :aggregate_failures do
[:build, nil, 1, ''].each do |next_version|
expect { described_class.new(version: version, changelog: nil, next_version: next_version) }
.to raise_error(ArgumentError, 'next_version must be :major, :minor, or :patch')
end
end

it 'requires custom version objects to accept part: only for non-patch next versions', :aggregate_failures do
custom = Class.new do
def read = '1.2.3'
def set!(value) = value
def increment!(from:) = from
end.new
expect { described_class.new(version: custom, changelog: nil, next_version: :minor) }
.to raise_error(ArgumentError, "version object's increment! must accept part: to use next_version: :minor")
expect { described_class.new(version: custom, changelog: nil) }.not_to raise_error
end

it 'writes the next minor version through a reference-updating Ruby constant' do
Dir.mktmpdir do |directory|
path = File.join(directory, 'version.rb')
File.write(path, "VERSION = '2.0.0'\n")
constant = RubyGemRelease::Version::RubyConstant.new(path: path, constant: 'VERSION')
described_class.new(version: RubyGemRelease::Version::References.new(version: constant, references: {}), changelog: nil, **objects.except(:changelog), next_version: :minor).install_tasks
Rake::Task['release:bump'].invoke
expect(File.read(path)).to eq("VERSION = '2.1.0'\n")
end
end

it 'rejects an Actions checkpoint without a configured workflow' do
RubyGemRelease::Tasks.install
expect { Rake::Task['release:workflow:checkpoint'].invoke }.to raise_error(/must implement checkpoint!/)
Expand Down
6 changes: 6 additions & 0 deletions spec/ruby_gem_release/workflow/semantic_ruby_gem_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ def invoke(*tasks)
expect(received).to have_attributes(analysis: have_attributes(version: '1.3.0'), release: have_attributes(version: '1.3.0', gemspec_version: '9.9.9', next_version: nil))
end

it 'bumps the configured next version part when bumping is enabled' do
install(bump: true, next_version: :minor)
invoke('validate', 'prepare', 'publish', 'bump')
expect(components.fetch(:version)).to have_received(:increment!).with(from: '1.3.0', part: :minor)
end

it 'optionally bumps and records the next development version without replacing analysis' do
received = nil
prepared = nil
Expand Down
Loading