Skip to content

Commit

Permalink
Automate publish (#339)
Browse files Browse the repository at this point in the history
## 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
  • Loading branch information
Yang-33 authored Nov 15, 2024
1 parent 4ab52ed commit 150140f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Publish package to the RubyGems.org
on:
release:
types: [published]
workflow_dispatch:
inputs:
version:
description: 'The version to release. v prefix is required (e.g. v1.10.0)'
required: true

jobs:
push:
name: Push gem to RubyGems.org
runs-on: ubuntu-latest

permissions:
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
contents: write # IMPORTANT: this permission is required for `rake release` to push the release tag

steps:
- uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
ruby-version: 3.3
- name: Update version file with the release version
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
VERSION=${{ github.event.inputs.version }}
else
VERSION=${{ github.event.release.tag_name }}
fi
VERSION=${VERSION#v}
sed -i "s/VERSION = \".*\"/VERSION = \"$VERSION\"/" lib/line/bot/api/version.rb
cat lib/line/bot/api/version.rb
- uses: rubygems/release-gem@v1
10 changes: 10 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,13 @@ require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)

task default: :spec

# We don't want to push tags to source control when releasing the gem
Rake::Task["release"].clear

# Redefine `release` task to build and push gem to RubyGems without pushing to source control
## https://github.com/rubygems/bundler/blob/35be6d9a603084f719fec4f4028c18860def07f6/lib/bundler/gem_helper.rb#L53-L57
desc "Build and push gem to RubyGems without pushing to source control"
task "release", [:remote] => ["build", "release:guard_clean", "release:rubygem_push"] do
puts "Built and pushed gem to RubyGems without pushing to source control."
end

0 comments on commit 150140f

Please sign in to comment.