Bundler: How to release a gem with 2FA enabled

Updated . Posted . Visible to the public.

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:

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.

Last edit
Julian
License
Source code in this card is licensed under the MIT License.
Posted by Emanuel to makandra dev (2019-11-14 16:26)