Skip to content

Commit 150140f

Browse files
authored
Automate publish (#339)
## Changes Resolve #299 Rubygems provides a way to release gem with GitHub Actions officially. It seems it doesn't require personal access token. let's try to use it. On publishing, this workflow calls `bundle exec rake release`, and it tries to push git tag. this doesn't match our use case. We always create release note with git tag in this repository at first (in other 5 bot sdk projects), and we want the workflow to publish(release) gem later. This change modifies `release` task not to push git tag. I don't know if this works. Let me try it. ref: - https://guides.rubygems.org/trusted-publishing/adding-a-publisher/ - I've set `publish.yml` in `line/line-bot-sdk-ruby` can be trusted in `line-bot-api` gem: https://rubygems.org/gems/line-bot-api/trusted_publishers - https://github.com/rubygems/release-gem
1 parent 4ab52ed commit 150140f

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

.github/workflows/publish.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Publish package to the RubyGems.org
2+
on:
3+
release:
4+
types: [published]
5+
workflow_dispatch:
6+
inputs:
7+
version:
8+
description: 'The version to release. v prefix is required (e.g. v1.10.0)'
9+
required: true
10+
11+
jobs:
12+
push:
13+
name: Push gem to RubyGems.org
14+
runs-on: ubuntu-latest
15+
16+
permissions:
17+
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
18+
contents: write # IMPORTANT: this permission is required for `rake release` to push the release tag
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
- uses: ruby/setup-ruby@v1
23+
with:
24+
bundler-cache: true
25+
ruby-version: 3.3
26+
- name: Update version file with the release version
27+
run: |
28+
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
29+
VERSION=${{ github.event.inputs.version }}
30+
else
31+
VERSION=${{ github.event.release.tag_name }}
32+
fi
33+
VERSION=${VERSION#v}
34+
35+
sed -i "s/VERSION = \".*\"/VERSION = \"$VERSION\"/" lib/line/bot/api/version.rb
36+
37+
cat lib/line/bot/api/version.rb
38+
- uses: rubygems/release-gem@v1

Rakefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,13 @@ require 'rspec/core/rake_task'
44
RSpec::Core::RakeTask.new(:spec)
55

66
task default: :spec
7+
8+
# We don't want to push tags to source control when releasing the gem
9+
Rake::Task["release"].clear
10+
11+
# Redefine `release` task to build and push gem to RubyGems without pushing to source control
12+
## https://github.com/rubygems/bundler/blob/35be6d9a603084f719fec4f4028c18860def07f6/lib/bundler/gem_helper.rb#L53-L57
13+
desc "Build and push gem to RubyGems without pushing to source control"
14+
task "release", [:remote] => ["build", "release:guard_clean", "release:rubygem_push"] do
15+
puts "Built and pushed gem to RubyGems without pushing to source control."
16+
end

0 commit comments

Comments
 (0)