giddyup-deploy 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/giddyup/command_wrapper.rb +9 -2
- data/lib/giddyup/git_deploy.rb +33 -20
- metadata +4 -4
@@ -36,6 +36,9 @@ class Giddyup::CommandWrapper
|
|
36
36
|
# Giddyup::CommandWrapper::CommandFailed exception is raised containing
|
37
37
|
# the status of the failed command and all output.
|
38
38
|
#
|
39
|
+
# If a block is passed, it will be called for each line of output, and
|
40
|
+
# pass two arguments: `<stream>` and `<line>`.
|
41
|
+
#
|
39
42
|
def self.run_command(cmd)
|
40
43
|
output = []
|
41
44
|
rv = nil
|
@@ -70,7 +73,9 @@ class Giddyup::CommandWrapper
|
|
70
73
|
stdout.close
|
71
74
|
fds.delete(stdout)
|
72
75
|
else
|
73
|
-
|
76
|
+
l = stdout.readline.chomp
|
77
|
+
yield :stdout, l if block_given?
|
78
|
+
output << [:stdout, l]
|
74
79
|
end
|
75
80
|
end
|
76
81
|
|
@@ -79,7 +84,9 @@ class Giddyup::CommandWrapper
|
|
79
84
|
stderr.close
|
80
85
|
fds.delete(stderr)
|
81
86
|
else
|
82
|
-
|
87
|
+
l = stderr.readline.chomp
|
88
|
+
yield :stderr, l if block_given?
|
89
|
+
output << [:stderr, l]
|
83
90
|
end
|
84
91
|
end
|
85
92
|
end
|
data/lib/giddyup/git_deploy.rb
CHANGED
@@ -51,6 +51,11 @@ class Giddyup::GitDeploy
|
|
51
51
|
"No environment given to deploy to"
|
52
52
|
end
|
53
53
|
|
54
|
+
unless valid_environment?
|
55
|
+
raise RuntimeError,
|
56
|
+
"Unknown or unconfigured environment '#{@env}'"
|
57
|
+
end
|
58
|
+
|
54
59
|
@stdout.puts "Deploying to environment '#{@env}'"
|
55
60
|
|
56
61
|
do_push
|
@@ -60,6 +65,10 @@ class Giddyup::GitDeploy
|
|
60
65
|
end
|
61
66
|
|
62
67
|
private
|
68
|
+
def valid_environment?
|
69
|
+
!config_list('(pushTo|target(Enumerator)?)$').empty?
|
70
|
+
end
|
71
|
+
|
63
72
|
def do_push
|
64
73
|
config_item("pushTo", true).each do |t|
|
65
74
|
run_command "Pushing HEAD to remote '#{t}'",
|
@@ -81,25 +90,23 @@ class Giddyup::GitDeploy
|
|
81
90
|
# array of strings containing the names of all machines to deploy to.
|
82
91
|
#
|
83
92
|
def targets
|
84
|
-
@targets ||=
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
93
|
+
@targets ||= begin
|
94
|
+
config_list('target(Enumerator)?$').map do |li|
|
95
|
+
if li[0].downcase == 'target'
|
96
|
+
li[1]
|
97
|
+
elsif li[0].downcase == 'targetenumerator'
|
98
|
+
rv = run_command("Enumerating targets using '#{li[1]}'", li[1]).split(/\s+/)
|
99
|
+
if $?.exitstatus != 0
|
100
|
+
raise RuntimeError,
|
101
|
+
"Target enumeration failed. Aborting."
|
102
|
+
end
|
103
|
+
rv
|
104
|
+
else
|
94
105
|
raise RuntimeError,
|
95
|
-
|
106
|
+
"Unknown target expansion option: #{li[0]}"
|
96
107
|
end
|
97
|
-
|
98
|
-
|
99
|
-
raise RuntimeError,
|
100
|
-
"Unknown target expansion option: #{li[0]}"
|
101
|
-
end
|
102
|
-
end.flatten
|
108
|
+
end.flatten
|
109
|
+
end
|
103
110
|
end
|
104
111
|
|
105
112
|
# Get the value(s) of a configuration item from the config file.
|
@@ -178,12 +185,18 @@ class Giddyup::GitDeploy
|
|
178
185
|
# as a string.
|
179
186
|
#
|
180
187
|
def run_command(desc, cmdline)
|
181
|
-
|
188
|
+
in_progress = "[....] #{desc}"
|
189
|
+
|
190
|
+
$stdout.print in_progress
|
182
191
|
|
183
192
|
output = nil
|
184
193
|
failed = false
|
185
194
|
begin
|
186
|
-
output = @command.run_command(cmdline)
|
195
|
+
output = @command.run_command(cmdline) do |fd, l|
|
196
|
+
next unless @verbose
|
197
|
+
@stdout.puts "\x0d\x1b[K#{fd.to_s.send(fd == :stderr ? :cyan : purple)}: #{l}"
|
198
|
+
@stdout.print in_progress
|
199
|
+
end
|
187
200
|
rescue Giddyup::CommandWrapper::CommandFailed => e
|
188
201
|
@stdout.puts "\x0d["+"FAIL".red+"] #{desc}"
|
189
202
|
output = e.output
|
@@ -192,7 +205,7 @@ class Giddyup::GitDeploy
|
|
192
205
|
@stdout.puts "\x0d["+" OK ".green+"] #{desc}"
|
193
206
|
end
|
194
207
|
|
195
|
-
if
|
208
|
+
if failed and !@verbose
|
196
209
|
@stdout.puts cmdline
|
197
210
|
@stdout.puts output.map { |l| "#{l[0].to_s.send(l[0] == :stderr ? :cyan : :purple)}: #{l[1]}" }.join("\n")
|
198
211
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: giddyup-deploy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2015-01-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: git-version-bump
|
@@ -197,7 +197,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
197
197
|
version: '0'
|
198
198
|
segments:
|
199
199
|
- 0
|
200
|
-
hash:
|
200
|
+
hash: -1324647467486882675
|
201
201
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
202
202
|
none: false
|
203
203
|
requirements:
|
@@ -206,7 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
206
206
|
version: '0'
|
207
207
|
segments:
|
208
208
|
- 0
|
209
|
-
hash:
|
209
|
+
hash: -1324647467486882675
|
210
210
|
requirements: []
|
211
211
|
rubyforge_project:
|
212
212
|
rubygems_version: 1.8.23
|