diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000..0e02fe1a --- /dev/null +++ b/.github/workflows/publish.yml @@ -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 diff --git a/Rakefile b/Rakefile index 4c774a2b..33cd4fbb 100644 --- a/Rakefile +++ b/Rakefile @@ -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