Class: Bard::CLI
- Inherits:
-
Thor
show all
- Includes:
- Git, Term::ANSIColor
- Defined in:
- lib/bard.rb,
lib/bard/base.rb,
lib/bard/error.rb
Defined Under Namespace
Modules: Git
Classes: MasterNonFastForwardError, NonFastForwardError, TestsAbortedError, TestsFailedError
Instance Method Summary
collapse
Instance Method Details
#ci ⇒ Object
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/bard.rb', line 82
def ci
return unless has_ci?
puts "Continuous integration: starting build..."
last_build_number = get_last_build_number
last_time_elapsed = get_last_time_elapsed
start_ci
sleep(2) while last_build_number == get_last_build_number
start_time = Time.new.to_i
while (response = `curl -s #{ci_host}/lastBuild/api/xml?token=botandrose`).include? "<building>true</building>"
elapsed_time = Time.new.to_i - start_time
if last_time_elapsed
percentage = (elapsed_time.to_f / last_time_elapsed.to_f * 100).to_i
output = " Estimated completion: #{percentage}%"
else
output = " No estimated completion time. Elapsed time: #{elapsed_time} sec"
end
print "\x08" * output.length
print output
$stdout.flush
sleep(2)
end
puts
case response
when /<result>FAILURE<\/result>/ then
puts
puts `curl -s #{ci_host}/lastBuild/console?token=botandrose`.match(/<pre>(.+)<\/pre>/m)[1]
puts
raise TestsFailedError, "#{ci_host}/#{get_last_build_number}/console"
when /<result>ABORTED<\/result>/ then
raise TestsAbortedError, "#{ci_host}/#{get_last_build_number}/console"
when /<result>SUCCESS<\/result>/ then
puts "Continuous integration: success! deploying to production"
else raise "Unknown response from CI server:\n#{response}"
end
end
|
#data(from = "production", to = "local") ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/bard.rb', line 13
def data(from = "production", to = "local")
if to == "local"
if from == "production" and heroku?
exec "heroku db:pull --confirm #{project_name}"
else
exec "cap _2.5.10_ data:pull ROLES=#{from}"
end
else
if from == "local"
exec "cap _2.5.10_ data:push ROLES=#{to}"
end
end
end
|
#deploy ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/bard.rb', line 54
def deploy
invoke :push
if has_integration_branch?
run_crucial "git fetch origin"
run_crucial "git checkout master"
run_crucial "git pull --rebase origin master"
raise MasterNonFastForwardError if not fast_forward_merge? "master", "integration"
run_crucial "git merge integration"
run_crucial "git push origin master"
run_crucial "git checkout integration"
end
invoke :ci
if heroku?
run_crucial "git push production master", options.verbose?
run_crucial "heroku run rake bootstrap:production:post", options.verbose?
else
run_crucial "cap _2.5.10_ deploy", options.verbose?
end
puts green("Deploy Succeeded")
end
|
#pull ⇒ Object
30
31
32
33
|
# File 'lib/bard.rb', line 30
def pull
run_crucial "git pull --rebase origin #{current_branch}", options.verbose?
run_crucial "bundle && bundle exec rake bootstrap", options.verbose?
end
|
#push ⇒ Object
37
38
39
40
|
# File 'lib/bard.rb', line 37
def push
raise NonFastForwardError unless fast_forward_merge?("origin/#{current_branch}")
run_crucial "git push origin #{current_branch}", true
end
|
#stage ⇒ Object
44
45
46
47
48
49
50
|
# File 'lib/bard.rb', line 44
def stage
invoke :push
run_crucial "cap _2.5.10_ stage BRANCH=#{current_branch}", options.verbose?
puts green("Stage Succeeded")
end
|