vx-builder 0.1.8 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -1
  3. data/lib/vx/builder/build_configuration.rb +9 -6
  4. data/lib/vx/builder/build_configuration/deploy.rb +22 -13
  5. data/lib/vx/builder/build_configuration/deploy/provider.rb +58 -0
  6. data/lib/vx/builder/configuration.rb +1 -1
  7. data/lib/vx/builder/matrix.rb +14 -0
  8. data/lib/vx/builder/script.rb +32 -7
  9. data/lib/vx/builder/script/artifacts.rb +1 -3
  10. data/lib/vx/builder/script/base.rb +56 -0
  11. data/lib/vx/builder/script/clojure.rb +5 -9
  12. data/lib/vx/builder/script/deploy.rb +40 -0
  13. data/lib/vx/builder/script/env.rb +1 -3
  14. data/lib/vx/builder/script/java.rb +5 -5
  15. data/lib/vx/builder/script/ruby.rb +20 -15
  16. data/lib/vx/builder/script/scala.rb +11 -13
  17. data/lib/vx/builder/script/script.rb +19 -8
  18. data/lib/vx/builder/script/services.rb +1 -3
  19. data/lib/vx/builder/task.rb +5 -0
  20. data/lib/vx/builder/version.rb +1 -1
  21. data/spec/fixtures/integration/ruby/deploy/config.yml +12 -0
  22. data/spec/fixtures/integration/ruby/deploy/d.after_script.sh +10 -0
  23. data/spec/fixtures/integration/ruby/deploy/d.before_script.sh +61 -0
  24. data/spec/fixtures/integration/ruby/deploy/d.script.sh +4 -0
  25. data/spec/fixtures/integration/ruby/language/after_script.sh +10 -0
  26. data/spec/fixtures/integration/ruby/language/before_script.sh +59 -0
  27. data/spec/fixtures/integration/ruby/language/config.yml +1 -0
  28. data/spec/fixtures/integration/ruby/language/script.sh +8 -0
  29. data/spec/fixtures/integration/ruby/matrix/0.after_script.sh +10 -0
  30. data/spec/fixtures/integration/ruby/matrix/0.before_script.sh +61 -0
  31. data/spec/fixtures/integration/ruby/matrix/0.script.sh +6 -0
  32. data/spec/fixtures/integration/ruby/matrix/1.after_script.sh +10 -0
  33. data/spec/fixtures/integration/ruby/matrix/1.before_script.sh +61 -0
  34. data/spec/fixtures/integration/ruby/matrix/1.script.sh +6 -0
  35. data/spec/fixtures/integration/ruby/matrix/config.yml +11 -0
  36. data/spec/fixtures/integration/ruby/matrix/d.after_script.sh +10 -0
  37. data/spec/fixtures/integration/ruby/matrix/d.before_script.sh +59 -0
  38. data/spec/fixtures/integration/ruby/matrix/d.script.sh +4 -0
  39. data/spec/fixtures/travis.yml +3 -0
  40. data/spec/integration/ruby_spec.rb +159 -0
  41. data/spec/lib/builder/build_configuration_spec.rb +31 -0
  42. data/spec/lib/builder/matrix_spec.rb +59 -0
  43. data/spec/lib/builder/task_spec.rb +2 -1
  44. data/spec/support/create.rb +14 -11
  45. data/vx-builder.gemspec +1 -1
  46. metadata +48 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b8f98b349ac5e5f3a102fcd18a48ff2ca2f4c981
4
- data.tar.gz: 94227f045bda9344db2dd491f850fec6454713eb
3
+ metadata.gz: 4f388f5d51a408009ccf40e8f4d3d7a335e64e49
4
+ data.tar.gz: 90887f071d58925f1c82395380b43d6d20368cb7
5
5
  SHA512:
6
- metadata.gz: ffd85365e4386368d2876160ce25ab21a0fd1e03c5036c12d95c16ffc75de84aef87855e1f8ab2c738a56c20b9c66f6bc7fbc53627a5b918cf497eb3022dc283
7
- data.tar.gz: 70166faee2d5f3c6afd12180b547c27cdb1a2ccbcfc13f5e2a93440eedb044610bc00e9479b09e72508831df4e71efdc4a822dd46e4c34c24ea80045724d2e95
6
+ metadata.gz: 0f5f92fb3b91936043982b9f5c532d6058465f9f5b4df6f707e6fa358bb55157afedb5226b8c4e44de0732986bf78fae85009359a3dcdefe5f7d690e332a3d15
7
+ data.tar.gz: 46de92052fb9323fa78825693d568b78da5b03d2ce5e85ad0008ce4adadce5e9eb9c78e798f8185a809725ce3e89edc15b82be4b6c6b2dc46896faf5eadc5385
data/.travis.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  rvm:
2
2
  - 2.0.0
3
- - 2.1.0
3
+ - 2.1.2
4
4
 
5
5
  script: bundle exec rake
@@ -1,6 +1,6 @@
1
1
  require 'yaml'
2
2
 
3
- Dir[File.expand_path("../build_configuration/*.rb", __FILE__)].each do |f|
3
+ Dir[File.expand_path("../build_configuration/**/*.rb", __FILE__)].each do |f|
4
4
  require f
5
5
  end
6
6
 
@@ -23,6 +23,9 @@ module Vx
23
23
  before_script
24
24
  script
25
25
  after_success
26
+
27
+ before_deploy
28
+ after_deploy
26
29
  }
27
30
 
28
31
  class << self
@@ -38,7 +41,7 @@ module Vx
38
41
  end
39
42
  end
40
43
 
41
- attr_reader :env, :cache, :artifacts, :deploy
44
+ attr_reader :env, :cache, :artifacts, :deploy, :attributes
42
45
 
43
46
  def initialize(new_attributes = {}, matrix_attributes = {})
44
47
  new_attributes = {} unless new_attributes.is_a?(Hash)
@@ -70,6 +73,10 @@ module Vx
70
73
  !deploy.attributes.empty?
71
74
  end
72
75
 
76
+ def deploy_attributes= (val)
77
+ @deploy = Deploy.new(val)
78
+ end
79
+
73
80
  # for tests
74
81
  def matrix_id
75
82
  matrix_attributes.to_a.map{|i| i.join(":") }.sort.join(", ")
@@ -106,10 +113,6 @@ module Vx
106
113
 
107
114
  private
108
115
 
109
- def attributes
110
- @attributes
111
- end
112
-
113
116
  def build_attributes(new_attributes)
114
117
  @attributes = ATTRIBUTES.inject({}) do |ac, attribute_name|
115
118
  attribute = new_attributes[attribute_name]
@@ -6,17 +6,22 @@ module Vx
6
6
  attr_reader :attributes
7
7
 
8
8
  def initialize(new_env)
9
- normalize_attributes(new_env)
9
+ normalize(new_env)
10
+ end
11
+
12
+ def attributes
13
+ @attributes
10
14
  end
11
15
 
12
16
  def providers
13
- @providers
17
+ @providers ||= @attributes.map do |a|
18
+ Deploy::Provider.new(a)
19
+ end
14
20
  end
15
- alias :attributes :providers
16
21
 
17
22
  private
18
23
 
19
- def normalize_attributes(new_env)
24
+ def normalize(new_env)
20
25
  attrs =
21
26
  case new_env
22
27
  when Array
@@ -24,22 +29,26 @@ module Vx
24
29
  when Hash
25
30
  [new_env]
26
31
  when String
27
- [{"command" => new_env}]
32
+ [new_env]
28
33
  else
29
34
  []
30
35
  end
31
36
 
32
- extract_options_and_normalize_items(attrs)
37
+ normalize_each(attrs)
33
38
  end
34
39
 
35
- def extract_options_and_normalize_items(new_env)
36
- @providers = []
40
+ def normalize_each(new_env)
41
+ @attributes = []
37
42
  new_env.each do |env|
38
- case
39
- when env["provider"]
40
- @providers.push env
41
- when env["command"]
42
- @providers.push env.merge("provider" => "shell")
43
+ case env
44
+ when Hash
45
+ if env["provider"]
46
+ @attributes.push env
47
+ else
48
+ @attributes.push env.merge("provider" => "shell")
49
+ end
50
+ when String
51
+ @attributes.push("provider" => "shell", "command" => env)
43
52
  end
44
53
  end
45
54
  end
@@ -0,0 +1,58 @@
1
+ module Vx
2
+ module Builder
3
+ class BuildConfiguration
4
+ class Deploy
5
+
6
+ class Provider
7
+
8
+ attr_reader :name, :options, :on
9
+
10
+ def initialize(new_attributes)
11
+ normalize new_attributes.dup
12
+ end
13
+
14
+ def branch?(branch)
15
+ return true if on.empty?
16
+ on.include?(branch)
17
+ end
18
+
19
+ def to_hash
20
+ options.merge(
21
+ "provider" => @name,
22
+ "branch" => on
23
+ )
24
+ end
25
+
26
+ def shell?
27
+ @name == 'shell'
28
+ end
29
+
30
+ def command
31
+ Array(options["command"])
32
+ end
33
+
34
+ private
35
+
36
+ def normalize(new_attributes)
37
+ @name = new_attributes.delete("provider")
38
+ @on = new_attributes.delete("branch")
39
+ @options = new_attributes
40
+
41
+ @on =
42
+ case @on
43
+ when String
44
+ [@on]
45
+ when Array
46
+ @on.map(&:to_s)
47
+ else
48
+ []
49
+ end
50
+
51
+ end
52
+
53
+ end
54
+
55
+ end
56
+ end
57
+ end
58
+ end
@@ -9,7 +9,7 @@ module Vx
9
9
  self.env_namespace = 'vx'
10
10
  self.raise_missing_keys = true
11
11
 
12
- define casher_ruby: "/opt/rbenv/versions/1.9.3-p545/bin/ruby"
12
+ define casher_ruby: "/opt/rbenv/versions/1.9.3-p547/bin/ruby"
13
13
 
14
14
  end
15
15
  end
@@ -24,6 +24,20 @@ module Vx
24
24
  end
25
25
  end
26
26
 
27
+ def deploy_configuration(branch)
28
+ return unless build_configuration.deploy?
29
+
30
+ availabled_providers = build_configuration.deploy.providers.select do |provider|
31
+ provider.branch?(branch)
32
+ end
33
+
34
+ unless availabled_providers.empty?
35
+ build_configurations.first.dup.tap do |config|
36
+ config.deploy_attributes = availabled_providers.map(&:to_hash)
37
+ end
38
+ end
39
+ end
40
+
27
41
  def attributes_for_new_build_configurations_with_merged_env
28
42
  attrs = attributes_for_new_build_configurations
29
43
  attrs = [{}] if attrs.empty?
@@ -4,6 +4,7 @@ module Vx
4
4
  module Builder
5
5
  class Script
6
6
 
7
+ autoload :Base, File.expand_path("../script/base", __FILE__)
7
8
  autoload :Env, File.expand_path("../script/env", __FILE__)
8
9
  autoload :Ruby, File.expand_path("../script/ruby", __FILE__)
9
10
  autoload :Java, File.expand_path("../script/java", __FILE__)
@@ -15,6 +16,7 @@ module Vx
15
16
  autoload :Cache, File.expand_path("../script/cache", __FILE__)
16
17
  autoload :Services, File.expand_path("../script/services", __FILE__)
17
18
  autoload :Artifacts, File.expand_path("../script/artifacts", __FILE__)
19
+ autoload :Deploy, File.expand_path("../script/deploy", __FILE__)
18
20
 
19
21
  include Common::Helper::Middlewares
20
22
 
@@ -28,6 +30,7 @@ module Vx
28
30
  use Builder::Script::Scala
29
31
  use Builder::Script::Clojure
30
32
  use Builder::Script::Ruby
33
+ use Builder::Script::Deploy
31
34
  use Builder::Script::Script
32
35
  end
33
36
 
@@ -56,8 +59,13 @@ module Vx
56
59
  a << "\n# install"
57
60
  a += env.install
58
61
 
59
- a << "\n# before script"
62
+ if deploy?
63
+ a << "\n# before deploy"
64
+ else
65
+ a << "\n# before script"
66
+ end
60
67
  a += env.before_script
68
+
61
69
  a.join("\n")
62
70
  end
63
71
 
@@ -65,22 +73,36 @@ module Vx
65
73
  a = []
66
74
  a << "\n# after script init"
67
75
  a += env.after_script_init
68
- a << "\n# after script"
76
+
77
+ if deploy?
78
+ a << "\n# after deploy"
79
+ else
80
+ a << "\n# after script"
81
+ end
69
82
  a += env.after_script
70
83
  a.join("\n")
71
84
  end
72
85
 
73
86
  def to_script
74
87
  a = []
75
- a << "\n# script"
76
- a += env.script
77
-
78
- a << "\n# after success"
79
- a += env.after_success
88
+ if deploy?
89
+ a << "\n# deploy"
90
+ a += env.deploy
91
+ else
92
+ a << "\n# script"
93
+ a += env.script
94
+
95
+ a << "\n# after success"
96
+ a += env.after_success
97
+ end
80
98
 
81
99
  a.join("\n")
82
100
  end
83
101
 
102
+ def deploy?
103
+ task.deploy?
104
+ end
105
+
84
106
  private
85
107
 
86
108
  def env
@@ -108,6 +130,9 @@ module Vx
108
130
  after_script_init: [],
109
131
  after_script: [],
110
132
 
133
+ before_deploy: [],
134
+ deploy: [],
135
+
111
136
  source: source,
112
137
  task: task,
113
138
  cache_key: [],
@@ -2,9 +2,7 @@ module Vx
2
2
  module Builder
3
3
  class Script
4
4
 
5
- Artifacts = Struct.new(:app) do
6
-
7
- include Helper::TraceShCommand
5
+ class Artifacts < Base
8
6
 
9
7
  FIND='find . -type f -path "./%s" | sed "s/^\.\///g"'
10
8
 
@@ -0,0 +1,56 @@
1
+ module Vx
2
+ module Builder
3
+ class Script
4
+
5
+ Base = Struct.new(:app) do
6
+
7
+ include Helper::TraceShCommand
8
+
9
+ def do_cache_key(env)
10
+ yield env.cache_key
11
+ end
12
+
13
+ def do_script(env)
14
+ if env.source.script.empty?
15
+ yield env.script
16
+ end
17
+ end
18
+
19
+ def do_cached_directories(env)
20
+ if env.source.cached_directories != false
21
+ yield env.cached_directories
22
+ end
23
+ end
24
+
25
+ def do_announce(env)
26
+ yield env.announce
27
+ end
28
+
29
+ def do_before_install(env)
30
+ yield env.before_install
31
+ end
32
+
33
+ def do_install(env)
34
+ yield env.install
35
+ end
36
+
37
+ def do_before_deploy(env)
38
+ yield env.before_deploy
39
+ end
40
+
41
+ def do_after_deploy(env)
42
+ yield env.after_deploy
43
+ end
44
+
45
+ def do_deploy(env)
46
+ yield env.deploy
47
+ end
48
+
49
+ def deploy?
50
+ env.task.deploy?
51
+ end
52
+ end
53
+
54
+ end
55
+ end
56
+ end
@@ -2,24 +2,20 @@ module Vx
2
2
  module Builder
3
3
  class Script
4
4
 
5
- Clojure = Struct.new(:app) do
6
-
7
- include Helper::TraceShCommand
5
+ class Clojure < Base
8
6
 
9
7
  def call(env)
10
8
  if enabled?(env)
11
- env.announce.tap do |i|
9
+ do_announce(env) do |i|
12
10
  i << trace_sh_command("lein version")
13
11
  end
14
12
 
15
- env.install.tap do |i|
13
+ do_install(env) do |i|
16
14
  i << trace_sh_command("lein deps")
17
15
  end
18
16
 
19
- if env.source.script.empty?
20
- env.script.tap do |i|
21
- i << trace_sh_command("lein test")
22
- end
17
+ do_script(env) do |i|
18
+ i << trace_sh_command("lein test")
23
19
  end
24
20
  end
25
21
 
@@ -0,0 +1,40 @@
1
+ module Vx
2
+ module Builder
3
+ class Script
4
+
5
+ class Deploy < Base
6
+
7
+ def call(env)
8
+ if enabled?(env)
9
+ env.source.deploy.providers.each do |provider|
10
+ if provider.shell?
11
+ deploy_using_shell(env, provider)
12
+ end
13
+ end
14
+ end
15
+
16
+ do_before_deploy(env) do |i|
17
+ i += env.source.before_deploy
18
+ end
19
+
20
+ app.call(env)
21
+ end
22
+
23
+ private
24
+
25
+ def enabled?(env)
26
+ env.task.deploy? && env.source.deploy?
27
+ end
28
+
29
+ def deploy_using_shell(env, provider)
30
+ do_deploy(env) do |i|
31
+ provider.command.each do |cmd|
32
+ i << trace_sh_command(cmd)
33
+ end
34
+ end
35
+ end
36
+
37
+ end
38
+ end
39
+ end
40
+ end