Skip to content

Commit 95e2d45

Browse files
committed
fix tag check logic in gem-push workflow
1 parent 0142cbe commit 95e2d45

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

.github/workflows/gem-push.yml

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,31 @@ on:
77
jobs:
88
test:
99
uses: ./.github/workflows/test.yml
10+
check:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: read
14+
outputs:
15+
tag_name: ${{ steps.get_tag.outputs.TAG_NAME }}
16+
steps:
17+
- uses: actions/checkout@v4
18+
- id: get_tag
19+
name: Get Local Tag Name
20+
run: |
21+
TAG_NAME=$(ruby -I. -r lib/restful_error/version -e 'puts "v#{RestfulError::VERSION}"')
22+
if git fetch --depth 1 origin tag $TAG_NAME; then
23+
echo "::notice::$TAG_NAME already released. skip publishing."
24+
exit 0
25+
fi
26+
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_OUTPUT
27+
1028
build:
11-
needs: test
29+
needs:
30+
- test
31+
- check
32+
if: needs.check.outputs.tag_name
33+
env:
34+
TAG_NAME: ${{ needs.check.outputs.tag_name }}
1235
name: Build + Publish
1336
runs-on: ubuntu-latest
1437
permissions:
@@ -17,54 +40,32 @@ jobs:
1740

1841
steps:
1942
- uses: actions/checkout@v4
20-
with:
21-
fetch-tags: 'true'
2243
- name: Set up Ruby 3.3
2344
uses: ruby/setup-ruby@v1
2445
with:
2546
ruby-version: 3.3
26-
27-
- name: Get Local Tag Name
28-
run: |
29-
TAG_NAME=$(ruby -I. -r lib/restful_error/version -e 'puts "v#{RestfulError::VERSION}"')
30-
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV
31-
32-
- id: check
33-
name: Check already released
34-
run: |
35-
if git fetch --depth 1 origin tag $TAG_NAME; then
36-
echo "$TAG_NAME already released. skip."
37-
exit 0
38-
fi
39-
echo "deploy=true" >> $GITHUB_OUTPUT
40-
4147
- name: build
42-
if: steps.check.outputs.deploy == 'true'
4348
run: gem build *.gemspec
4449

4550
- name: Publish to RubyGems
46-
if: steps.check.outputs.deploy == 'true'
4751
run: gem push *.gem
4852
env:
4953
GEM_HOST_API_KEY: ${{ secrets.GEM_HOST_API_KEY }}
5054

5155
- name: Publish to GPR
52-
if: steps.check.outputs.deploy == 'true'
5356
run: gem push --host https://rubygems.pkg.github.com/${OWNER} *.gem
5457
env:
5558
OWNER: ${{ github.repository_owner }}
5659
GEM_HOST_API_KEY: ${{ secrets.GITHUB_TOKEN }}
5760

5861
- name: Create Tag
59-
if: steps.check.outputs.deploy == 'true'
6062
run: |
6163
git config user.email "o@kbn.one"
6264
git config user.name "github action"
6365
git tag $TAG_NAME
6466
git push origin $TAG_NAME
6567
6668
- name: Create Release
67-
if: steps.check.outputs.deploy == 'true'
6869
uses: actions/create-release@v1
6970
env:
7071
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)