Skip to content

About

Reusable GitHub Actions workflow and Ruby Rake tasks for gem releases

Topics

Resources

Contributing

Stars

3 stars

Watchers

0 watching

Forks

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

A faceted ruby gemstone with an upward release arrow

Ruby Gem Release

Gem Version Test Coverage Status

Release your Ruby gem from GitHub Actions without maintaining custom release scripts or storing a RubyGems API key.

Implements Releases as Code for Ruby gems. You start a GitHub Actions workflow, and it:

  • runs your tests,
  • publishes the gem to RubyGems,
  • updates the changelog (optional),
  • creates a Git tag and a GitHub Release,
  • bumps the version for the next development iteration.

See also npm-package-release and rust-crate-release.

You need Ruby 3.3+, GitHub Actions, and RubyGems Trusted Publishing.

Usage

1. Configure Your Gem

Add ruby-gem-release and commonmarker ~> 2.10 (needed only for Markdown changelogs) to your development dependencies. Then install the release tasks in your Rakefile, naming your version file and changelog format:

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_tasks

With these defaults, a release:

  • uses the only gemspec in the repository root,
  • fails if the changelog has no pending notes,
  • moves the pending notes under a new release heading,
  • publishes to RubyGems and GitHub Releases,
  • bumps the patch version afterwards (pass next_version: :minor or :major to bump another part),
  • dates the release in UTC.

If your Rakefile also installs the Bundler gem tasks, disable the local Bundler release tasks so nobody can publish around the workflow. See Bundler Release Tasks.

Every release starts by checking that the checkout is clean, and Ruby setup installs gems inside it. Add what it writes to .gitignore, leaving out the lockfile if you commit it:

/vendor/bundle/
/.bundle/
/Gemfile.lock

With a release Gemfile, ignore its lockfile instead, such as /gemfiles/release.gemfile.lock. A dry run fails and lists any lines that are missing.

2. Add the Release Workflow

Copy the sample workflow to .github/workflows/release.yml and set your Ruby version:

name: Release

on:
  workflow_dispatch:
    inputs:
      version:
        description: Optional release version overriding the checked-in version.
        type: string
        required: false
      rubygems-owner:
        description: RubyGems account ID for first publication; omit for an existing gem.
        type: string
        required: false

permissions:
  contents: write
  id-token: write

jobs:
  release:
    uses: dblock/ruby-gem-release/.github/workflows/release.yml@v0.9.0
    with:
      ruby-version: '3.3'
      version: ${{ inputs.version }}
      rubygems-owner: ${{ inputs.rubygems-owner }}

3. Enable Trusted Publishing

Trusted Publishing lets GitHub Actions publish to RubyGems without a stored API key.

  1. In your GitHub repository, open Settings → Environments and create an environment named release. Or run gh api --method PUT repos/{owner}/{repo}/environments/release from your repository directory.
  2. On RubyGems, open the pending trusted publishers page for a new gem, or your gem's Trusted publishers page (for example https://rubygems.org/gems/example/trusted_publishers) for an existing gem.
  3. Create a trusted publisher with your gem's repository, workflow filename release.yml, and environment release.
  4. Set the separate workflow repository fields to dblock and ruby-gem-release. This tells RubyGems to trust this project's reusable workflow.

To check the setup without releasing, run a dry run.

Anyone with write access can now dispatch a release, without admin access or RubyGems credentials. The release environment alone restricts nothing. To require approval from a maintainer, configure required reviewers and deployment branches.

4. Make a Release

Your branch rules must allow the workflow to push release commits and tags (branch permissions); each release checks this before publishing. Run your tests, review the changes, then dispatch from your default branch. Dispatching starts a real release; with required reviewers, it waits for approval.

Do not merge into the default branch while a release runs. If that happens, see recovery.

First release: pass your numeric RubyGems account ID, shown on the Pending Trusted Publishers page, as rubygems-owner. This account will own the new gem:

gh workflow run release.yml -f rubygems-owner=YOUR_ACCOUNT_ID

Later releases: omit rubygems-owner. The trusted publisher is still required:

gh workflow run release.yml

To release a different version, enter it in the dispatch form or pass -f version=1.2.3. The workflow writes it to your version file, and the next development version is bumped from it.

For a real-world example of adding this to an existing gem, see ruby-link-checker #26.

Extending the Workflow

Replace only what you need. See the standard workflow and Detailed Usage for examples.

For complete examples, see releasing ruby-gem-release itself and GitLab and semantic releases.

The defaults include clean-checkout checks, duplicate-version checks, and preserved recovery artifacts. Custom publication callbacks must keep the documented order and artifact checks.

Upgrading

See UPGRADING.md for breaking changes and migration steps. Upgrade the gem and pinned workflow or action together.

Contributing

See CONTRIBUTING.md, DESIGN.md, CHANGELOG.md, and RELEASING.md.

License

Distributed under the MIT License.

About

Reusable GitHub Actions workflow and Ruby Rake tasks for gem releases

Topics

Resources

Contributing

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages