This repository has been archived by the owner on Jun 8, 2019. It is now read-only.
/
heroku.rb
60 lines (48 loc) · 1.54 KB
/
heroku.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
require 'cocaine'
module Kumade
class Heroku
DEPLOY_BRANCH = "deploy"
attr_reader :git
def initialize
@git = Git.new
@branch = @git.current_branch
end
def sync
git.create(DEPLOY_BRANCH)
git.push("#{DEPLOY_BRANCH}:master", Kumade.configuration.environment, true)
end
def migrate_database
heroku("rake db:migrate") unless Kumade.configuration.pretending?
Kumade.configuration.outputter.success("Migrated #{Kumade.configuration.environment}")
end
def restart_app
unless Kumade.configuration.pretending?
heroku("restart")
end
Kumade.configuration.outputter.success("Restarted #{Kumade.configuration.environment}")
end
def delete_deploy_branch
git.delete(DEPLOY_BRANCH, @branch)
end
def heroku(command)
full_heroku_command = "#{bundle_exec_heroku(command)} --remote #{Kumade.configuration.environment}"
command_line = CommandLine.new(full_heroku_command)
command_line.run_or_error("Failed to run #{command} on Heroku")
end
def cedar?
return @cedar unless @cedar.nil?
command_line = CommandLine.new("bundle exec heroku stack --remote #{Kumade.configuration.environment}")
@cedar = command_line.run_or_error.split("\n").grep(/\*/).any? do |line|
line.include?("cedar")
end
end
private
def bundle_exec_heroku(command)
if cedar? && command != 'restart'
"bundle exec heroku run #{command}"
else
"bundle exec heroku #{command}"
end
end
end
end