vx-builder 0.2.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/lib/vx/builder.rb +15 -2
  3. data/lib/vx/builder/build_configuration.rb +12 -13
  4. data/lib/vx/builder/build_configuration/deploy.rb +10 -17
  5. data/lib/vx/builder/build_configuration/deploy/base.rb +64 -0
  6. data/lib/vx/builder/build_configuration/deploy/shell.rb +21 -0
  7. data/lib/vx/builder/build_configuration/env.rb +11 -4
  8. data/lib/vx/builder/deploy_builder.rb +59 -0
  9. data/lib/vx/builder/{matrix.rb → matrix_builder.rb} +8 -20
  10. data/lib/vx/builder/script_builder.rb +127 -0
  11. data/lib/vx/builder/script_builder/base.rb +59 -0
  12. data/lib/vx/builder/{script/base.rb → script_builder/base.rb-e} +13 -10
  13. data/lib/vx/builder/{script/artifacts.rb → script_builder/cache.rb} +13 -30
  14. data/lib/vx/builder/{script/cache.rb → script_builder/cache.rb-e} +0 -0
  15. data/lib/vx/builder/script_builder/clojure.rb +34 -0
  16. data/lib/vx/builder/{script/clojure.rb → script_builder/clojure.rb-e} +0 -0
  17. data/lib/vx/builder/script_builder/deploy.rb +34 -0
  18. data/lib/vx/builder/script_builder/deploy.rb-e +34 -0
  19. data/lib/vx/builder/script_builder/env.rb +39 -0
  20. data/lib/vx/builder/{script/env.rb → script_builder/env.rb-e} +0 -0
  21. data/lib/vx/builder/script_builder/java.rb +31 -0
  22. data/lib/vx/builder/{script/java.rb → script_builder/java.rb-e} +0 -0
  23. data/lib/vx/builder/script_builder/prepare.rb +72 -0
  24. data/lib/vx/builder/{script/prepare.rb → script_builder/prepare.rb-e} +0 -0
  25. data/lib/vx/builder/script_builder/ruby.rb +80 -0
  26. data/lib/vx/builder/{script/ruby.rb → script_builder/ruby.rb-e} +0 -0
  27. data/lib/vx/builder/script_builder/scala.rb +50 -0
  28. data/lib/vx/builder/{script/scala.rb → script_builder/scala.rb-e} +0 -0
  29. data/lib/vx/builder/script_builder/script.rb +32 -0
  30. data/lib/vx/builder/script_builder/script.rb-e +32 -0
  31. data/lib/vx/builder/script_builder/services.rb +26 -0
  32. data/lib/vx/builder/{script/services.rb → script_builder/services.rb-e} +0 -0
  33. data/lib/vx/builder/task.rb +1 -7
  34. data/lib/vx/builder/version.rb +1 -1
  35. data/spec/fixtures/integration/ruby/deploy/config.yml +6 -2
  36. data/spec/fixtures/integration/ruby/deploy/d.after_script.sh +1 -1
  37. data/spec/fixtures/integration/ruby/deploy/d.before_script.sh +3 -1
  38. data/spec/fixtures/integration/ruby/deploy/d.script.sh +6 -2
  39. data/spec/fixtures/integration/ruby/matrix/config.yml +4 -1
  40. data/spec/fixtures/integration/ruby/matrix/d.after_script.sh +1 -1
  41. data/spec/fixtures/integration/ruby/matrix/d.before_script.sh +1 -1
  42. data/spec/fixtures/integration/ruby/matrix/d.script.sh +6 -2
  43. data/spec/fixtures/travis.yml +2 -7
  44. data/spec/integration/ruby_spec.rb +14 -19
  45. data/spec/lib/builder/build_configuration/cache_spec.rb +35 -0
  46. data/spec/lib/builder/build_configuration/deploy/base_spec.rb +33 -0
  47. data/spec/lib/builder/build_configuration/deploy/shell_spec.rb +61 -0
  48. data/spec/lib/builder/build_configuration/deploy_spec.rb +50 -0
  49. data/spec/lib/builder/build_configuration/env_spec.rb +43 -0
  50. data/spec/lib/builder/build_configuration_spec.rb +4 -124
  51. data/spec/lib/builder/deploy_builder_spec.rb +82 -0
  52. data/spec/lib/builder/{matrix_spec.rb → matrix_builder_spec.rb} +9 -67
  53. data/spec/lib/builder/{script → script_builder}/cache_spec.rb +1 -1
  54. data/spec/lib/builder/{script → script_builder}/clojure_spec.rb +1 -1
  55. data/spec/lib/builder/{script → script_builder}/env_spec.rb +1 -1
  56. data/spec/lib/builder/{script → script_builder}/java_spec.rb +1 -1
  57. data/spec/lib/builder/{script → script_builder}/prepare_spec.rb +2 -2
  58. data/spec/lib/builder/{script → script_builder}/ruby_spec.rb +1 -1
  59. data/spec/lib/builder/{script → script_builder}/scala_spec.rb +1 -1
  60. data/spec/lib/builder/{script_spec.rb → script_builder_spec.rb} +1 -1
  61. data/spec/lib/builder/task_spec.rb +0 -2
  62. data/spec/support/create.rb +24 -11
  63. metadata +59 -38
  64. data/lib/vx/builder/build_configuration/artifacts.rb +0 -68
  65. data/lib/vx/builder/build_configuration/deploy/provider.rb +0 -58
  66. data/lib/vx/builder/script.rb +0 -145
  67. data/lib/vx/builder/script/deploy.rb +0 -40
  68. data/lib/vx/builder/script/script.rb +0 -39
  69. data/spec/lib/builder/script/artifacts_spec.rb +0 -18
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vx::Builder::BuildConfiguration::Deploy::Shell do
4
+ let(:params) { {
5
+ "shell" => "echo true",
6
+ "branch" => "master"
7
+ } }
8
+ subject { described_class.new params }
9
+
10
+ context "#branch" do
11
+ it "should be empty if key 'branch' is not exists" do
12
+ expect(shell nil).to eq []
13
+ end
14
+
15
+ it "should be if string" do
16
+ expect(shell "master").to eq ['master']
17
+ end
18
+
19
+ it "should be if array" do
20
+ expect(shell [:master, :staging]).to eq %w{ master staging }
21
+ end
22
+
23
+ def shell(branch)
24
+ described_class.new(params.merge("branch" => branch)).branch
25
+ end
26
+ end
27
+
28
+ context "#to_commands" do
29
+
30
+ it "should be empty if nil" do
31
+ expect(shell nil).to eq []
32
+ end
33
+
34
+ it "should be if string" do
35
+ expect(shell "command").to eq %w{ command }
36
+ end
37
+
38
+ it "should be if array" do
39
+ expect(shell [:cmd1, :cmd2]).to eq %w{ cmd1 cmd2 }
40
+ end
41
+
42
+ def shell(command)
43
+ described_class.new(params.merge("shell" => command)).to_commands
44
+ end
45
+ end
46
+
47
+ context ".detect" do
48
+
49
+ it "should be true if key shell exists" do
50
+ expect(shell "shell" => "value").to be
51
+ end
52
+
53
+ it "should be false if key shell does not exists" do
54
+ expect(shell "not_shell" => "value").to_not be
55
+ end
56
+
57
+ def shell(params)
58
+ described_class.detect(params)
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vx::Builder::BuildConfiguration::Deploy do
4
+ let(:params) { { "shell" => '/bin/true' } }
5
+ let(:deploy) { described_class.new params }
6
+ subject { deploy }
7
+
8
+ context "attributes" do
9
+ subject { deploy.attributes }
10
+
11
+ context "when is hash" do
12
+ let(:params) { { "shell" => '/bin/true' } }
13
+ it { should eq [{"shell" => "/bin/true"}] }
14
+ end
15
+
16
+ context "when is array" do
17
+ let(:params) { [{"shell" => '/bin/true'}] }
18
+ it { should eq [{"shell" => "/bin/true"}] }
19
+ end
20
+
21
+ context "when is nil" do
22
+ let(:params) { nil }
23
+ it { should eq [] }
24
+ end
25
+ end
26
+
27
+ context "find_modules" do
28
+ let(:branch) { 'master' }
29
+ subject { deploy.find_modules branch }
30
+
31
+ context "when deploy branch is empty array" do
32
+ let(:params) { {'shell' => 'true'} }
33
+ it { should_not be_empty }
34
+ end
35
+
36
+ context "when deploy branch is array" do
37
+ let(:params) { {'shell' => 'true', 'branch' => ['master', 'production']} }
38
+
39
+ it "should be true if branch found" do
40
+ expect(deploy.find_modules 'master').to_not be_empty
41
+ expect(deploy.find_modules 'production').to_not be_empty
42
+ end
43
+
44
+ it "should be false if branch not found" do
45
+ expect(deploy.find_modules 'staging').to eq []
46
+ end
47
+ end
48
+ end
49
+
50
+ end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vx::Builder::BuildConfiguration::Env do
4
+ let(:params) { { 'matrix' => ['a', 'b'], 'global' => ['c', 'd'] } }
5
+ let(:env) { described_class.new params }
6
+ subject { env }
7
+
8
+ its(:attributes) { should eq("matrix" => ['a', 'b'], "global" => ['c', 'd']) }
9
+
10
+ context "attributes" do
11
+
12
+ context "when env is string" do
13
+ let(:params) { 'foo' }
14
+ its(:matrix) { should eq [] }
15
+ its(:global) { should eq ["foo"] }
16
+ end
17
+
18
+ context "when env is array" do
19
+ let(:params) { [:foo, :bar] }
20
+ its(:matrix) { should eq ['foo', 'bar'] }
21
+ its(:global) { should eq [] }
22
+ end
23
+
24
+ context "when env is array of one element" do
25
+ let(:params) { [:foo] }
26
+ its(:matrix) { should eq [] }
27
+ its(:global) { should eq ['foo'] }
28
+ end
29
+
30
+ context "when env is valid hash" do
31
+ let(:params) { { "global" => "foo", "matrix" => 'bar' } }
32
+ its(:matrix) { should eq ['bar'] }
33
+ its(:global) { should eq ['foo'] }
34
+ end
35
+
36
+ context "when env is invalid hash" do
37
+ let(:params) { { "key" => "foo" } }
38
+ its(:matrix) { should eq [] }
39
+ its(:global) { should eq [] }
40
+ end
41
+
42
+ end
43
+ end
@@ -43,8 +43,7 @@ describe Vx::Builder::BuildConfiguration do
43
43
  "scala" => ['2.10.3'],
44
44
  "script" => ["RAILS_ENV=test ls -1 && echo DONE!"],
45
45
  "services" => ['rabbitmq'],
46
- "artifacts" => ["app/foo.txt", "app/*.txt", "app/", {"prefix"=>"$CI_JOB_ID/"}],
47
- "deploy" => [{"command"=>"cap deploy production", "provider"=>"shell"}],
46
+ "deploy" => [{"shell"=>"cap deploy production"}],
48
47
  "bundler_args" => ["--without development"],
49
48
  "before_deploy" => ["echo before deploy"],
50
49
  "after_deploy" => ["echo after deploy"]
@@ -54,135 +53,16 @@ describe Vx::Builder::BuildConfiguration do
54
53
 
55
54
  context "env" do
56
55
  subject { config.env }
57
-
58
- context "when is array" do
59
- let(:content) { { 'env' => %w{ 1 2 3 } } }
60
- its(:matrix) { should eq %w{1 2 3} }
61
- its(:global) { should eq [] }
62
- end
63
-
64
- context "when is hash" do
65
- let(:content) { { 'env' => {
66
- 'global' => "global",
67
- "matrix" => "matrix"
68
- } } }
69
- its(:matrix) { should eq %w{matrix} }
70
- its(:global) { should eq %w{global} }
71
- end
72
-
73
- context "when is empty" do
74
- let(:content) { {} }
75
- its(:matrix) { should eq [] }
76
- its(:global) { should eq [] }
77
- end
56
+ it { should be }
78
57
  end
79
58
 
80
59
  context "cache" do
81
60
  subject { config.cache }
82
-
83
- context "when directories present" do
84
- let(:content) { { "cache" => {
85
- "directories" => ["~/.cache"]
86
- } } }
87
- its(:directories) { should eq ["~/.cache"] }
88
- its(:enabled?) { should be_true }
89
- end
90
-
91
- context "when directories is not exists" do
92
- let(:content) { {} }
93
- its(:directories) { should eq [] }
94
- its(:enabled?) { should be_true }
95
- end
96
-
97
- context "when disabled" do
98
- let(:content) { { "cache" => false } }
99
- its(:directories) { should eq [] }
100
- its(:enabled?) { should be_false }
101
- end
102
- end
103
-
104
- context "artifacts" do
105
- subject { config.artifacts }
106
-
107
- its(:prefix) { should eq "$CI_JOB_ID/" }
108
- its(:files) { should eq ["app/foo.txt", "app/*.txt", "app/"] }
109
-
110
- context "when is empty" do
111
- let(:content) { {} }
112
- its(:files) { should eq [] }
113
- its(:prefix) { should be_nil }
114
- its(:attributes) { should eq [] }
115
- end
61
+ it { should be }
116
62
  end
117
63
 
118
64
  context "deploy" do
119
65
  subject { config.deploy }
120
-
121
- context "when is empty" do
122
- let(:content) { {} }
123
- its(:attributes) { should eq [] }
124
-
125
- it "build_configuration#deploy? should be false" do
126
- expect(config).to_not be_deploy
127
- end
128
- end
129
-
130
- context "when is array" do
131
- let(:content) { {
132
- "deploy" => [
133
- {
134
- "provider" => "some"
135
- }
136
- ]
137
- } }
138
- its(:attributes){ should eq [{"provider" => "some"}] }
139
-
140
- it "build_configuration#deploy? should be true" do
141
- expect(config).to be_deploy
142
- end
143
- end
144
-
145
- context "when is hash" do
146
- let(:content) { {
147
- "deploy" => {
148
- "provider" => "some"
149
- }
150
- } }
151
- its(:attributes){ should eq [{"provider" => "some"}] }
152
-
153
- it "build_configuration#deploy? should be true" do
154
- expect(config).to be_deploy
155
- end
156
- end
157
-
158
- context "with on:" do
159
- subject { config.deploy.providers.first.on }
160
-
161
- context "when is string" do
162
- let(:content) { {
163
- "deploy" => {
164
- "provider" => "some",
165
- "branch" => "production"
166
- }
167
- } }
168
-
169
- it "should be branch" do
170
- expect(subject).to eq(["production"])
171
- end
172
- end
173
-
174
- context "when is array" do
175
- let(:content) { {
176
- "deploy" => {
177
- "provider" => "some",
178
- "branch" => %w{ production master }
179
- }
180
- } }
181
-
182
- it { should eq %w{ production master } }
183
- end
184
-
185
- end
66
+ it { should be }
186
67
  end
187
-
188
68
  end
@@ -0,0 +1,82 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vx::Builder::DeployBuilder do
4
+ let(:params) { {
5
+ "env" => {
6
+ 'global' => "1",
7
+ "matrix" => "2",
8
+ },
9
+ "image" => "image",
10
+ "before_script" => "before",
11
+ "after_success" => "after",
12
+ "script" => "script",
13
+ "deploy" => {
14
+ "shell" => "/bin/true",
15
+ "branch" => "master"
16
+ }
17
+ } }
18
+ let(:matrix) { create(:matrix_builder, params) }
19
+ let(:branch) { 'master' }
20
+ let(:deploy) { described_class.new matrix, branch: branch }
21
+ subject { deploy }
22
+
23
+
24
+ context "just created" do
25
+ it { should be }
26
+ its(:base_build_configuration) { should eq matrix.build_configuration }
27
+ its(:matrix_build_configuration) { should eq matrix.build.first }
28
+ its(:matrix_build_configuration) { should be }
29
+ its(:branch) { should eq 'master' }
30
+ end
31
+
32
+ context "valid?" do
33
+ it "should be true if deploy key exists and found deploy modules" do
34
+ expect(deploy).to be_valid
35
+ expect(deploy).to have(1).deploy_modules
36
+ expect(deploy).to be_deploy
37
+ end
38
+
39
+ it "should be false if cannot found modules for deploy" do
40
+ deploy = described_class.new matrix, branch: "production"
41
+ expect(deploy).to_not be_valid
42
+ expect(deploy).to have(0).deploy_modules
43
+ expect(deploy).to be_deploy
44
+ end
45
+
46
+ it "should be false if deploy key does not exists" do
47
+ matrix = create(:matrix_builder)
48
+ deploy = described_class.new matrix, branch: "master"
49
+ expect(deploy).to_not be_valid
50
+ expect(deploy).to have(0).deploy_modules
51
+ expect(deploy).to_not be_deploy
52
+ end
53
+ end
54
+
55
+ context "build" do
56
+
57
+ it "should create build_configuration with deploy_modules and without deploy" do
58
+ expect(deploy.build).to be
59
+ expect(deploy.build).to_not be_deploy
60
+ expect(deploy.build).to be_deploy_modules
61
+ end
62
+
63
+ it "should be false if not valid" do
64
+ deploy = described_class.new matrix, branch: "production"
65
+ expect(deploy.build).to be_false
66
+ end
67
+
68
+ it "should remove attributes from BLACK_LIST" do
69
+ config = deploy.build
70
+ expect(config.image).to be_empty
71
+ expect(config.before_script).to be_empty
72
+ expect(config.script).to be_empty
73
+ expect(config.after_success).to be_empty
74
+ end
75
+
76
+ it "should remove matrix env" do
77
+ config = deploy.build
78
+ expect(config.env.global).to eq(['1'])
79
+ expect(config.env.matrix).to eq([])
80
+ end
81
+ end
82
+ end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'yaml'
3
3
 
4
- describe Vx::Builder::Matrix do
4
+ describe Vx::Builder::MatrixBuilder do
5
5
  let(:attributes) { {
6
6
  "env" => %w{ FOO=1 BAR=2 },
7
7
  "rvm" => %w{ 1.8.7 1.9.3 2.0.0 },
@@ -30,68 +30,9 @@ describe Vx::Builder::Matrix do
30
30
  end
31
31
  end
32
32
 
33
- context "deploy_configuration" do
34
- let(:branch) { 'master' }
35
- subject { matrix.deploy_configuration branch }
33
+ context 'build' do
36
34
 
37
- it "should be nil without :deploy key" do
38
- expect(subject).to be_nil
39
- end
40
-
41
- context "with single deploy without condifitions" do
42
- let(:attributes) { {
43
- "deploy" => "cap deploy production"
44
- } }
45
-
46
- it { should be }
47
- its("deploy.attributes"){ should eq(
48
- [{"command"=>"cap deploy production", "provider"=>"shell", "branch"=>[]}]
49
- ) }
50
- end
51
-
52
- context "with single deploy and condititions" do
53
- let(:attributes) { {
54
- "deploy" => {
55
- "command" => "cap deploy production",
56
- "branch" => ["master"]
57
- }
58
- } }
59
-
60
- it { should be }
61
- its("deploy.attributes"){ should eq(
62
- [{"command"=>"cap deploy production", "provider"=>"shell", "branch"=>["master"]}]
63
- ) }
64
- end
65
-
66
- context "with multiple deploys and condititions" do
67
- let(:attributes) { {
68
- "deploy" => [
69
- {
70
- "command" => "cap deploy staging",
71
- "branch" => ["master"]
72
- },
73
- {
74
- "command" => "cap deploy production",
75
- "branch" => ["production"]
76
- }
77
- ]
78
- } }
79
-
80
- it { should be }
81
- its("deploy.attributes"){ should eq(
82
- [{"command"=>"cap deploy staging", "provider"=>"shell", "branch"=>["master"]}]
83
- ) }
84
-
85
- context "when no one matched" do
86
- let(:branch) { 'staging' }
87
- it { should be_nil }
88
- end
89
- end
90
- end
91
-
92
- context 'build_configurations' do
93
-
94
- subject { matrix.build_configurations }
35
+ subject { matrix.build }
95
36
 
96
37
  it { should have(12).items }
97
38
 
@@ -115,7 +56,7 @@ describe Vx::Builder::Matrix do
115
56
  it { should have(1).item }
116
57
 
117
58
  context "attributes" do
118
- subject { matrix.build_configurations.first.to_hash.select{|k,v| !v.empty? } }
59
+ subject { matrix.build.first.to_hash.select{|k,v| !v.empty? } }
119
60
 
120
61
  it { should eq(
121
62
  "env" => {
@@ -140,7 +81,7 @@ describe Vx::Builder::Matrix do
140
81
 
141
82
  expect(keys.first["rvm"]).to eq ['2.0.0']
142
83
  expect(keys.first['env']).to eq(
143
- "matrix" => ["DB=postgresql"],
84
+ "matrix" => [],
144
85
  "global" => ["DB=postgresql"]
145
86
  )
146
87
  end
@@ -156,7 +97,7 @@ describe Vx::Builder::Matrix do
156
97
  end
157
98
 
158
99
  context "attributes" do
159
- subject { matrix.build_configurations.map(&:matrix_id) }
100
+ subject { matrix.build.map(&:matrix_id) }
160
101
 
161
102
  it "should have true values" do
162
103
  expect(subject).to eq [
@@ -199,8 +140,9 @@ describe Vx::Builder::Matrix do
199
140
 
200
141
  it { should have(12).items }
201
142
 
202
- it "should merge matrix env to global env" do
203
- expect(subject.map{|i| i["env"]["global"] }.uniq.sort).to eq([["BAR=1", "FOO=1"], ["BAR=2", "FOO=1"]])
143
+ it "should create environments" do
144
+ expect(subject.map{|i| i["env"]["matrix"] }.uniq.sort).to eq([["BAR=1"], ["BAR=2"]])
145
+ expect(subject.map{|i| i["env"]["global"] }.uniq.sort).to eq([["FOO=1"]])
204
146
  end
205
147
  end
206
148