lib/hu/deploy.rb in hu-1.4.2 vs lib/hu/deploy.rb in hu-1.4.4
- old
+ new
@@ -27,11 +27,14 @@
::TTY::Formats::FORMATS[:huroku] = { frames: '⣾⣽⣻⢿⡿⣟⣯⣷'.chars, interval: 10 }
$stdout.sync
@@shutting_down = false
@@spinner = nil
+ @@home_branch = nil
+ MINIMUM_GIT_VERSION = Versionomy.parse('2.9.0')
+
text 'Interactive deployment.'
desc 'Interactive deployment'
if Hu::API_TOKEN.nil?
text ''
text "\e[1mWARNING: Environment variable 'HEROKU_API_KEY' must be set.\e[0m"
@@ -50,10 +53,11 @@
if $!.class == SystemExit && 130 == $!.status
puts "\n\n"
end
Hu::Tm.flush!
shutdown
+ return_to_home_branch
print "\e[0m\e[?25h"
end
begin
@git = Rugged::Repository.discover('.')
@@ -101,10 +105,11 @@
Hu::Tm.t(:error_git_flow_prefix_enabled, cmd: 'deploy')
exit 1
end
push_url = heroku_git_remote
+ @@home_branch = current_branch_name
wc_update = Thread.new { update_working_copy }
app = heroku_app_by_git(push_url)
@@ -143,10 +148,18 @@
busy 'update working copy', :dots
wc_update.join
unbusy
+ unless develop_can_be_merged_into_master?
+ puts
+ puts "ERROR: It seems like a merge of 'develop' into 'master' would fail.".color(:red)
+ puts " Aborting early to prevent a merge conflict.".color(:red)
+ puts
+ exit 1
+ end
+
highest_version = find_highest_version_tag
begin
highest_versionomy = Versionomy.parse(highest_version)
rescue
highest_versionomy = Versionomy.parse('v0.0.0')
@@ -432,12 +445,17 @@
rows.each do |r|
table << r
end
+ git_version_warning = ''
+ if current_git_version < MINIMUM_GIT_VERSION
+ git_version_warning = " (your git is outdated. please upgrade to v#{MINIMUM_GIT_VERSION}!)".color(:black).bright
+ end
+
puts "\e[H\e[2J" if clear
- puts " PIPELINE #{pipeline_name} ".inverse
+ puts " PIPELINE #{pipeline_name} ".inverse+git_version_warning
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
@@ -832,9 +850,41 @@
:return
# Abort failed merge (if any)
git merge --abort
EOS
Hu::Tm.t(:abort_merge, cmd: 'deploy')
+ end
+
+ def return_to_home_branch
+ return if @@home_branch.nil? or @@home_branch == current_branch_name
+ run_each <<-EOS.strip_heredoc
+ :quiet
+ :nospinner
+ :return
+ # Return to home branch
+ git checkout #{@@home_branch}
+ EOS
+ Hu::Tm.t(:return_home, cmd: 'deploy')
+ end
+
+ def develop_can_be_merged_into_master?
+ status = run_each <<-EOS.strip_heredoc
+ :quiet
+ :nospinner
+ :return
+ git checkout develop
+ git diff --exit-code --quiet develop..master || { git format-patch master --stdout >/tmp/hu.diff.tmp && git checkout master && git apply --check </tmp/hu.diff.tmp ; }
+ rm -f /tmp/hu.diff.tmp
+ EOS
+ status == 0
+ end
+
+ def current_branch_name
+ @git.head.name.sub(/^refs\/heads\//, '')
+ end
+
+ def current_git_version
+ Versionomy.parse(`git --version`.chomp.split(' ')[-1])
end
def create_changelog(env)
if File.executable? '.hu/hooks/changelog'
env.each { |k, v| ENV[k] = v }