fix tag check logic in gem-push workflow #24
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Ruby Gem | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| jobs: | |
| test: | |
| uses: ./.github/workflows/test.yml | |
| check: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| outputs: | |
| tag_name: ${{ steps.get_tag.outputs.TAG_NAME }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - id: get_tag | |
| name: Get Local Tag Name | |
| run: | | |
| TAG_NAME=$(ruby -I. -r lib/restful_error/version -e 'puts "v#{RestfulError::VERSION}"') | |
| if git fetch --depth 1 origin tag $TAG_NAME; then | |
| echo "::notice::$TAG_NAME already released. skip publishing." | |
| exit 0 | |
| fi | |
| echo "TAG_NAME=$TAG_NAME" >> $GITHUB_OUTPUT | |
| build: | |
| needs: | |
| - test | |
| - check | |
| if: needs.check.outputs.tag_name | |
| env: | |
| TAG_NAME: ${{ needs.check.outputs.tag_name }} | |
| name: Build + Publish | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| packages: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Ruby 3.3 | |
| uses: ruby/setup-ruby@v1 | |
| with: | |
| ruby-version: 3.3 | |
| - name: build | |
| run: gem build *.gemspec | |
| - name: Publish to RubyGems | |
| run: gem push *.gem | |
| env: | |
| GEM_HOST_API_KEY: ${{ secrets.GEM_HOST_API_KEY }} | |
| - name: Publish to GPR | |
| run: gem push --host https://rubygems.pkg.github.com/${OWNER} *.gem | |
| env: | |
| OWNER: ${{ github.repository_owner }} | |
| GEM_HOST_API_KEY: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Create Tag | |
| run: | | |
| git config user.email "[email protected]" | |
| git config user.name "github action" | |
| git tag $TAG_NAME | |
| git push origin $TAG_NAME | |
| - name: Create Release | |
| uses: actions/create-release@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| tag_name: ${{ env.TAG_NAME }} | |
| release_name: Release ${{ env.TAG_NAME }} | |
| draft: false | |
| prerelease: false |