lib/hu/deploy.rb in hu-1.3.19 vs lib/hu/deploy.rb in hu-1.3.20
- old
+ new
@@ -16,14 +16,19 @@
require 'rugged'
require 'pty'
require 'thread'
require 'paint'
require 'lolcat/lol'
+require 'io/console'
module Hu
class Cli < Optix::Cli
class Deploy < Optix::Cli
+ ::TTY::Formats::FORMATS[:hu] = { frames: '🌑🌒🌓🌔🌕🌖🌗🌘'.chars, interval: 10 }
+ ::TTY::Formats::FORMATS[:huroku] = { frames: '⣾⣽⣻⢿⡿⣟⣯⣷'.chars, interval: 10 }
+
+ $stdout.sync
@@shutting_down = false
@@spinner = nil
text 'Interactive deployment.'
desc 'Interactive deployment'
@@ -208,18 +213,18 @@
puts
Hu::Tm.t(:phase1, cmd: 'deploy')
end
if release_branch_exists && git_revisions[:release] == git_revisions[stag_app_name]
- puts 'Phase 2/3: Your local ' + "release/#{release_tag}".bright + ' (formerly ' + 'develop'.bright + ") is now live at #{stag_app_name}."
- puts ' Please test thoroughly: ' + (app['web_url']).to_s.bright
+ puts 'Phase 2/3: Your local ' + "release/#{release_tag}".bright + ' (formerly ' + 'develop'.bright + ") is live at "+"#{stag_app_name}".bright+"."
+ puts ' Please test here: ' + (app['web_url']).to_s.bright
puts ' If everything looks good, you may proceed and finish the release.'
puts ' If there are problems: Quit, delete the release branch and start fixing.'
puts
Hu::Tm.t(:phase2, cmd: 'deploy')
elsif git_revisions[prod_app_name] != git_revisions[stag_app_name] && !release_branch_exists && git_revisions[:release] != git_revisions[stag_app_name]
- puts 'Phase 3/3: HEADS UP. This is the last chance to detect problems.'
+ puts 'Phase 3/3: HEADS UP! This is the last chance to detect problems.'
puts ' The final version of ' + "release/#{release_tag}".bright + ' is now staged.'
puts
puts ' Test here: ' + (app['web_url']).to_s.bright
sleep 1
puts
@@ -327,17 +332,25 @@
end
end
def show_pipeline_status(pipeline_name, stag_app_name, prod_app_name, release_tag, clear = true)
table = TTY::Table.new header: %w(location commit tag app_last_modified app_last_modified_by dynos# state)
- busy '', :classic
+ busy 'loading', :huroku
ts = []
+ workers = []
tpl_row = ['?', '', '', '', '', '', '']
revs = ThreadSafe::Hash.new
+ app_config = ThreadSafe::Hash.new
[[0, stag_app_name], [1, prod_app_name]].each do |idx, app_name|
+ workers << Thread.new do
+ # config vars
+ app_config[app_name] = h.config_var.info(app_name)
+ end
+
ts << Thread.new do
+ # dyno settings
table_row = tpl_row.dup
table_row[0] = app_name
loop do
dynos = h.dyno.list(app_name)
break if dynos.nil?
@@ -379,10 +392,14 @@
end
[idx, table_row]
end
end
+ workers.each do |t|
+ t.join
+ end
+
rows = []
ts.each do |t|
idx, table_row = t.value
rows[idx] = table_row
end
@@ -416,10 +433,20 @@
puts "\e[H\e[2J" if clear
puts " PIPELINE #{pipeline_name} ".inverse
puts
puts table.render(:unicode, padding: [0, 1, 0, 1], multiline: true)
+
+ missing_env = app_config[stag_app_name].keys - app_config[prod_app_name].keys
+ unless missing_env.empty?
+ puts
+ missing_env.each do |var|
+ puts " WARNING ".color(:red).bright.inverse + " Missing config in "+prod_app_name.bright+": #{var}"
+ sleep 0.42
+ end
+ end
+
Hu::Tm.t(:status_screen, cmd: 'deploy')
revs
end
def heroku_app_by_git(git_url)
@@ -479,53 +506,55 @@
next if line.empty? || ['#', ':'].include?(line[0])
status = nil
if opts[:stream]
puts "\n> ".color(:green) + line.color(:black).bright
- PTY.spawn(line) do |r, _w, pid|
- @tspin ||= Thread.new do
- @minispin_last_char = Time.now
- @minispin_disable = false
- i = 0
- loop do
- break if @minispin_last_char == :end
- if 0.23 > Time.now - @minispin_last_char || @minispin_disable
- sleep 0.1
- next
- end
- @spinlock.synchronize do
- print "\e[?25l"
- print Paint[' ', '#000', Lol.rainbow(1, i / 3.0)]
- sleep 0.12
- print 8.chr
- print ' '
- print 8.chr
- i += 1
- print "\e[?25h"
- end
+ rows, cols = STDIN.winsize
+ @minispin_disable = false
+ @minispin_last_char_at = Time.now
+ @tspin ||= Thread.new do
+ i = 0
+ loop do
+ break if @minispin_last_char_at == :end
+ if 0.23 > Time.now - @minispin_last_char_at || @minispin_disable
+ sleep 0.1
+ next
end
+ @spinlock.synchronize do
+ next if @minispin_disable
+ print "\e[?25l"
+ print Paint[' ', '#000', Lol.rainbow(1, i / 3.0)]
+ sleep 0.12
+ print 8.chr
+ print ' '
+ print 8.chr
+ i += 1
+ print "\e[?25h"
+ end
end
+ end
+ PTY.spawn("stty rows #{rows} cols #{cols}; "+line) do |r, _w, pid|
begin
until r.eof?
c = r.getc
@spinlock.synchronize do
print c
- @minispin_last_char = Time.now
- c = c.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '') # barf.
+ @minispin_last_char_at = Time.now
+ c = c.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: "\e") # barf.
# hold on when we are (likely) inside an escape sequence
- @minispin_disable = true if c == 27
- @minispin_disable = false if c =~ /[A-Za-z]/
+ @minispin_disable = true if c.ord == 27 || c.ord < 9
+ @minispin_disable = false if c =~ /[A-Za-z]/ || [13,10].include?(c.ord)
end
end
rescue Errno::EIO
# Linux raises EIO on EOF, cf.
# https://github.com/ruby/ruby/blob/57fb2199059cb55b632d093c2e64c8a3c60acfbb/ext/pty/pty.c#L519
nil
end
_pid, status = Process.wait2(pid)
- @minispin_last_char = :end
+ @minispin_last_char_at = :end
@tspin.join
@tspin = nil
# status = PTY.check(pid)
end
else