|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: Setting up a gem for publication |
| 4 | +date: 2025-08-13 |
| 5 | +summary: Steps to do to enable publication of a new gem |
| 6 | +--- |
| 7 | + |
| 8 | +Those are the steps you have to take to publish a new gem: |
| 9 | + |
| 10 | + |
| 11 | +## Setup GitHub workflow |
| 12 | + |
| 13 | +Right now we don't have a way to sync workflows for each gem. |
| 14 | +Copy the [release workflow](https://github.com/voxpupuli/gem-workflow-test/blob/master/.github/workflows/release.yml) from our [boilerplate gem](https://github.com/voxpupuli/gem-workflow-test). |
| 15 | +This workflow will take care of: |
| 16 | + |
| 17 | +* Building the gem |
| 18 | +* Creating a GitHub and rubygems.org release |
| 19 | +* Attaching the gem to the GitHub release |
| 20 | +* Creating the changelog for the GitHub release |
| 21 | +* Waits until the new version is present on the rubygems.org cache |
| 22 | + |
| 23 | +### Configure rubygems.org |
| 24 | + |
| 25 | +**This needs to be done by a PMC member** |
| 26 | + |
| 27 | +Before the first release, trusted publishing needs to be configured on rubygems.org |
| 28 | + |
| 29 | +* login to rubygems.org with the voxpupui or openvoxproject account from gopass |
| 30 | +* go to https://rubygems.org/profile/oidc/pending_trusted_publishers |
| 31 | +* click "create" |
| 32 | +* add gem name, repo owner ("voxpupuli" or "OpenVoxProject"), repo name (usually same as gem name), workflow name (`release.yml`) |
| 33 | +* Set environment to `release` ([configured in our workflow](https://github.com/voxpupuli/gem-workflow-test/blob/96a29ada7ddea2ba0f27cbe0efd2194c7b9e7213/.github/workflows/release.yml#L71)) |
| 34 | + |
| 35 | +This step has to be done at maximum 48h before the first release, or rubygems.org deletes the configuration |
| 36 | +The configuratin can be added again if rubygems.org deleted it. |
| 37 | + |
| 38 | +## Setup the GitHub Changelog configuration |
| 39 | + |
| 40 | +Copy the [config yaml](https://github.com/voxpupuli/gem-workflow-test/blob/master/.github/release.yml). |
| 41 | +This will ensure that all closed issues and PRs with labels are sorted into the correct categories. |
| 42 | + |
| 43 | +## Recommendations |
| 44 | + |
| 45 | +### dependabot |
| 46 | + |
| 47 | +We have a basic [dependabot config](https://github.com/voxpupuli/gem-workflow-test/blob/master/.github/dependabot.yml). |
| 48 | +It will raise PRs for updates on Ruby dependencies or github action dependencies. |
| 49 | +We highly recommend that you copy the file. |
| 50 | + |
| 51 | +### Gemfile |
| 52 | + |
| 53 | +We recommend that the Gemfile contains a `release` gem group: |
| 54 | + |
| 55 | +```ruby |
| 56 | +group :release, optional: true do |
| 57 | + gem 'faraday-retry', '~> 2.1', require: false |
| 58 | + gem 'github_changelog_generator', '~> 1.16.4', require: false |
| 59 | +end |
| 60 | +``` |
| 61 | + |
| 62 | +### Rakefile |
| 63 | + |
| 64 | +With the `changelog` rake task, you can follow our [release documentation](https://voxpupuli.org/docs/releasing_gem/). |
| 65 | +Put the following in a Rakefile (adjust the `config.project` value): |
| 66 | + |
| 67 | +```ruby |
| 68 | +begin |
| 69 | + require 'rubygems' |
| 70 | + require 'github_changelog_generator/task' |
| 71 | +rescue LoadError |
| 72 | +else |
| 73 | + GitHubChangelogGenerator::RakeTask.new :changelog do |config| |
| 74 | + config.exclude_labels = %w[duplicate question invalid wontfix wont-fix skip-changelog dependencies] |
| 75 | + config.user = 'voxpupuli' |
| 76 | + config.project = 'json-schema' |
| 77 | + gem_version = Gem::Specification.load("#{config.project}.gemspec").version |
| 78 | + config.future_release = "#{gem_version}" |
| 79 | + end |
| 80 | +end |
| 81 | +``` |
0 commit comments