Read more

Bundler: How to release a gem with 2FA enabled

Emanuel
November 14, 2019Software engineer at makandra GmbH

Rubygems supports a 2FA for your account. Once enabled you need to provide your personal OTP code for every release. Despite the CLI of the rake release task does not work well with the command prompt for your OTP code with Bundler versions < 2.0.2. It just looks like the task is frozen:

Illustration online protection

Rails professionals since 2007

Our laser focus on a single technology has made us a leader in this space. Need help?

  • We build a solid first version of your product
  • We train your development team
  • We rescue your project in trouble
Read more Show archive.org snapshot

Image

  • Workaround 1: Just type your OTP code and hit enter, your gem is released afterwards.
  • Workaround 2: Upgrade to Bundler >= 2.0.2.. Your supported Ruby versions for this gem must be >= 2.3.

When rake release returns an error

rake aborted!
Your rubygems.org credentials aren't set. Run `gem push` to set them.

If you have no api key in ~/.gem/credentials then gem signin have maybe silently failed. You can fetch the api key yourself.

curl -H "OTP: REPLACE_WITH_YOUR_OTP" -u REPLACE_WITH_YOUR_USERNAME https://rubygems.org/api/v1/api_key.yaml > ~/.gem/credentials
chmod 0600 ~/.gem/credentials

When you need to release a gem using an old Ruby version

If you need to release a gem with a legacy Ruby version like 1.8.7, the workarounds above won't work for you.

In this case, switch to a modern Ruby version only to make the release, then switch back.
You will have to call the rake release command without bundle exec.

Posted by Emanuel to makandra dev (2019-11-14 17:26)