Class: Volley::Dsl::PushAction
- Defined in:
- lib/volley/dsl/push_action.rb
Instance Attribute Summary
Attributes inherited from Action
Instance Method Summary collapse
-
#initialize(name, options = {}, &block) ⇒ PushAction
constructor
A new instance of PushAction.
Methods inherited from Action
Constructor Details
#initialize(name, options = {}, &block) ⇒ PushAction
Returns a new instance of PushAction.
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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 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 |
# File 'lib/volley/dsl/push_action.rb', line 6 def initialize(name, ={}, &block) @name = name.to_sym @stage = .delete(:stage) @plan = .delete(:plan) @options = { project: nil, branch: nil, version: nil, }.merge() raise "stage instance must be set" unless @stage raise "plan instance must be set" unless @plan @plan.action :check, :pre do raise "branch(#{branch}) and version(#{version}) must be specified" unless branch && version p = @plan.project.name b = branch v = version if Volley::Dsl.publisher.exists?(p, b, v) log ".. artifact exists: #{p}@#{b}:#{v}" @plan.stop unless args.force end end @plan.action :files, :main do raise "branch(#{branch}) and version(#{version}) must be specified" unless branch && version list = yield if block list = [*list].flatten # use #exists? so it can work for directories notfound = list.reject { |f| File.exists?(f) } raise "built files not found: #{notfound.join(",")}" unless notfound.count == 0 files list file Volley.config.volleyfile if Volley.config.volleyfile end if attributes.pack @plan.action :pack, :post do raise "branch(#{branch}) and version(#{version}) must be specified" unless branch && version path = attributes.pack_dir = "/var/tmp/volley-%d-%d-%05d" % [Time.now.to_i, $$, rand(99999)] Dir.mkdir(path) dir = Dir.pwd Volley::Log.debug ".. files: #{files.inspect}" files.each do |art| next unless art if art =~ /^\// && art !~ /^#{dir}/ # file is full path and not in current directory source = art dest = "#{path}/#{File.basename(art)}" else # file is relative path or in current directory f = art.gsub(/^#{dir}/, "").gsub(/^\//, "") source = "#{dir}/#{f}" dest = "#{path}/#{f}" end begin FileUtils.mkdir_p(File.dirname(dest)) if File.directory?(source) FileUtils.cp_r(source, dest) else FileUtils.copy(source, dest) end rescue => e raise "could not copy file #{source}: #{e.}" end end origpath = Dir.pwd Dir.chdir(path) case attributes.pack_type when "tgz" n = "#{branch}-#{version}.tgz" c = "tar cvfz #{n} *" Volley::Log.debug "command:#{c}" command(c) attributes.artifact = "#{path}/#{n}" else raise "unknown pack type '#{attributes.pack_type}'" end Dir.chdir(origpath) end end if attributes.encrypt @plan.action :encrypt, :post do art = attributes.artifact key = attributes.encrypt_key cpt = "#{art}.cpt" raise "in action encrypt: artifact file does not exist: #{art}" unless File.file?(art) raise "in action encrypt: encrypted file #{cpt} already exists" if File.file?(cpt) && !attributes.encrypt_overwrite shellout("ccrypt -e --key '#{key}' #{art}") attributes.artifact_unencrypted = art attributes.artifact = cpt end end @plan.action :push, :post do publisher = Volley::Dsl.publisher publisher.push([:project] || project.name, [:branch] || branch, [:version] || version, attributes.artifact) end end |