Use the standard workflow, or custom callbacks for different release steps. Both use the same Actions interface. Install the tasks only once.
To publish an existing signed tag whose changes are already reviewed and merged, use the reviewed workflow. It makes no commits, tags, pushes, or version bumps, and supports stable branches and package collections.
For a version file such as lib/example/version.rb:
# frozen_string_literal: true
module Example
VERSION = '0.1.0'
endPick the changelog class that matches your format: KeepAChangelog for this sample, or Intridea for Next headings. Neither is guessed.
Add ruby-gem-release and commonmarker ~> 2.10 (only needed for Markdown changelogs) to your development dependencies. On JRuby, use changelog: nil or your own changelog class:
require 'ruby-gem-release/workflow/ruby_gem'
require 'ruby-gem-release/changelog'
RubyGemRelease::Workflow::RubyGem.new(
version: RubyGemRelease::Version::RubyConstant.new(path: 'lib/example/version.rb', constant: 'VERSION'),
changelog: RubyGemRelease::Changelog::KeepAChangelog.new
).install_tasksA release validates, updates the version file and changelog, publishes the gem, pushes the release commit and tag, creates the GitHub Release, and bumps the patch version (or the part set by next_version:).
It releases the checked-in version unless you pass the optional version input, which is written with the version object's set!. The context keeps the original version. Custom preparation callbacks must update files themselves.
Validation. Before any edits, release:validate fails unless the changelog has pending notes or already has a heading for this version, even with an explicit version. To replace it, pass a validate: lambda that raises (or returns false) on failure. Without a changelog, validation passes.
Notifications. Pass optional success: and failure: lambdas to Workflow::RubyGem.new. success gets the execution context after the next development version is pushed. failure gets a RubyGemRelease::ReleaseFailure with the failed phase, the error when available, and the execution context.
Hooks. Use lifecycle hooks to add checks or file edits. Edits made by preparation hooks go into the release commit; see the example.
Defaults. The gem is built from GEMSPEC_PATH or the only gemspec in the root. The repository, branch, and artifact directory come from the checkout and workflow. Missing or ambiguous choices fail.
Testing. The optional ruby-gem-release/rspec helpers run the real workflow in a throwaway repository, so you can check the commits and files your customizations produce. See Testing Custom Workflows.
bundler/gem_tasks and Bundler::GemHelper.install_tasks add a rake release task that builds, tags, pushes, and publishes from your machine with your own RubyGems credentials. Its helpers release:rubygem_push and release:source_control_push can also be run directly. To make the workflow the only way to release, replace all three after Bundler installs them:
%w[release release:rubygem_push release:source_control_push].each do |name|
Rake::Task[name].clear
task(name) { abort "#{name} is disabled; releases run through GitHub Actions" }
endclear also removes their prerequisites, so nothing is built or tagged before the task aborts. The Bundler build and install tasks still work, and this gem's release:* tasks are unaffected.
You can replace package:, destination:, git:, hosting:, or provider: and keep the same steps. For example, turn off GitHub Releases but keep publishing to RubyGems:
RubyGemRelease::Workflow::RubyGem.new(
version: RubyGemRelease::Version::RubyConstant.new(path: 'lib/example/version.rb', constant: 'VERSION'),
changelog: RubyGemRelease::Changelog::KeepAChangelog.new,
hosting: nil
).install_tasksWithout a changelog, set changelog: nil; version bumps and publication still run. Both version: and changelog: are required, even when the changelog is nil.
Write callbacks only when you need different release steps; for smaller changes, use lifecycle hooks. Keep this order: it ensures the published gem is the one that was built and checked, catches concurrent changes, and publishes the gem before the tag:
require 'ruby-gem-release/workflow/ruby_gem'
require 'ruby-gem-release/changelog'
require 'ruby-gem-release/hosting/github_release'
require 'ruby-gem-release/package/ruby_gem'
require 'ruby-gem-release/destination/ruby_gems'
require 'ruby-gem-release/source_control/git'
provider = RubyGemRelease::ExecutionProvider.current
package = RubyGemRelease::Package::RubyGem.new(directory: provider.directory)
destination = RubyGemRelease::Destination::RubyGems.new
version = RubyGemRelease::Version::RubyConstant.new(path: 'lib/example/version.rb', constant: 'VERSION')
changelog = RubyGemRelease::Changelog::KeepAChangelog.new
git = RubyGemRelease::SourceControl::Git.new(directory: provider.directory)
github = RubyGemRelease::Hosting::GitHubRelease.new
workflow = RubyGemRelease::Workflow::RubyGem.new(version: version, changelog: changelog, package: package, destination: destination,
git: git, hosting: github, provider: provider)
RubyGemRelease::Tasks.install(workflow: workflow, package: package, destination: destination, provider: provider) do |tasks|
tasks.validate { |ctx| changelog.released?(ctx.release.version) || changelog.pending? }
tasks.prepare do |ctx|
release = ctx.release
git.stage_changes! do
version.set!(release.version) unless provider.fetch('INPUT_VERSION', '').empty?
changelog.release!(release.with_version(version.read))
end
end
tasks.publish do |ctx|
release = ctx.release
workflow.checkpoint!(ctx)
destination.publish!(release, package: package)
git.push!(release)
github.publish!(release, package: package)
end
tasks.bump do |ctx|
release = ctx.release
next_release = nil
git.stage_changes! do
next_release = release.with_next_version(version.increment!(from: release.version))
changelog.prepare_next!(next_release)
end
git.commit_next!(next_release)
git.push!
ctx.record_next_version!(next_release.next_version)
end
tasks.success { |ctx| puts "Published #{ctx.release.version}" }
tasks.failure do |failure|
version = failure.context.release&.version || 'version unavailable'
error = failure.error&.original_class || 'details unavailable'
warn "Release failed during #{failure.phase} for #{version}: #{error}"
end
end- Callbacks receive an
ExecutionContextwith an immutableRelease; version changes return a copy. Tasksdoes not edit files; your callbacks do.- Call
record_next_version!only after the next-version commit is pushed. - Wrap preparation edits in
git.stage_changes!. Files changed by a custompreparecommand are staged before tests run. - Publication never stages files; later changes fail the release instead of entering the commit.
- Pass
workflow:sorelease:workflow:checkpointcan build and preserve artifacts before publication. - Each publishing task checks its own result. On a rerun, an existing gem counts as published only if its checksum matches. See reruns.
Follow Usage to set up and dispatch a release. The workflow reference lists every input, default, and command override.
Dispatching publishes unless validation fails. Custom commands must be safe to rerun with the same checkout and inputs (reruns). Never overwrite a published version or move a release tag.
Set the gemspec, version, Ruby version, commands, and commit author under with:. Pin a release or commit, not master.
- Release Workflow: All inputs, defaults, permissions, commands, and recovery artifacts.
Workflow::Environment: Records release settings at the start and checks the prepared version.Workflow::RubyGemsCredentials: RubyGems Trusted Publishing login, with an optional owner ID for a gem's first release.
Standard workflows run the usual steps with your version and changelog objects. You can swap the package, Git, or hosting objects.
Workflow::RubyGem: Prepares, publishes, and bumps the version, with safe defaults.Workflow::SemanticRubyGem: Picks versions and writes notes from Conventional Commits and past releases.
Version objects read, set, and bump the version in your project files. For other formats, write your own object with read, set!(value), and increment!(from:).
Version::RubyConstant: A numeric version in a Ruby constant, updated without running the file.Version::PlainText: A numeric version in a plain text file, such asVERSION.Version::References: Wraps another version object and also updates version references in other files, such as README pins, to the released version during the next development bump.
Callbacks do the release work. The standard workflow installs them; Custom Callbacks shows how to set them up by hand. An unregistered callback does nothing, and an exception fails the task. Callback code runs with release credentials, so it must be trusted.
Tasks: Registers callbacks and their Rake tasks.ExecutionContext: Release data, current and previous steps, the workflow, and run details.ExecutionProvider: Access to the CI platform, with a GitHub Actions implementation and a generic base.Release: The immutable version and date of a release.
Changelog objects add the release heading and open a section for the next version, leaving the rest of the file unchanged.
Changelog::KeepAChangelog: Unreleased sections and version comparison references.Changelog::Intridea: Next sections and a configured contribution placeholder.Changelog::Base: Shared base class for the formats above.Changelog::Generated: Dated sections from notes generated by semantic releases.
Package objects build and verify the gem; destinations publish it.
Package::RubyGem: Reads gem metadata, builds the gem, and verifies it.
Destinations publish the built gem to a registry. The default is RubyGems. A custom destination brings its own version checks, uploads, and credentials.
Destination: The base class for registries, including how they log in.Destination::RubyGems: Checks whether a version exists on RubyGems and publishes the exact built gem.
Source control objects create release commits and tags, whatever service hosts the repository.
SourceControl::Git: Release and next-version commits, tags, recovery bundles, branch checks, and all-or-nothing pushes.
Hosting objects create a release page with notes and the gem after the tag is pushed. To turn this off, set hosting: nil, or leave out the hosting call in custom callbacks.
Hosting::GitHubRelease: A GitHub Release with changelog or generated notes and the exact gem attached.