Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .github/workflows/gem-push.yml
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" ]
Comment on lines +5 to +7
Copy link

Copilot AI Nov 25, 2025

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:

  1. Publishing unreviewed/unmerged code
  2. Version conflicts if multiple PRs are opened
  3. Unauthorized publishing attempts

Consider removing pull_request from the triggers and only publish on push to master, or better yet, only on tagged releases:

on:
  push:
    tags:
      - 'v*'
Suggested change
branches: [ "master" ]
pull_request:
branches: [ "master" ]
tags:
- 'v*'

Copilot uses AI. Check for mistakes.

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
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ruby 2.6 reached end-of-life in March 2022 and no longer receives security updates. Consider upgrading to a supported Ruby version (3.0+) to ensure security patches and compatibility with modern gems.

Suggested change
ruby-version: 2.6.x
ruby-version: 3.2.x

Copilot uses AI. Check for mistakes.

- 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
Copy link

Copilot AI Nov 25, 2025

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.

Suggested change
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 uses AI. Check for mistakes.
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
Copy link

Copilot AI Nov 25, 2025

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.

Suggested change
gem build *.gemspec
# Reuse the gem built in the previous step to avoid non-deterministic builds and save CI time

Copilot uses AI. Check for mistakes.
gem push *.gem
env:
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
Comment on lines +27 to +48
Copy link

Copilot AI Nov 25, 2025

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.

Suggested change
- 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

Copilot uses AI. Check for mistakes.