Skip to content

Commit 9c9a726

Browse files
dblockclaude
andcommitted
Select the next development version part
Add `next_version:` to `Workflow::RubyGem` (and, through it, `Workflow::SemanticRubyGem`) to choose `:patch` (default), `:minor`, or `:major` for the next development iteration. The default call to `increment!(from:)` is unchanged; other parts pass `part:`, which is checked against the version object at construction so an unsupported selection fails before publication. Start 0.8.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011Gr21j6KD4oksnhmZ5u3pr
1 parent c435259 commit 9c9a726

11 files changed

Lines changed: 84 additions & 11 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Changelog
22

3-
## 0.7.1 (Next)
3+
## 0.8.0 (Next)
44

5+
- [#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).
56
- [#80](https://github.com/dblock/ruby-gem-release/pull/80): Skip posting empty Danger report comments - [@dblock](https://github.com/dblock).
67
- Your contribution here.
78

‎DESIGN.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Failure callbacks receive the failed phase, captured Ruby exception when availab
5454

5555
## Manual and Semantic Workflows
5656

57-
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.
57+
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.
5858

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

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ RubyGemRelease::Workflow::RubyGem.new(
2626
).install_tasks
2727
```
2828

29-
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.
29+
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.
3030

3131
### 2. Add the Release Workflow
3232

‎RELEASING.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Availability depends on visibility and plan; verify these controls before relyin
2727

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

30-
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).
30+
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).
3131

3232
Validate and build before authorizing a release:
3333

‎docs/usage.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ RubyGemRelease::Workflow::RubyGem.new(
3232
).install_tasks
3333
```
3434

35-
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.
35+
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).
3636

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

‎docs/workflow/ruby_gem.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ Installs the standard Ruby gem release sequence through [`Tasks`](../tasks.md),
44

55
## Version
66

7-
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`.
7+
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`.
8+
9+
## Next Version
10+
11+
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.
812

913
## Changelog
1014

‎docs/workflow/semantic_ruby_gem.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ GitHub hosting passes frozen `release.notes` verbatim through a private file; ma
6868

6969
## Development Iterations
7070

71-
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.
71+
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.
7272

7373
## State and Callbacks
7474

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module RubyGemRelease
4-
VERSION = '0.7.1'
4+
VERSION = '0.8.0'
55
end

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

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ module Workflow
1212
class RubyGem
1313
include Lifecycle
1414

15+
NEXT_VERSIONS = %i[major minor patch].freeze
16+
1517
attr_reader :version, :changelog, :package, :destination, :git, :hosting, :provider
1618

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

3840
private
3941

42+
def configure_version!(version, next_version)
43+
@version = Version::Interface.check!(version)
44+
part = next_version.to_sym if next_version.is_a?(String) || next_version.is_a?(Symbol)
45+
raise ArgumentError, 'next_version must be :major, :minor, or :patch' unless NEXT_VERSIONS.include?(part)
46+
raise ArgumentError, "version object's increment! must accept part: to use next_version: #{part.inspect}" unless part == :patch || increment_accepts_part?
47+
48+
@next_version = part
49+
end
50+
51+
def increment_accepts_part?
52+
@version.method(:increment!).parameters.any? { |type, name| %i[keyrest rest].include?(type) || (%i[key keyreq].include?(type) && name == :part) }
53+
end
54+
55+
def increment_options
56+
@next_version == :patch ? {} : { part: @next_version }
57+
end
58+
4059
def install_callbacks(tasks)
4160
tasks.validate { |ctx| validate_with_hooks(ctx) }
4261
tasks.prepare { |ctx| prepare_release(ctx) }
@@ -89,7 +108,7 @@ def stage_next!(ctx)
89108
next_ctx = ctx
90109
@git.stage_changes! do
91110
run_stage(:prepare_next, ctx, after_context: -> { next_ctx }) do
92-
next_ctx = ctx.with(release: ctx.release.with_next_version(@version.increment!(from: ctx.release.version)))
111+
next_ctx = ctx.with(release: ctx.release.with_next_version(@version.increment!(from: ctx.release.version, **increment_options)))
93112
@changelog&.prepare_next!(next_ctx.release)
94113
end
95114
end

‎spec/ruby_gem_release/workflow/ruby_gem_spec.rb‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require 'spec_helper'
44
require 'ruby-gem-release/workflow/ruby_gem'
55
require 'ruby-gem-release/changelog'
6+
require 'ruby-gem-release/version/references'
67

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

95+
it 'increments the configured next version part from the release version', :aggregate_failures do
96+
install(next_version: :minor)
97+
Rake::Task['release:bump'].invoke
98+
expect(version).to have_received(:increment!).with(from: '2.0.0', part: :minor)
99+
expect(objects.fetch(:git)).to have_received(:commit_next!).with(having_attributes(next_version: '2.0.1'))
100+
end
101+
102+
it 'accepts next version parts as strings' do
103+
install(next_version: 'major')
104+
Rake::Task['release:bump'].invoke
105+
expect(version).to have_received(:increment!).with(from: '2.0.0', part: :major)
106+
end
107+
108+
it 'rejects unknown next version parts at construction', :aggregate_failures do
109+
[:build, nil, 1, ''].each do |next_version|
110+
expect { described_class.new(version: version, changelog: nil, next_version: next_version) }
111+
.to raise_error(ArgumentError, 'next_version must be :major, :minor, or :patch')
112+
end
113+
end
114+
115+
it 'requires custom version objects to accept part: only for non-patch next versions', :aggregate_failures do
116+
custom = Class.new do
117+
def read = '1.2.3'
118+
def set!(value) = value
119+
def increment!(from:) = from
120+
end.new
121+
expect { described_class.new(version: custom, changelog: nil, next_version: :minor) }
122+
.to raise_error(ArgumentError, "version object's increment! must accept part: to use next_version: :minor")
123+
expect { described_class.new(version: custom, changelog: nil) }.not_to raise_error
124+
end
125+
126+
it 'writes the next minor version through a reference-updating Ruby constant' do
127+
Dir.mktmpdir do |directory|
128+
path = File.join(directory, 'version.rb')
129+
File.write(path, "VERSION = '2.0.0'\n")
130+
constant = RubyGemRelease::Version::RubyConstant.new(path: path, constant: 'VERSION')
131+
described_class.new(version: RubyGemRelease::Version::References.new(version: constant, references: {}), changelog: nil, **objects.except(:changelog), next_version: :minor).install_tasks
132+
Rake::Task['release:bump'].invoke
133+
expect(File.read(path)).to eq("VERSION = '2.1.0'\n")
134+
end
135+
end
136+
94137
it 'rejects an Actions checkpoint without a configured workflow' do
95138
RubyGemRelease::Tasks.install
96139
expect { Rake::Task['release:workflow:checkpoint'].invoke }.to raise_error(/must implement checkpoint!/)

0 commit comments

Comments
 (0)