Skip to content

Commit 5f46427

Browse files
committed
chore(ci): add automated gem release
1 parent de9e726 commit 5f46427

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

.github/workflows/publish.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Publish Gems
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
publish:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- name: Setup Ruby
14+
uses: ruby/setup-ruby@v1
15+
with:
16+
ruby-version: '3.2'
17+
- name: Install dependencies
18+
run: bundle install --jobs 4 --retry 3
19+
- name: Setup just
20+
uses: extractions/setup-just@v1
21+
- name: Publish gems
22+
env:
23+
GEM_HOST_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
24+
run: ruby scripts/publish_gems.rb

MAINTAINERS.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,23 @@ packages can be used interchangeably.
120120

121121
All the above steps are automated by `scripts/publish_gems.rb` which
122122
builds and publishes the pure Ruby gem and all native variants.
123+
124+
### Automated publishing via GitHub Actions
125+
126+
Gems are published automatically when a tag matching `v<version>` is
127+
pushed. The workflow defined in `.github/workflows/publish.yml` checks
128+
that the tag version equals the versions in both gemspecs and then runs
129+
`scripts/publish_gems.rb`.
130+
131+
The workflow requires a RubyGems API key stored as a repository secret
132+
named `RUBYGEMS_API_KEY`. Obtain the key with `gem signin` and copy the
133+
`rubygems_api_key` value from `~/.gem/credentials`. Add it under
134+
`Settings → Secrets and variables → Actions` in the repository so the
135+
workflow can authenticate with RubyGems.
136+
137+
To release a new version:
138+
139+
1. Update the `version` field in both gemspecs.
140+
2. Commit the changes and create an annotated tag `v<version>`.
141+
3. Push the tag to GitHub. The workflow will build and publish the
142+
gems if the tag matches the versions.

scripts/publish_gems.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@
22
# frozen_string_literal: true
33

44
require 'fileutils'
5+
require 'rubygems'
6+
7+
def gem_version(path)
8+
Gem::Specification.load(path).version.to_s
9+
end
10+
11+
def ensure_tag_matches_version
12+
tag = ENV['GITHUB_REF_NAME'] || ENV['RELEASE_TAG'] || `git describe --tags --exact-match`.strip
13+
tag = tag.sub(/^v/, '')
14+
15+
native_version = gem_version(File.join('gems', 'native-tracer', 'codetracer-ruby-recorder.gemspec'))
16+
pure_version = gem_version(File.join('gems', 'pure-ruby-tracer', 'codetracer_pure_ruby_recorder.gemspec'))
17+
18+
unless tag == native_version && tag == pure_version
19+
abort("Tag #{tag} does not match gem versions #{native_version} and #{pure_version}")
20+
end
21+
end
22+
23+
ensure_tag_matches_version
524

625
def load_targets
726
return ARGV unless ARGV.empty?

0 commit comments

Comments
 (0)