From 9c9a7266f2fe9e600247b533dd3828fa7acaa817 Mon Sep 17 00:00:00 2001 From: "Daniel (dB.) Doubrovkine" Date: Fri, 20 Nov 2026 16:08:07 -0500 Subject: [PATCH] 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 Claude-Session: https://claude.ai/code/session_011Gr21j6KD4oksnhmZ5u3pr --- CHANGELOG.md | 3 +- DESIGN.md | 2 +- README.md | 2 +- RELEASING.md | 2 +- docs/usage.md | 2 +- docs/workflow/ruby_gem.md | 6 ++- docs/workflow/semantic_ruby_gem.md | 2 +- lib/ruby-gem-release/version.rb | 2 +- lib/ruby-gem-release/workflow/ruby_gem.rb | 25 +++++++++-- .../workflow/ruby_gem_spec.rb | 43 +++++++++++++++++++ .../workflow/semantic_ruby_gem_spec.rb | 6 +++ 11 files changed, 84 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f73799..1c39753 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/DESIGN.md b/DESIGN.md index 24b751f..f593b4d 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -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. diff --git a/README.md b/README.md index 8516ca8..280f756 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/RELEASING.md b/RELEASING.md index 1211126..55aaa08 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -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: diff --git a/docs/usage.md b/docs/usage.md index e0a024f..5a7c7c0 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -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. diff --git a/docs/workflow/ruby_gem.md b/docs/workflow/ruby_gem.md index fb37fef..4325f8a 100644 --- a/docs/workflow/ruby_gem.md +++ b/docs/workflow/ruby_gem.md @@ -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 diff --git a/docs/workflow/semantic_ruby_gem.md b/docs/workflow/semantic_ruby_gem.md index f08a2f3..d584b79 100644 --- a/docs/workflow/semantic_ruby_gem.md +++ b/docs/workflow/semantic_ruby_gem.md @@ -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 diff --git a/lib/ruby-gem-release/version.rb b/lib/ruby-gem-release/version.rb index 8a7661b..1ecf89b 100644 --- a/lib/ruby-gem-release/version.rb +++ b/lib/ruby-gem-release/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module RubyGemRelease - VERSION = '0.7.1' + VERSION = '0.8.0' end diff --git a/lib/ruby-gem-release/workflow/ruby_gem.rb b/lib/ruby-gem-release/workflow/ruby_gem.rb index 57e9703..9091aba 100644 --- a/lib/ruby-gem-release/workflow/ruby_gem.rb +++ b/lib/ruby-gem-release/workflow/ruby_gem.rb @@ -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 @@ -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) } @@ -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 diff --git a/spec/ruby_gem_release/workflow/ruby_gem_spec.rb b/spec/ruby_gem_release/workflow/ruby_gem_spec.rb index 46f742f..4ca4f6d 100644 --- a/spec/ruby_gem_release/workflow/ruby_gem_spec.rb +++ b/spec/ruby_gem_release/workflow/ruby_gem_spec.rb @@ -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) { [] } @@ -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!/) diff --git a/spec/ruby_gem_release/workflow/semantic_ruby_gem_spec.rb b/spec/ruby_gem_release/workflow/semantic_ruby_gem_spec.rb index 9045033..ad4ba9a 100644 --- a/spec/ruby_gem_release/workflow/semantic_ruby_gem_spec.rb +++ b/spec/ruby_gem_release/workflow/semantic_ruby_gem_spec.rb @@ -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