volley 0.1.0.alpha4 → 0.1.0.alpha5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -1
- data/.rspec +1 -0
- data/Gemfile +4 -1
- data/Rakefile +34 -0
- data/bin/volley +88 -40
- data/conf/common.volleyfile +12 -29
- data/features/publisher.feature +45 -0
- data/features/step_definitions/common_steps.rb +9 -0
- data/features/step_definitions/publisher_steps.rb +92 -0
- data/features/support/env.rb +19 -0
- data/init/Volleyfile +1 -104
- data/lib/volley/descriptor.rb +28 -0
- data/lib/volley/dsl/action.rb +31 -0
- data/lib/volley/dsl/argument.rb +96 -0
- data/lib/volley/dsl/file.rb +70 -0
- data/lib/volley/dsl/plan.rb +110 -235
- data/lib/volley/dsl/project.rb +10 -2
- data/lib/volley/dsl/pull_action.rb +50 -0
- data/lib/volley/dsl/push_action.rb +101 -0
- data/lib/volley/dsl/stage.rb +40 -0
- data/lib/volley/dsl.rb +7 -0
- data/lib/volley/log.rb +22 -8
- data/lib/volley/meta.rb +24 -0
- data/lib/volley/publisher/amazons3.rb +67 -66
- data/lib/volley/publisher/base.rb +81 -42
- data/lib/volley/publisher/exceptions.rb +7 -0
- data/lib/volley/publisher/local.rb +41 -27
- data/lib/volley/scm/base.rb +10 -0
- data/lib/volley.rb +38 -12
- data/spec/descriptor_spec.rb +39 -0
- data/spec/dsl_plan_spec.rb +103 -0
- data/spec/dsl_project_spec.rb +36 -0
- data/spec/dsl_volleyfile_spec.rb +21 -0
- data/spec/meta_spec.rb +26 -0
- data/spec/publisher_spec.rb +92 -0
- data/test/dsl/amazons3_publisher.volleyfile +6 -0
- data/test/dsl/local_publisher.volleyfile +4 -0
- data/test/dsl/log_console.volleyfile +2 -0
- data/test/dsl/log_file.volleyfile +2 -0
- data/test/dsl/simple.volleyfile +17 -0
- data/test/meta.yml +3 -0
- data/test/project/Rakefile +13 -0
- data/test/project/Volleyfile +18 -0
- data/test/trunk-1.tgz +0 -0
- data/volley.gemspec +2 -1
- metadata +67 -5
- data/lib/volley/config.rb +0 -8
- data/lib/volley/volley_file.rb +0 -45
@@ -0,0 +1,96 @@
|
|
1
|
+
module Volley
|
2
|
+
module Dsl
|
3
|
+
class Argument
|
4
|
+
attr_accessor :name
|
5
|
+
attr_accessor :value
|
6
|
+
attr_reader :default
|
7
|
+
attr_reader :convert
|
8
|
+
attr_reader :required
|
9
|
+
|
10
|
+
def initialize(name, options={ }, &block)
|
11
|
+
@name = name.to_sym
|
12
|
+
@block = block
|
13
|
+
@plan = options.delete(:plan)
|
14
|
+
@required = options.delete(:required)
|
15
|
+
@default = options.delete(:default)
|
16
|
+
@convert = options.delete(:convert)
|
17
|
+
@convopt = options.delete(:convert_opts) || {}
|
18
|
+
@choices = options.delete(:choices)
|
19
|
+
|
20
|
+
@value = @required ? nil : (@default || nil)
|
21
|
+
|
22
|
+
raise "plan instance must be set" unless @plan
|
23
|
+
|
24
|
+
#@plan.action "argument-#{name}", :pre do
|
25
|
+
# arguments[name.to_sym].handler
|
26
|
+
#end
|
27
|
+
end
|
28
|
+
|
29
|
+
def value=(value)
|
30
|
+
@value = value
|
31
|
+
@value ||= @default unless @default.nil?
|
32
|
+
raise "arg '#@name' is required, but not set" if @required && @value.nil?
|
33
|
+
if @convert.nil?
|
34
|
+
if block_given?
|
35
|
+
@value = yield @value
|
36
|
+
end
|
37
|
+
else
|
38
|
+
case @convert
|
39
|
+
when :boolean
|
40
|
+
@value = boolean(@value)
|
41
|
+
when :descriptor
|
42
|
+
@value = Volley::Descriptor.new(@value, @convopt)
|
43
|
+
else
|
44
|
+
@value = @value.send(@convert)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
raise "arg '#@name' is required, but not set (after convert)" if @required && @value.nil?
|
48
|
+
raise "arg '#@name' should be one of #{@choices.inspect}" if @choices && !@choices.include?(@value)
|
49
|
+
end
|
50
|
+
|
51
|
+
def check
|
52
|
+
raise "arg '#@name' is required, but not set (in check)" if @required && @value.nil?
|
53
|
+
end
|
54
|
+
|
55
|
+
#def handler
|
56
|
+
# @value ||= @default unless @default.nil?
|
57
|
+
# raise "arg '#{@name}' is required, but not set" if @required && @value.nil?
|
58
|
+
# if @convert.nil?
|
59
|
+
# if block_given?
|
60
|
+
# @value = yield @value
|
61
|
+
# end
|
62
|
+
# else
|
63
|
+
# case @convert
|
64
|
+
# when :boolean
|
65
|
+
# @value = boolean(@value)
|
66
|
+
# when :descriptor
|
67
|
+
# opts = @convopt || {}
|
68
|
+
# @value = Volley::Descriptor.new(@value, @convopt)
|
69
|
+
# else
|
70
|
+
# @value = @value.send(@convert)
|
71
|
+
# end
|
72
|
+
# end
|
73
|
+
# raise "arg '#{name}' is required, but not set (after convert)" if @required && @value.nil?
|
74
|
+
# raise "arg '#{name}' should be one of #{@choices.inspect}" if @choices && !@choices.include?(@value)
|
75
|
+
#end
|
76
|
+
|
77
|
+
def usage
|
78
|
+
v = @choices || @convert || "string"
|
79
|
+
r = @required ? "*" : ""
|
80
|
+
d = @default ? "(#@default)" : ""
|
81
|
+
"#@name:#{v}#{r}#{d}"
|
82
|
+
end
|
83
|
+
|
84
|
+
def boolean(value)
|
85
|
+
case value.class
|
86
|
+
when TrueClass, FalseClass
|
87
|
+
return value
|
88
|
+
else
|
89
|
+
return true if value.to_s =~ /^(1|t|true|y|yes)$/
|
90
|
+
return false if value.to_s =~ /^(0|f|false|n|no)$/
|
91
|
+
end
|
92
|
+
nil
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module Volley
|
2
|
+
module Dsl
|
3
|
+
module VolleyFile
|
4
|
+
class << self
|
5
|
+
def init
|
6
|
+
@loaded ||= { }
|
7
|
+
|
8
|
+
["/etc/Volleyfile", "~/.Volleyfile", "../../../../conf/common.volleyfile"].each do |f|
|
9
|
+
load(f, :optional => true)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def load(filename, options={ })
|
14
|
+
file = load_file(filename)
|
15
|
+
raise "cannot read file #{file}" unless file || options[:optional]
|
16
|
+
config.volleyfile = file if options[:primary]
|
17
|
+
true
|
18
|
+
end
|
19
|
+
|
20
|
+
def unload
|
21
|
+
@loaded = nil
|
22
|
+
end
|
23
|
+
|
24
|
+
# TOP LEVEL DSL METHODS
|
25
|
+
|
26
|
+
def config
|
27
|
+
Volley.config
|
28
|
+
end
|
29
|
+
|
30
|
+
def project(name, o={ }, &block)
|
31
|
+
Volley::Log.debug "project: #{name}"
|
32
|
+
Volley::Dsl::Project.project(name, o, &block)
|
33
|
+
end
|
34
|
+
|
35
|
+
def publisher(name, o={ }, &block)
|
36
|
+
Volley::Dsl::Publisher.publisher(name, o, &block)
|
37
|
+
end
|
38
|
+
|
39
|
+
def log(level, dest)
|
40
|
+
Volley::Log.add(level, dest)
|
41
|
+
end
|
42
|
+
|
43
|
+
def directory(dir)
|
44
|
+
Volley.config.directory = dir
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def load_file(filename)
|
50
|
+
@loaded ||= { }
|
51
|
+
@projects ||= { }
|
52
|
+
|
53
|
+
file = find_file(filename)
|
54
|
+
exists = file && File.file?(file)
|
55
|
+
Volley::Log.debug "LOAD: [#{exists}] #{filename} (#{file})"
|
56
|
+
return unless exists
|
57
|
+
@loaded[file] ||= instance_eval(File.read(file), file)
|
58
|
+
file
|
59
|
+
end
|
60
|
+
|
61
|
+
def find_file(filename)
|
62
|
+
[filename, File.expand_path(filename), File.expand_path(filename, __FILE__)].each do |f|
|
63
|
+
return f if File.file?(f)
|
64
|
+
end
|
65
|
+
nil
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/lib/volley/dsl/plan.rb
CHANGED
@@ -3,78 +3,73 @@ require 'tempfile'
|
|
3
3
|
module Volley
|
4
4
|
module Dsl
|
5
5
|
class Plan
|
6
|
-
attr_accessor :
|
6
|
+
attr_accessor :argv
|
7
|
+
attr_reader :project
|
8
|
+
attr_reader :stages
|
9
|
+
attr_reader :arguments
|
10
|
+
attr_reader :attributes
|
7
11
|
|
8
12
|
def initialize(name, o={ }, &block)
|
9
|
-
options
|
13
|
+
options = {
|
10
14
|
:name => name,
|
11
|
-
:output => false,
|
12
15
|
:project => nil,
|
16
|
+
:output => false,
|
13
17
|
:encrypt => false,
|
18
|
+
:remote => true,
|
14
19
|
:pack => true,
|
15
20
|
:pack_type => "tgz",
|
16
21
|
}.merge(o)
|
17
|
-
raise "project instance must be set" if options[:project].nil?
|
18
|
-
@project = options[:project]
|
19
|
-
@block = block
|
20
22
|
@attributes = OpenStruct.new(options)
|
21
|
-
@
|
22
|
-
|
23
|
-
@
|
24
|
-
@
|
23
|
+
raise "project instance must be set" if @attributes.project.nil?
|
24
|
+
|
25
|
+
@name = name.to_sym
|
26
|
+
@project = options[:project]
|
27
|
+
@block = block
|
28
|
+
@files = []
|
29
|
+
@arguments = { }
|
30
|
+
@argv = []
|
31
|
+
@stages = {
|
32
|
+
:pre => Volley::Dsl::Stage.new(:pre, :plan => self),
|
33
|
+
:main => Volley::Dsl::Stage.new(:main, :plan => self),
|
34
|
+
:post => Volley::Dsl::Stage.new(:post, :plan => self),
|
35
|
+
}
|
36
|
+
@stage_order = [:pre, :main, :post]
|
37
|
+
|
25
38
|
instance_eval &block if block_given?
|
26
39
|
|
27
|
-
|
28
|
-
|
40
|
+
if @attributes.remote
|
41
|
+
argument :descriptor, :required => true, :convert => :descriptor
|
42
|
+
else
|
43
|
+
argument :descriptor, :convert => :descriptor, :convert_opts => { :partial => true }
|
44
|
+
end
|
29
45
|
end
|
30
46
|
|
31
|
-
def call(options={})
|
32
|
-
@
|
33
|
-
|
34
|
-
|
35
|
-
run_actions
|
36
|
-
end
|
47
|
+
def call(options={ })
|
48
|
+
Volley::Log.debug "## #{@project.name} : #@name"
|
49
|
+
@origargs = options[:args]
|
50
|
+
data = @origargs
|
37
51
|
|
38
|
-
|
39
|
-
|
40
|
-
@
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
o = "%15s %15s %1s %s" % [n, t, (r ? '*' : ''), d]
|
47
|
-
out << "#{o}"
|
48
|
-
end
|
49
|
-
out
|
52
|
+
process_arguments(data)
|
53
|
+
|
54
|
+
raise "descriptor must be specified" if @attributes.remote && !args.descriptor
|
55
|
+
#raise "cannot determine branch" unless branch
|
56
|
+
#raise "cannot determine version" unless version
|
57
|
+
|
58
|
+
run_actions
|
59
|
+
[branch, version].join(":")
|
50
60
|
end
|
51
61
|
|
52
62
|
def usage
|
53
63
|
out = []
|
54
|
-
@
|
55
|
-
|
56
|
-
r = arg[:required]
|
57
|
-
d = arg[:default] ? "#{arg[:default]}" : ""
|
58
|
-
v = arg[:choices] ? "[#{arg[:choices].join(",")}]" : "<#{n}>"
|
59
|
-
out << "#{n}:#{v}#{"*" if r}"
|
64
|
+
@arguments.each do |n, arg|
|
65
|
+
out << arg.usage
|
60
66
|
end
|
61
67
|
out.join(" ")
|
62
68
|
end
|
63
69
|
|
64
70
|
def run_actions(*stages)
|
65
|
-
|
66
|
-
|
67
|
-
stages.each do |stage|
|
68
|
-
Volley::Log.debug "running actions[:#{stage}]:" if @actions[stage].count > 0
|
69
|
-
@actions[stage].each do |act|
|
70
|
-
Volley::Log.debug "running action: #{act[:name]}"
|
71
|
-
begin
|
72
|
-
self.instance_eval(&act[:block])
|
73
|
-
rescue => e
|
74
|
-
Volley::Log.info "error running action: #{act[:name]}: #{e.message} at #{e.backtrace.first}"
|
75
|
-
Volley::Log.debug e
|
76
|
-
end
|
77
|
-
end
|
71
|
+
@stage_order.each do |stage|
|
72
|
+
@stages[stage].call
|
78
73
|
end
|
79
74
|
end
|
80
75
|
|
@@ -84,51 +79,47 @@ module Volley
|
|
84
79
|
end
|
85
80
|
|
86
81
|
def args
|
87
|
-
@args
|
82
|
+
@args = OpenStruct.new(@arguments.inject({ }) { |h, e| (k, v)=e; h[k] = v.value; h })
|
88
83
|
end
|
89
84
|
|
90
85
|
def source
|
91
86
|
@project.source or raise "SCM not configured"
|
92
87
|
end
|
93
88
|
|
89
|
+
def remote(tf)
|
90
|
+
raise "remote can only be set to true or false" unless [true,false].include?(tf)
|
91
|
+
@attributes.remote = tf
|
92
|
+
end
|
93
|
+
|
94
|
+
def branch
|
95
|
+
(args.descriptor ? args.descriptor.branch : nil) || source.branch || nil
|
96
|
+
end
|
97
|
+
|
98
|
+
def version
|
99
|
+
v = args.descriptor ? args.descriptor.version : nil
|
100
|
+
if v == "latest"
|
101
|
+
v = source.revision || nil
|
102
|
+
end
|
103
|
+
v
|
104
|
+
end
|
105
|
+
|
106
|
+
def log(msg)
|
107
|
+
Volley::Log.info msg
|
108
|
+
end
|
109
|
+
|
94
110
|
def load(file)
|
95
|
-
|
96
|
-
Volley::VolleyFile.load(real)
|
111
|
+
Volley::Dsl.file(file)
|
97
112
|
rescue => e
|
98
113
|
Volley::Log.error "failed to load file: #{e.message}: #{file} (#{real})"
|
99
114
|
Volley::Log.debug e
|
100
115
|
end
|
101
116
|
|
102
|
-
def
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
if @argdata[n].nil?
|
109
|
-
if opts[:default].nil?
|
110
|
-
nil
|
111
|
-
else
|
112
|
-
opts[:default]
|
113
|
-
end
|
114
|
-
else
|
115
|
-
@argdata[n]
|
116
|
-
end
|
117
|
-
end
|
118
|
-
raise "arg '#{name}' is required, but not set" if opts[:required] && v.nil?
|
119
|
-
if opts[:convert]
|
120
|
-
if opts[:convert] == :boolean
|
121
|
-
v = boolean(v)
|
122
|
-
else
|
123
|
-
v = v.send(opts[:convert])
|
124
|
-
end
|
125
|
-
elsif block_given?
|
126
|
-
v = yield v
|
127
|
-
end
|
128
|
-
raise "arg '#{name}' is required, but not set (after convert)" if opts[:required] && v.nil?
|
129
|
-
@args.send("#{n}=", v)
|
130
|
-
@attributes.send("#{n}=", v) if opts[:attr]
|
131
|
-
end
|
117
|
+
def config
|
118
|
+
Volley.config
|
119
|
+
end
|
120
|
+
|
121
|
+
def argument(name, opts={ }, &block)
|
122
|
+
@arguments[name.to_sym] = Volley::Dsl::Argument.new(name, opts.merge(:plan => self), &block)
|
132
123
|
end
|
133
124
|
|
134
125
|
def output(tf=true)
|
@@ -141,145 +132,33 @@ module Volley
|
|
141
132
|
end
|
142
133
|
|
143
134
|
def action(name, stage=:main, &block)
|
144
|
-
|
145
|
-
|
135
|
+
@stages[stage].action(name, :plan => self, :stage => stage, &block)
|
136
|
+
#n = name.to_sym
|
137
|
+
#@actions[stage] << { :name => n, :stage => stage, :block => block }
|
146
138
|
end
|
147
139
|
|
148
|
-
def
|
149
|
-
|
150
|
-
list = begin
|
151
|
-
case block.arity
|
152
|
-
when 1
|
153
|
-
yield @attributes.dup
|
154
|
-
else
|
155
|
-
yield
|
156
|
-
end
|
157
|
-
end
|
158
|
-
list = [*list].flatten
|
159
|
-
notfound = list.reject { |f| File.exists?(f) }
|
160
|
-
raise "built files not found: #{notfound.join(",")}" unless notfound.count == 0
|
161
|
-
@attributes.artifact_list = list
|
162
|
-
@attributes.artifact_list << Volley.config.volleyfile
|
163
|
-
end
|
164
|
-
|
165
|
-
if @attributes.pack
|
166
|
-
action :pack, :post do
|
167
|
-
path = @attributes.pack_dir = "/var/tmp/volley-#{Time.now.to_i}-#{$$}"
|
168
|
-
Dir.mkdir(path)
|
169
|
-
dir = Dir.pwd
|
170
|
-
|
171
|
-
@attributes.artifact_list.each do |art|
|
172
|
-
if art =~ /^\// && art !~ /^#{dir}/
|
173
|
-
# file is full path and not in current directory
|
174
|
-
source = art
|
175
|
-
dest = "#{path}/#{File.basename(art)}"
|
176
|
-
else
|
177
|
-
# file is relative path or in current directory
|
178
|
-
f = art.gsub(/^#{dir}/, "").gsub(/^\//, "")
|
179
|
-
source = "#{dir}/#{f}"
|
180
|
-
dest = "#{path}/#{f}"
|
181
|
-
end
|
182
|
-
|
183
|
-
begin
|
184
|
-
Volley::Log.debug "pack file: #{source} => #{dest}"
|
185
|
-
FileUtils.mkdir_p(File.dirname(dest))
|
186
|
-
if File.directory?(source)
|
187
|
-
FileUtils.cp_r(source, dest)
|
188
|
-
else
|
189
|
-
FileUtils.copy(source, dest)
|
190
|
-
end
|
191
|
-
rescue => e
|
192
|
-
raise "could not copy file #{source}: #{e.message}"
|
193
|
-
end
|
194
|
-
end
|
195
|
-
|
196
|
-
origpath = Dir.pwd
|
197
|
-
Dir.chdir(path)
|
198
|
-
case @attributes.pack_type
|
199
|
-
when "tgz"
|
200
|
-
n = "#{args.branch}-#{args.version}.tgz"
|
201
|
-
c = "tar cvfz #{n} *"
|
202
|
-
Volley::Log.debug "command:#{c}"
|
203
|
-
shellout(c)
|
204
|
-
|
205
|
-
@attributes.artifact = "#{path}/#{n}"
|
206
|
-
else
|
207
|
-
raise "unknown pack type '#{@attributes.pack_type}'"
|
208
|
-
end
|
209
|
-
|
210
|
-
Dir.chdir(origpath)
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
if @attributes.encrypt
|
215
|
-
action :encrypt, :post do
|
216
|
-
art = @attributes.artifact
|
217
|
-
key = @attributes.encrypt_key
|
218
|
-
cpt = "#{art}.cpt"
|
219
|
-
|
220
|
-
raise "in action encrypt: artifact file does not exist: #{art}" unless File.file?(art)
|
221
|
-
raise "in action encrypt: encrypted file #{cpt} already exists" if File.file?(cpt) && !@attributes.encrypt_overwrite
|
222
|
-
shellout("ccrypt -e --key '#{key}' #{art}")
|
223
|
-
|
224
|
-
@attributes.artifact_unencrypted = art
|
225
|
-
@attributes.artifact = cpt
|
226
|
-
end
|
227
|
-
end
|
228
|
-
|
229
|
-
action :push, :post do
|
230
|
-
publisher = Volley::Dsl.publisher
|
231
|
-
publisher.push(@project.name, args.branch, args.version, @attributes.artifact)
|
232
|
-
end
|
140
|
+
def file(file)
|
141
|
+
@files << file
|
233
142
|
end
|
234
143
|
|
235
|
-
def
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
action :download do
|
243
|
-
pr = @project.name
|
244
|
-
br = args.branch
|
245
|
-
ve = args.version
|
246
|
-
|
247
|
-
pub = Volley::Dsl.publisher
|
248
|
-
file = pub.pull(pr, br, ve)
|
249
|
-
|
250
|
-
dir = File.dirname(file)
|
251
|
-
Volley::Log.info "changing directory: #{dir} (#{file})"
|
252
|
-
end
|
253
|
-
|
254
|
-
action :unpack do
|
255
|
-
FileUtils.mkdir_p("#{dir}/unpack")
|
256
|
-
Dir.chdir("#{dir}/unpack")
|
257
|
-
tgz = %x{tar xvfz #{file} 2>/dev/null}
|
258
|
-
File.open("#{dir}/tgz.log", "w") {|f| f.write(tgz)}
|
144
|
+
def files(*list)
|
145
|
+
list = [*list].flatten
|
146
|
+
if @files.count > 0 && list.count > 0
|
147
|
+
Volley::Log.warn "overriding file list"
|
148
|
+
Volley::Log.debug "files: #{@files.inspect}"
|
149
|
+
Volley::Log.debug "new: #{list.inspect}"
|
259
150
|
end
|
151
|
+
@files = list if list.count > 0
|
152
|
+
@files
|
153
|
+
end
|
260
154
|
|
261
|
-
|
262
|
-
|
263
|
-
end
|
155
|
+
def push(&block)
|
156
|
+
Volley::Dsl::PushAction.new(:push_dummy, :plan => self, :stage => :main, &block)
|
264
157
|
end
|
265
158
|
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
# :branch => args.branch,
|
270
|
-
# :version => "latest",
|
271
|
-
# :plan => "pull",
|
272
|
-
# }.merge(opts)
|
273
|
-
#
|
274
|
-
# desc = [o[:project], o[:branch], o[:version], o[:plan]].compact.join(":")
|
275
|
-
# actionname = "volley-#{desc}"
|
276
|
-
# action actionname do
|
277
|
-
# Volley::Log.info "VOLLEY: #{desc}"
|
278
|
-
# cmd = ["volley"]
|
279
|
-
# cmd << desc
|
280
|
-
# shellout(cmd.join(" "), :output => true)
|
281
|
-
# end
|
282
|
-
#end
|
159
|
+
def pull(&block)
|
160
|
+
Volley::Dsl::PullAction.new(:pull_dummy, :plan => self, :stage => :main, &block)
|
161
|
+
end
|
283
162
|
|
284
163
|
def volley(opts={ })
|
285
164
|
o = {
|
@@ -288,7 +167,8 @@ module Volley
|
|
288
167
|
}.merge(opts)
|
289
168
|
|
290
169
|
action "volley-#{o[:project]}-#{o[:plan]}" do
|
291
|
-
|
170
|
+
options = { :plan => "#{project}:#{plan}", :descriptor => "#{project}@#{branch}:#{version}", :args => @origargs }.merge(o)
|
171
|
+
Volley.process(options)
|
292
172
|
end
|
293
173
|
end
|
294
174
|
|
@@ -301,9 +181,9 @@ module Volley
|
|
301
181
|
|
302
182
|
def shellout(*args)
|
303
183
|
require "mixlib/shellout"
|
304
|
-
opts
|
184
|
+
opts = args.last.is_a?(Hash) ? args.pop : { }
|
305
185
|
options = {
|
306
|
-
:output
|
186
|
+
:output => @attributes.output,
|
307
187
|
:prepend => ">> ",
|
308
188
|
}.merge(opts)
|
309
189
|
command = ::Mixlib::ShellOut.new(*args)
|
@@ -315,27 +195,22 @@ module Volley
|
|
315
195
|
end
|
316
196
|
|
317
197
|
private
|
318
|
-
|
319
|
-
def boolean(value)
|
320
|
-
case value.class
|
321
|
-
when TrueClass, FalseClass
|
322
|
-
return value
|
323
|
-
else
|
324
|
-
return true if value =~ /^(1|t|true|y|yes)$/
|
325
|
-
return false if value =~ /^(0|f|false|n|no)$/
|
326
|
-
end
|
327
|
-
nil
|
328
|
-
end
|
329
|
-
|
330
198
|
def process_arguments(raw)
|
331
|
-
Volley::Log.debug "process arguments: #{raw.inspect}"
|
199
|
+
Volley::Log.debug ".. process arguments: #{raw.inspect}"
|
332
200
|
if raw
|
333
|
-
kvs
|
334
|
-
raw
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
201
|
+
kvs = raw.select { |e| e =~ /\=/ }
|
202
|
+
raw = raw.reject { |e| e =~ /\=/ }
|
203
|
+
@argv = raw
|
204
|
+
kvs.each do |a|
|
205
|
+
(k, v) = a.split(/\=/)
|
206
|
+
if @arguments[k.to_sym]
|
207
|
+
Volley::Log.debug ".. .. setting argument: #{k} = #{v}"
|
208
|
+
@arguments[k.to_sym].value = v
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
@arguments.each do |k, v|
|
213
|
+
v.check
|
339
214
|
end
|
340
215
|
end
|
341
216
|
end
|
data/lib/volley/dsl/project.rb
CHANGED
@@ -8,7 +8,7 @@ module Volley
|
|
8
8
|
n = name.to_sym
|
9
9
|
@projects ||= {}
|
10
10
|
if @projects[n]
|
11
|
-
|
11
|
+
raise "defining project #{name} more than once"
|
12
12
|
else
|
13
13
|
@projects[n] = new(n)
|
14
14
|
@projects[n].instance_eval &block if block_given?
|
@@ -28,6 +28,10 @@ module Volley
|
|
28
28
|
n = name.to_sym
|
29
29
|
@projects.keys.include?(n)
|
30
30
|
end
|
31
|
+
|
32
|
+
def unload
|
33
|
+
@projects = nil
|
34
|
+
end
|
31
35
|
end
|
32
36
|
|
33
37
|
attr_reader :plans
|
@@ -40,7 +44,11 @@ module Volley
|
|
40
44
|
end
|
41
45
|
|
42
46
|
def config
|
43
|
-
|
47
|
+
Volley.config
|
48
|
+
end
|
49
|
+
|
50
|
+
def log(msg)
|
51
|
+
Volley::Log.info msg
|
44
52
|
end
|
45
53
|
|
46
54
|
def plan(name, o={}, &block)
|
@@ -0,0 +1,50 @@
|
|
1
|
+
|
2
|
+
module Volley
|
3
|
+
module Dsl
|
4
|
+
class PullAction < Action
|
5
|
+
def initialize(name, options={}, &block)
|
6
|
+
@name = name.to_sym
|
7
|
+
@stage = options.delete(:stage)
|
8
|
+
@plan = options.delete(:plan)
|
9
|
+
#@block = block
|
10
|
+
@options = {
|
11
|
+
}.merge(options)
|
12
|
+
raise "stage instance must be set" unless @stage
|
13
|
+
raise "plan instance must be set" unless @plan
|
14
|
+
|
15
|
+
dir = nil
|
16
|
+
file = nil
|
17
|
+
|
18
|
+
@plan.action :download do
|
19
|
+
pr = project.name
|
20
|
+
br = branch
|
21
|
+
ve = version
|
22
|
+
|
23
|
+
pub = Volley::Dsl.publisher
|
24
|
+
raise "publisher must be defined" unless pub
|
25
|
+
file = pub.pull(pr, br, ve)
|
26
|
+
|
27
|
+
dir = File.dirname(file)
|
28
|
+
end
|
29
|
+
|
30
|
+
@plan.action :unpack do
|
31
|
+
FileUtils.mkdir_p("#{dir}/unpack")
|
32
|
+
Volley::Log.info "changing directory: #{dir} (#{file})"
|
33
|
+
Dir.chdir("#{dir}/unpack")
|
34
|
+
tgz = %x{tar xvfz #{file} 2>/dev/null}
|
35
|
+
File.open("#{dir}/tgz.log", "w") { |f| f.write(tgz) }
|
36
|
+
end
|
37
|
+
|
38
|
+
@plan.action :run do
|
39
|
+
raise "failed to unpack: #{dir}/unpack" unless dir && File.directory?("#{dir}/unpack")
|
40
|
+
yield "#{dir}/unpack"
|
41
|
+
end
|
42
|
+
|
43
|
+
@plan.action :meta do
|
44
|
+
Volley.meta[project.name] = "#{args.descriptor.branch}:#{args.descriptor.version}"
|
45
|
+
Volley.meta.save
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|