From 8f833513669f9c497c82598fccb96b038eabc4ed Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 14 Dec 2021 12:48:01 -0800 Subject: [PATCH] Add support for YubiKey OTP codes during release This patch adds support for automatically getting OTP codes from your YubiKey during release. You must have the `ykman` commandline tool installed, and have two accounts setup with the names `rubygems.org` and `npmjs.com`. For example, the output from `ykman oath accounts list` on my machine is this: ``` $ ykman oath accounts list npmjs.com:aaron.patterson@gmail.com rubygems.org:aaron.patterson@gmail.com ``` If you meet these conditions, you can do `rake release` without typing an OTP code for every gem. If no `ykman` tool is found on your system, this will just fall back to asking for an OTP code. --- tasks/release.rb | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/tasks/release.rb b/tasks/release.rb index ad1c5ecb2c2f4..345ad7ea02ed2 100644 --- a/tasks/release.rb +++ b/tasks/release.rb @@ -99,12 +99,26 @@ end task push: :build do - sh "gem push #{gem}" + otp = "" + begin + otp = " --otp " + `ykman oath accounts code -s rubygems.org`.chomp + rescue + # User doesn't have ykman + end + + sh "gem push #{gem}#{otp}" if File.exist?("#{framework}/package.json") Dir.chdir("#{framework}") do npm_tag = /[a-z]/.match?(version) ? "pre" : "latest" - sh "npm publish --tag #{npm_tag}" + npm_otp = "" + begin + npm_otp = " --otp " + `ykman oath accounts code -s npmjs.com`.chomp + rescue + # User doesn't have ykman + end + + sh "npm publish --tag #{npm_tag}#{npm_otp}" end end end