Skip to content

Conversation

@Kelleretoro
Copy link

This pull request adds a new GitHub Actions workflow for automating the build and publishing process of Ruby gems. The workflow is triggered on pushes and pull requests to the master branch and supports publishing to both GitHub Packages and RubyGems.

Continuous Integration and Deployment:

  • Introduces .github/workflows/gem-push.yml to automate building and publishing Ruby gems when changes are pushed or pull requests are made to master.
  • Configures steps to set up Ruby 2.6, build the gem, and publish it to both GitHub Packages and RubyGems using respective API keys and credentials.

Copilot AI review requested due to automatic review settings November 25, 2025 20:07
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces a GitHub Actions workflow to automate the publishing of Ruby gems to both GitHub Packages and RubyGems. The workflow is triggered on pushes and pull requests to the master branch.

Key Changes:

  • Adds automated CI/CD workflow for Ruby gem publishing with dual-target deployment
  • Configures Ruby 2.6 environment setup using pinned ruby/setup-ruby action
  • Implements credential management and authentication for both GitHub Packages and RubyGems

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +5 to +7
branches: [ "master" ]
pull_request:
branches: [ "master" ]
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.
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.
# 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.
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.
Comment on lines +27 to +48
- 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}}"
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant