From bace85d36efe89448cdda292bdadbf9d9cc611f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?TATSUNO=20=E2=80=9CTaz=E2=80=9D=20Yasuhiro?= Date: Tue, 2 Dec 2025 20:59:20 +0900 Subject: [PATCH 1/2] automate release --- .github/workflows/push_gem.yml | 63 ++++++++++++++++++++++++++++++++++ README.md | 6 ++-- 2 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/push_gem.yml diff --git a/.github/workflows/push_gem.yml b/.github/workflows/push_gem.yml new file mode 100644 index 00000000..737ffbed --- /dev/null +++ b/.github/workflows/push_gem.yml @@ -0,0 +1,63 @@ +name: release + +on: + workflow_dispatch: + inputs: + version: + description: 'Version to release (e.g. 0.21.3 or v0.21.3)' + 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@v5 + with: + fetch-depth: 0 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + ruby-version: ruby + + - name: Bump version.rb + run: | + set -euo pipefail + version="${{ github.event.inputs.version }}" + version="${version#v}" + + echo "VERSION_NO_V=$version" >> "$GITHUB_ENV" + echo "VERSION_TAG=v$version" >> "$GITHUB_ENV" + + if ! [[ "$version" =~ ^[0-9]+(\.[0-9]+)*$ ]]; then + echo "Invalid version format: $version" >&2 + exit 1 + fi + + ruby -pi -e "sub(/VERSION = .*/, \"VERSION = '$version'\")" lib/rspec/openapi/version.rb + git status --short + + - name: Commit version bump + run: | + set -euo pipefail + version="$VERSION_NO_V" + + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git commit -am "Bump version to ${version}" + git push origin "HEAD:${{ github.event.repository.default_branch }}" + + - uses: rubygems/release-gem@v1 + + - name: Create GitHub release + uses: softprops/action-gh-release@v2 + with: + tag_name: ${{ env.VERSION_TAG }} + name: ${{ env.VERSION_TAG }} + generate_release_notes: true diff --git a/README.md b/README.md index 0e0be56b..7fcb0728 100644 --- a/README.md +++ b/README.md @@ -410,9 +410,9 @@ Existing RSpec plugins which have OpenAPI integration: ## Releasing -1. Bump version in `lib/rspec/openapi/version.rb` -2. Run `bundle exec rake release` -3. Push tag +1. Ensure RubyGems trusted publishing is configured for this repo and gem ownership (see [Trusted publishing](https://guides.rubygems.org/trusted-publishing/)). +2. In GitHub Actions, run the `release` workflow manually and input the new version (`0.21.x` or `v0.21.x`). +3. The workflow bumps `lib/rspec/openapi/version.rb`, pushes the change to the default branch, publishes to RubyGems via `rubygems/release-gem`, and creates a GitHub release with autogenerated notes. ## License From 5cf58ba58bd638c9c844d131f53e9bb744550199 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?TATSUNO=20=E2=80=9CTaz=E2=80=9D=20Yasuhiro?= Date: Tue, 2 Dec 2025 21:02:31 +0900 Subject: [PATCH 2/2] automate release --- .github/workflows/push_gem.yml | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/.github/workflows/push_gem.yml b/.github/workflows/push_gem.yml index 737ffbed..3babf201 100644 --- a/.github/workflows/push_gem.yml +++ b/.github/workflows/push_gem.yml @@ -35,10 +35,22 @@ jobs: echo "VERSION_NO_V=$version" >> "$GITHUB_ENV" echo "VERSION_TAG=v$version" >> "$GITHUB_ENV" - if ! [[ "$version" =~ ^[0-9]+(\.[0-9]+)*$ ]]; then - echo "Invalid version format: $version" >&2 - exit 1 - fi + current_version=$(ruby -e "require_relative './lib/rspec/openapi/version'; puts RSpec::OpenAPI::VERSION") + VERSION_NO_V="$version" CURRENT_VERSION="$current_version" ruby - <<'RUBY' + version = ENV.fetch('VERSION_NO_V') + unless version.match?(/\A\d+(?:\.\d+)*\z/) + warn "Invalid version format: #{version}" + exit 1 + end + + require 'rubygems' + new_version = Gem::Version.new(version) + current_version = Gem::Version.new(ENV.fetch('CURRENT_VERSION')) + unless new_version < current_version + warn "Given version (#{new_version}) must be lower than current version (#{current_version})" + exit 1 + end + RUBY ruby -pi -e "sub(/VERSION = .*/, \"VERSION = '$version'\")" lib/rspec/openapi/version.rb git status --short