From b934a60d5447d5abf2f7a4395963a7d0f7c3e7ec Mon Sep 17 00:00:00 2001 From: Alex Palladii Date: Mon, 25 Jul 2022 13:53:23 +0200 Subject: [PATCH] Use rubygems.org API to determine if the version should be bumped --- .github/workflows/build-gem.yml | 26 -------------------------- .github/workflows/gem-check.yml | 19 +++++++++++++++++++ lib/scc/codestyle/version.rb | 2 +- 3 files changed, 20 insertions(+), 27 deletions(-) delete mode 100644 .github/workflows/build-gem.yml create mode 100644 .github/workflows/gem-check.yml diff --git a/.github/workflows/build-gem.yml b/.github/workflows/build-gem.yml deleted file mode 100644 index 4224c72..0000000 --- a/.github/workflows/build-gem.yml +++ /dev/null @@ -1,26 +0,0 @@ -name: Check if the gem exists on rubygems.org - -on: [pull_request] - -jobs: - build-gem: - runs-on: ubuntu-latest - continue-on-error: true - - strategy: - matrix: - ruby-version: ['2.5', '2.7'] - - steps: - - uses: actions/checkout@v2 - - name: Set up Ruby ${{ matrix.ruby-version }} - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ matrix.ruby-version }} - - name: Check if gem exists - run: | - GEM_VERSION=$(ruby -e "require 'scc/codestyle'; print Scc::Codestyle::VERSION" -I lib) - # if we install the gem, then the $GEM_VERSION already exist on rubygems.org - # therefore error - gem install -q --silent scc-codestyle -v $GEM_VERSION && (touch failed-install && exit 0) || exit 0 - test -f failed-install && (echo "bump the gem version!" && exit 1) diff --git a/.github/workflows/gem-check.yml b/.github/workflows/gem-check.yml new file mode 100644 index 0000000..f658b42 --- /dev/null +++ b/.github/workflows/gem-check.yml @@ -0,0 +1,19 @@ +name: Check if the gem version exists on rubygems.org + +on: [pull_request] + +jobs: + build-gem: + runs-on: ubuntu-latest + continue-on-error: true + defaults: + run: + shell: bash + + steps: + - uses: actions/checkout@v2 + - name: Compare local and remote gem versions + run: | + LOCAL_GEM_VERSION=$(cat lib/scc/codestyle/version.rb | grep VERSION | awk -F"'" '{print $2}') + REMOTE_GEM_VERSION=$(curl 'https://rubygems.org/api/v1/versions/scc-codestyle/latest.json' | jq '.version' | tr -d \"); + if [ "$(printf '%s\n' "$LOCAL_GEM_VERSION" "$REMOTE_GEM_VERSION" | sort -rV | head -n 1)" != "$REMOTE_GEM_VERSION" ]; then (echo "All good!" && echo exit 0); else (echo "Bump the gem version!" && exit 1); fi diff --git a/lib/scc/codestyle/version.rb b/lib/scc/codestyle/version.rb index f17a933..dcb95cc 100644 --- a/lib/scc/codestyle/version.rb +++ b/lib/scc/codestyle/version.rb @@ -1,5 +1,5 @@ module Scc module Codestyle - VERSION = '0.6.2'.freeze + VERSION = '0.6.3'.freeze end end