Skip to content

Commit cb7fd7b

Browse files
committed
Set up release automation via Trusted Publisher
Maintainers run tool/bump.rb on master to create a version bump commit. The release workflow then picks up the change, publishes the gem via RubyGems Trusted Publisher, and creates a GitHub Release. Release notes are produced via `gh release create --generate-notes`, so we do not maintain a CHANGELOG.md.
1 parent 1d0cf7f commit cb7fd7b

2 files changed

Lines changed: 79 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
paths:
8+
- lib/typeprof/version.rb
9+
10+
jobs:
11+
push:
12+
runs-on: ubuntu-latest
13+
timeout-minutes: 10
14+
permissions:
15+
contents: write
16+
id-token: write
17+
environment:
18+
name: release
19+
deployment: false
20+
steps:
21+
- uses: actions/checkout@v6
22+
23+
- name: Set up Ruby
24+
uses: ruby/setup-ruby@v1
25+
with:
26+
bundler-cache: true
27+
ruby-version: ruby
28+
29+
- name: Publish a gem
30+
uses: rubygems/release-gem@v1
31+
32+
- name: Create GitHub release
33+
run: |
34+
tag_name="$(git describe --tags --abbrev=0)"
35+
gh release create "${tag_name}" --verify-tag --generate-notes

tool/bump.rb

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env ruby
2+
3+
require "optparse"
4+
require_relative "../lib/typeprof/version"
5+
6+
REPO = "ruby/typeprof"
7+
8+
create_branch = false
9+
bump_kind = :patch
10+
11+
OptionParser.new do |opts|
12+
opts.banner = "Usage: ruby tool/bump.rb [--minor|--major] [-b|--branch]"
13+
opts.on("--minor", "Bump minor version") { bump_kind = :minor }
14+
opts.on("--major", "Bump major version") { bump_kind = :major }
15+
opts.on("-b", "--branch", "Create a new branch before committing") { create_branch = true }
16+
end.parse!
17+
18+
maj, min, pat = TypeProf::VERSION.split(".").map(&:to_i)
19+
nextver = case bump_kind
20+
when :patch then "#{maj}.#{min}.#{pat + 1}"
21+
when :minor then "#{maj}.#{min + 1}.0"
22+
when :major then "#{maj + 1}.0.0"
23+
end
24+
25+
branch = "master"
26+
Dir.chdir(File.expand_path("..", __dir__)) do
27+
abort "must be on master" unless `git rev-parse --abbrev-ref HEAD`.strip == "master"
28+
abort "working tree not clean" unless `git status --porcelain`.empty?
29+
30+
if create_branch
31+
prev_tag = `gh api repos/#{REPO}/tags --jq '.[0].name'`.strip
32+
abort "no previous tag found" if prev_tag.empty?
33+
branch = "release-from-#{prev_tag}"
34+
system("git switch -c #{branch}", exception: true)
35+
end
36+
37+
version_file = "lib/typeprof/version.rb"
38+
File.write(version_file, File.read(version_file).sub(/VERSION = "[^"]+"/, %(VERSION = "#{nextver}")))
39+
system("bundle install", exception: true)
40+
system("git add -u", exception: true)
41+
system("git commit -m 'Bump version to v#{nextver}'", exception: true)
42+
end
43+
44+
puts "Bumped to v#{nextver} (on #{branch})."

0 commit comments

Comments
 (0)