0

I'm encountering an issue while trying to publish a Ruby gem to RubyGems.org using GitHub Actions. Although the workflow seems to execute without errors, I'm running into an issue when pushing the gem to RubyGems.

I'm using an API key generated from RubyGems, which I've added as a Secret in my GitHub repository. However, I'm encountering the following error in the GitHub Actions log:

Run gem push *.gem --key rubygems_api_key
ERROR:  No such API key. Please add it to your configuration (done automatically on initial `gem push`).
Error: Process completed with exit code 1.

Here's how my workflow is configured in release.yml:

- name: Publish to RubyGems
  run: gem push *.gem --key rubygems_api_key
  env:
    RUBYGEMS_API_KEY: ${{ secrets.GEM_HOST_API_KEY }}

I have verified that the API key is correctly added as a Secret in GitHub and that the Secret name matches in the workflow. Am I missing something, or is there an additional step I need to take? Any help would be greatly appreciated.

Thank you!

1 Answer 1

1

The --key option to gem push expects to find the key in the file ~/.gem/credentials or ~/.local/share/gem/credentials or whatever the local Gem directory is on your GitHub Runner.

With GitHub Actions, instead of writing the key to a file and read it back from there, it is much easier to pass the key in an environment variable. If the --key option is left out, RubyGems looks for the API key in an environment variable named GEM_HOST_API_KEY.

So, all you need to do is remove the --key option from the call to gem push and publish the secret API key in an environment variable named GEM_HOST_API_KEY:

- name: Publish to RubyGems
  run: gem push *.gem
  env:
    GEM_HOST_API_KEY: ${{ secrets.GEM_HOST_API_KEY }}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.