-
Notifications
You must be signed in to change notification settings - Fork 36
Add GitHub Actions workflow for Ruby Gem publishing #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,48 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: Ruby Gem | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| on: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| push: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| branches: [ "master" ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pull_request: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| branches: [ "master" ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| jobs: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| build: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: Build + Publish | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| runs-on: ubuntu-latest | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| permissions: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| contents: read | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| packages: write | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| steps: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - uses: actions/checkout@v4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| - name: Set up Ruby 2.6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # change this to (see https://github.com/ruby/setup-ruby#versioning): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # uses: ruby/setup-ruby@v1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| with: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ruby-version: 2.6.x | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ruby-version: 2.6.x | |
| ruby-version: 3.2.x |
Copilot
AI
Nov 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The --KEY flag should be --key (lowercase). The gem push command uses lowercase option flags. This will cause the GitHub Packages publishing step to fail.
| gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem | |
| gem push --key github --host https://rubygems.pkg.github.com/${OWNER} *.gem |
Copilot
AI
Nov 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both publishing steps rebuild the gem unnecessarily. The gem is already built in the GPR step (line 33), so the RubyGems step doesn't need to rebuild it. This wastes CI time and could theoretically produce different artifacts if the build process is non-deterministic. Consider building once and reusing the artifact, or at minimum, document why rebuilding is necessary.
| gem build *.gemspec | |
| # Reuse the gem built in the previous step to avoid non-deterministic builds and save CI time |
Copilot
AI
Nov 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Both steps recreate the credentials file, which overwrites the previous credentials. This means authentication to GitHub Packages is lost before attempting to push to RubyGems. While this works because each step runs independently, it's inefficient to recreate the same directory structure twice. Consider consolidating the credential setup or using a single credentials file with both keys.
| - name: Publish to GPR | |
| run: | | |
| mkdir -p $HOME/.gem | |
| touch $HOME/.gem/credentials | |
| chmod 0600 $HOME/.gem/credentials | |
| printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials | |
| gem build *.gemspec | |
| gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem | |
| env: | |
| GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}" | |
| OWNER: ${{ github.repository_owner }} | |
| - name: Publish to RubyGems | |
| run: | | |
| mkdir -p $HOME/.gem | |
| touch $HOME/.gem/credentials | |
| chmod 0600 $HOME/.gem/credentials | |
| printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials | |
| gem build *.gemspec | |
| gem push *.gem | |
| env: | |
| GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}" | |
| - name: Set up gem credentials | |
| run: | | |
| mkdir -p $HOME/.gem | |
| touch $HOME/.gem/credentials | |
| chmod 0600 $HOME/.gem/credentials | |
| printf -- "---\n:github: Bearer ${{secrets.GITHUB_TOKEN}}\n:rubygems_api_key: ${{secrets.RUBYGEMS_AUTH_TOKEN}}\n" > $HOME/.gem/credentials | |
| - name: Publish to GPR | |
| run: | | |
| gem build *.gemspec | |
| gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem | |
| env: | |
| OWNER: ${{ github.repository_owner }} | |
| - name: Publish to RubyGems | |
| run: | | |
| gem build *.gemspec | |
| gem push *.gem |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Publishing gems on pull requests is problematic. This workflow will attempt to publish gems on every PR to master, which could lead to:
Consider removing
pull_requestfrom the triggers and only publish on push to master, or better yet, only on tagged releases: