From 915622d9a717a00c9981a1d4c0d4f13380f1b4ae Mon Sep 17 00:00:00 2001 From: Yuta Kasai Date: Thu, 14 Nov 2024 21:38:52 +0900 Subject: [PATCH 1/2] NO-ISSUE test --- .github/workflows/a.yml | 21 ++++++++++++++++++++ .github/workflows/publish.yml | 37 +++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 .github/workflows/a.yml create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/a.yml b/.github/workflows/a.yml new file mode 100644 index 00000000..2f90c6b9 --- /dev/null +++ b/.github/workflows/a.yml @@ -0,0 +1,21 @@ +name: Pull Request CI + +on: + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + ruby-version: 3.3 + - name: Update version + run: | + VERSION="1.29.1" + sed -i "s/VERSION = \".*\"/VERSION = \"$VERSION\"/" lib/line/bot/api/version.rb + + cat lib/line/bot/api/version.rb diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000..25a3cf44 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,37 @@ +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 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + ruby-version: 3.3 + - name: Update version + run: | + if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then + VERSION=${{ github.event.inputs.version }} + else + VERSION=${{ github.event.release.tag_name }} + fi + + sed -i "s/VERSION = \".*\"/VERSION = \"$VERSION\"/" lib/line/bot/api/version.rb + + - uses: rubygems/release-gem@v1 From 7fe12e7cef86aebff5bf7d2fcc6f20c6932603b7 Mon Sep 17 00:00:00 2001 From: Yuta Kasai Date: Thu, 14 Nov 2024 21:49:57 +0900 Subject: [PATCH 2/2] NO-ISSUE Publish gem without pushing git tag to repository --- .github/workflows/a.yml | 21 --------------------- .github/workflows/publish.yml | 11 ++++++----- Rakefile | 10 ++++++++++ 3 files changed, 16 insertions(+), 26 deletions(-) delete mode 100644 .github/workflows/a.yml diff --git a/.github/workflows/a.yml b/.github/workflows/a.yml deleted file mode 100644 index 2f90c6b9..00000000 --- a/.github/workflows/a.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: Pull Request CI - -on: - pull_request: - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Set up Ruby - uses: ruby/setup-ruby@v1 - with: - bundler-cache: true - ruby-version: 3.3 - - name: Update version - run: | - VERSION="1.29.1" - sed -i "s/VERSION = \".*\"/VERSION = \"$VERSION\"/" lib/line/bot/api/version.rb - - cat lib/line/bot/api/version.rb diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 25a3cf44..0e02fe1a 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -19,19 +19,20 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Set up Ruby - uses: ruby/setup-ruby@v1 + - uses: ruby/setup-ruby@v1 with: bundler-cache: true ruby-version: 3.3 - - name: Update version + - 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 - - sed -i "s/VERSION = \".*\"/VERSION = \"$VERSION\"/" lib/line/bot/api/version.rb + 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