diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index fcb6bda7..01d9bda8 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -26,7 +26,22 @@ jobs: with: bundler-cache: true + - name: Check if new version to release + id: gem_version + run: | + gem_version=$(ruby -r rubygems -e "puts Gem::Specification::load('$(ls *.gemspec)').version") + echo "::set-output name=gem_version::$gem_version" + + if git fetch origin "refs/tags/v$gem_version" >/dev/null 2>&1 + then + echo "Tag 'v$gem_version' already exists" + echo "::set-output name=new_version::false" + else + echo "::set-output name=new_version::true" + fi + - name: Publish + if: ${{ steps.gem_version.outputs.new_version }} env: RUBYGEMS_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }} GEM: govuk_tech_docs @@ -35,7 +50,7 @@ jobs: cat << EOF > ~/.gem/credentials --- - :rubygems_api_key: ${API_KEY} + :rubygems_api_key: ${RUBYGEMS_API_KEY} EOF chmod 0600 ~/.gem/credentials