Skip to content

Commit f481331

Browse files
architectureclaude
andcommitted
fix: make CI idempotent and add test job
The publish step failed when pushing a version that already existed on GitHub Packages. Now it gracefully skips if the version is already published. Also split the workflow into separate test and publish jobs so tests run on PRs without attempting to publish. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 56de1a6 commit f481331

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

.github/workflows/gem-push.yml

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,26 @@ on:
77
branches: [ "main" ]
88

99
jobs:
10-
build:
11-
name: Build + Publish
10+
test:
11+
name: Test
1212
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v4
16+
- name: Set up Ruby 3.3
17+
uses: ruby/setup-ruby@v1
18+
with:
19+
ruby-version: '3.3'
20+
bundler-cache: true
21+
22+
- name: Run tests
23+
run: ruby -Ilib -Itest -e "Dir.glob('test/*_test.rb').each{|f| require File.expand_path(f)}"
24+
25+
publish:
26+
name: Publish
27+
needs: test
28+
runs-on: ubuntu-latest
29+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
1330
permissions:
1431
contents: read
1532
packages: write
@@ -29,8 +46,16 @@ jobs:
2946
chmod 0600 $HOME/.gem/credentials
3047
printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
3148
gem build *.gemspec
32-
gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} elevenlabs-*.gem
49+
output=$(gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} elevenlabs-*.gem 2>&1) || {
50+
if echo "$output" | grep -q "already been pushed"; then
51+
echo "Version already published — skipping."
52+
exit 0
53+
else
54+
echo "$output"
55+
exit 1
56+
fi
57+
}
58+
echo "$output"
3359
env:
3460
GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
3561
OWNER: ${{ github.repository_owner }}
36-

0 commit comments

Comments
 (0)