Skip to content

Commit

Permalink
Prompt for RubyGems otp during release
Browse files Browse the repository at this point in the history
  • Loading branch information
allmarkedup committed May 29, 2024
1 parent bf278fe commit 8cbf8c5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ group :development, :test do
gem "listen"
gem "rubocop-rails", require: false
gem "standard", require: false
gem "tty-prompt"
end

group :test do
Expand Down
14 changes: 14 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ GEM
parser (3.3.0.5)
ast (~> 2.4.1)
racc
pastel (0.8.0)
tty-color (~> 0.5)
phlex (1.9.1)
concurrent-ruby (~> 1.2)
erb (>= 4)
Expand Down Expand Up @@ -305,6 +307,16 @@ GEM
stringio (3.1.0)
thor (1.3.1)
timeout (0.4.1)
tty-color (0.6.0)
tty-cursor (0.7.1)
tty-prompt (0.23.1)
pastel (~> 0.8)
tty-reader (~> 0.8)
tty-reader (0.9.0)
tty-cursor (~> 0.7)
tty-screen (~> 0.8)
wisper (~> 2.0)
tty-screen (0.8.2)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.5.0)
Expand All @@ -316,6 +328,7 @@ GEM
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
wisper (2.0.1)
xpath (3.2.0)
nokogiri (~> 1.8)
yard (0.9.36)
Expand Down Expand Up @@ -346,6 +359,7 @@ DEPENDENCIES
rubocop-rails
sprockets-rails
standard
tty-prompt
view_component

BUNDLED WITH
Expand Down
21 changes: 14 additions & 7 deletions bin/release
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require "bundler/setup"
require "dry/cli"
require "bundler/gem_tasks"

require "tty-prompt"
require "colorize"
require "lookbook"

Expand All @@ -12,7 +12,7 @@ def info(message)
end

def success(message)
puts "→ #{message}".colorize(color: :green, mode: :bold)
puts "→ #{message}".colorize(:green)
end

def error(message)
Expand All @@ -23,6 +23,10 @@ def debug(message)
puts "→ #{message}".colorize(:gray)
end

def ask(question)
TTY::Prompt.new.ask("\n#{question}".colorize(color: :magenta, mode: :bold))
end

module Lookbook
module Release
module Commands
Expand Down Expand Up @@ -64,12 +68,13 @@ module Lookbook
desc "Publishes the Lookbook gem to RubyGems"

option :dry_run, type: :boolean, default: false, desc: "Perform a dry run (no actual file changes)"
option :otp, type: :string, default: nil, desc: "RubyGems publish OTP code"

def pkg_dir
File.expand_path("#{File.dirname(__FILE__)}/../pkg")
end

def call(dry_run:)
def call(dry_run:, otp: nil)
version = Lookbook::VERSION

info "Packaging Lookbook #{version}..."
Expand All @@ -81,10 +86,14 @@ module Lookbook
success "Gem packaging complete."

info "Publishing Lookbook #{version} to RubyGems..."

otp ||= ask("Please provide RubyGems OPT code:")
raise ArgumentError, "OTP code cannot be blank." unless otp.present?

if dry_run
debug "[dry-run] Gem not pushed to RubyGems."
debug "[dry-run] Gem not pushed to RubyGems (OTP code: #{otp})"
success("Lookbook #{version} successfully published.")
elsif system("gem push #{pkg_dir}/lookbook-#{version}.gem")
elsif system("gem push #{pkg_dir}/lookbook-#{version}.gem --otp=#{otp}")
success("Lookbook #{version} successfully published.")
else
error("Error pushing gem to RubyGems")
Expand All @@ -106,9 +115,7 @@ module Lookbook

register "start", Start
register "bump", Bump
# register "package", Package
register "publish", Publish
# register "packpub", PackageAndPublish
end
end
end
Expand Down

0 comments on commit 8cbf8c5

Please sign in to comment.