Publishing a Ruby Gem to the GitHub Package Registry
When trying to publish a new gem to the GitHub package registry I received the following error:
Unable to push RubyGem to Package Registry (The expected resource was not found)
After doing some digging, it looks as though you cannot publish gems with any name you like to the package registry.
If you're using the GITHUB_SECRET
token in GitHub Actions, the gem name and repo name must match exactly. If your repo is michael-test-org/my_gem
then the gem must be named my_gem
.
If you're using a personal access token you have a little more flexibility. You can publish gems that match any repository within your organisation, not just the repository that the workflow is running for.
If you're looking for a workflow to publish gems, here are the relevant steps:
yaml
name: Publish Gemon:push:tags:- "v*"jobs:build:runs-on: ubuntu-18.04steps:- uses: actions/checkout@v2- name: Ruby gem cacheuses: actions/cache@v2with:path: ${{ github.workspace }}/vendor/bundlekey: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}restore-keys: |${{ runner.os }}-gems-- name: Bundle Setuprun: |gem install --no-document bundlerbundle config path ${{ github.workspace }}/vendor/bundle- name: Bundle Installrun: bundle install --jobs 4 --retry 3- name: Set Credentialsrun: |mkdir -p $HOME/.gemtouch $HOME/.gem/credentialschmod 0600 $HOME/.gem/credentialsprintf -- "---\n:github: Bearer ${GITHUB_TOKEN}\n" > $HOME/.gem/credentialsenv:GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}- name: Publish to GitHub Packagesrun: |export OWNER=$( echo ${{ github.repository }} | cut -d "/" -f 1 )gem build station.gemspecgem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gemgem push *.gem