Automatic release Ruby gems with Github CI

# ruby
18 May 2025
39 views

Intro

I've created a bunch of gems for API interactions recently and usually on finishing some work you'd like to have a new release of the tool. It's quite tedious process especially when you want to release often. Here are the steps you need to follow to get stuff done.

  1. Update version.rb file inside the gem

  2. Run bundle install

  3. Commit all the changes

  4. Update the CHANGELOG.md

  5. Build artifacts

  6. Create and push new tag

  7. Push new version to Rubygems

  8. Create a new release on Github with all the notes

  9. etc...

There are some gems like gem-release that can help you with part of these steps but I'd prefer to do it all automatically and not to mess around with bunch of tools but with one only. OK, let's go!

Prepare the repo

We'll use release-please Github workflow to achieve our goals. It automatically creates releases and tags for repo and builds changelog in a beautiful manner. To publish the gem to Rubygems we'll take rubygems/release-gem

Create .github/workflow/release.yml file with following content. Change the default branch and ruby version according to your project. 

name: Release

on:
  push:
    branches:
      - master

permissions:
  contents: write
  id-token: write
  pull-requests: write

jobs:
  release:
    runs-on: ubuntu-latest

    steps:
      - name: Release Please
        uses: googleapis/release-please-action@v4
        id: release
        with:
          token: ${{ secrets.GH_TOKEN }}

      - uses: actions/checkout@v4
        if: ${{ steps.release.outputs.release_created }}
        with:
          fetch-tags: true

      - name: Set up Ruby
        uses: ruby/setup-ruby@v1
        if: ${{ steps.release.outputs.release_created }}
        with:
          bundler-cache: true
          ruby-version: 3.4

      - uses: rubygems/release-gem@v1
        if: ${{ steps.release.outputs.release_created }}

release-please requires Github token to trigger all the necessary workflows so go to https://github.com/settings/tokens and create a new classic token and put it under the secrets in the repository with name GH_TOKEN 

To be able to create new releases on Rubygems you need to create a Trusted Publisher. It allows you not to pass any credentials between Github and Rubygems, no need to create any access token, etc. So go to https://rubygems.org/profile/oidc/pending_trusted_publishers/new and create a new one for the repo. 

Add release-please-config.json to the root of the project, change package-name and version-filepath.

{
  "packages": {
    ".": {
      "package-name": "taboola_api",
      "include-component-in-tag": false,
      "changelog-path": "CHANGELOG.md",
      "release-type": "ruby",
      "bump-minor-pre-major": true,
      "bump-patch-for-minor-pre-major": true,
      "draft": false,
      "prerelease": false,
      "version-file": "lib/taboola_api/version.rb"
    }
  },
  "$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json"
}

If your gem was already published you can specify the release version under .release-please-manifest.json file. If not just put the initial version in it.

{
  ".": "0.1.0"
}

That's it! Now go and examine https://www.conventionalcommits.org/en/v1.0.0/#summary because release-please use theirs conventions to group changes inside the CHANGELOG.md

Take a look at https://github.com/k0va1/taboola_api gem for full setup.

Links