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,50 @@
1
+ module Vx
2
+ module Builder
3
+ class ScriptBuilder
4
+
5
+ class Scala < Base
6
+
7
+ DEFAULT_SCALA = '2.10.3'
8
+
9
+ def call(env)
10
+ if enabled?(env)
11
+ do_cache_key(env) do |i|
12
+ i << "scala-#{scala env}"
13
+ end
14
+
15
+ do_announce(env) do |i|
16
+ i << trace_sh_command("export SCALA_VERSION=#{scala env}")
17
+ end
18
+
19
+ do_install(env) do |i|
20
+ i << "if [[ -d project || -f build.sbt ]] ; then #{trace_sh_command "sbt ++#{scala env} update"} ; fi"
21
+ end
22
+
23
+ do_script(env) do |i|
24
+ i << "if [[ -d project || -f build.sbt ]] ; then #{trace_sh_command "sbt ++#{scala env} test"} ; fi"
25
+ end
26
+
27
+ do_cached_directories(env) do |i|
28
+ i << "~/.sbt"
29
+ i << "~/.ivy2"
30
+ end
31
+ end
32
+
33
+ app.call(env)
34
+ end
35
+
36
+ private
37
+
38
+ def enabled?(env)
39
+ env.source.scala.first || env.source.language == 'scala'
40
+ end
41
+
42
+ def scala(env)
43
+ env.source.scala.first || DEFAULT_SCALA
44
+ end
45
+
46
+
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,32 @@
1
+ module Vx
2
+ module Builder
3
+ class ScriptBuilder
4
+
5
+ Script = Struct.new(:app) do
6
+
7
+ include Helper::TraceShCommand
8
+
9
+ def call(env)
10
+ env.source.before_install.each do |c|
11
+ env.before_install << trace_sh_command(c)
12
+ end
13
+
14
+ env.source.before_script.each do |c|
15
+ env.before_script << trace_sh_command(c)
16
+ end
17
+
18
+ env.source.script.each do |c|
19
+ env.script << trace_sh_command(c)
20
+ end
21
+
22
+ env.source.after_success.each do |c|
23
+ env.after_success << trace_sh_command(c)
24
+ end
25
+
26
+ app.call(env)
27
+ end
28
+
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,32 @@
1
+ module Vx
2
+ module Builder
3
+ class Script
4
+
5
+ Script = Struct.new(:app) do
6
+
7
+ include Helper::TraceShCommand
8
+
9
+ def call(env)
10
+ env.source.before_install.each do |c|
11
+ env.before_install << trace_sh_command(c)
12
+ end
13
+
14
+ env.source.before_script.each do |c|
15
+ env.before_script << trace_sh_command(c)
16
+ end
17
+
18
+ env.source.script.each do |c|
19
+ env.script << trace_sh_command(c)
20
+ end
21
+
22
+ env.source.after_success.each do |c|
23
+ env.after_success << trace_sh_command(c)
24
+ end
25
+
26
+ app.call(env)
27
+ end
28
+
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,26 @@
1
+ module Vx
2
+ module Builder
3
+ class ScriptBuilder
4
+
5
+ class Services < Base
6
+
7
+ ALIASES = {
8
+ 'rabbitmq' => 'rabbitmq-server'
9
+ }
10
+
11
+ def call(env)
12
+ env.source.services.each do |srv|
13
+ srv = ALIASES[srv] || srv
14
+ env.init << trace_sh_command("sudo service #{srv} start")
15
+ end
16
+ unless env.source.services.empty?
17
+ env.init << trace_sh_command("sleep 3")
18
+ end
19
+
20
+ app.call(env)
21
+ end
22
+
23
+ end
24
+ end
25
+ end
26
+ end
@@ -3,7 +3,7 @@ module Vx
3
3
  class Task
4
4
 
5
5
  attr_reader :name, :src, :sha, :deploy_key, :branch, :pull_request_id,
6
- :cache_url_prefix, :artifacts_url_prefix, :job_id, :build_id
6
+ :cache_url_prefix, :job_id, :build_id
7
7
 
8
8
  def initialize(options = {})
9
9
  @name = options[:name]
@@ -15,16 +15,10 @@ module Vx
15
15
  @branch = options[:branch]
16
16
  @pull_request_id = options[:pull_request_id]
17
17
  @cache_url_prefix = options[:cache_url_prefix]
18
- @artifacts_url_prefix = options[:artifacts_url_prefix]
19
- @deploy = !!options[:deploy]
20
18
 
21
19
  validate!
22
20
  end
23
21
 
24
- def deploy?
25
- @deploy
26
- end
27
-
28
22
  private
29
23
 
30
24
  def validate!
@@ -1,5 +1,5 @@
1
1
  module Vx
2
2
  module Builder
3
- VERSION = "0.2.2"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
@@ -1,11 +1,15 @@
1
1
  language: ruby
2
2
 
3
+ env:
4
+ global: "FOO"
5
+ matrix: "BAR"
6
+
3
7
  deploy:
4
8
 
5
- - command: cap staging deploy
9
+ - shell: cap staging deploy
6
10
  branch: master
7
11
 
8
- - command: cap producation deploy
12
+ - shell: cap producation deploy
9
13
  branch: production
10
14
 
11
15
  after_deploy: echo after deploy
@@ -6,5 +6,5 @@ export CI_BRANCH=master
6
6
  export VX_ROOT=$(pwd)
7
7
  cd ${VX_ROOT}/code/name
8
8
 
9
- # after deploy
9
+ # after script
10
10
  test -f $HOME/.casher/bin/casher && /opt/rbenv/versions/1.9.3-p547/bin/ruby $HOME/.casher/bin/casher push http://example.com/master/rvm-1.9.3-gemfile.tgz
@@ -7,6 +7,8 @@ export DEBIAN_FRONTEND=noninteractive
7
7
  export CI_JOB_ID=1
8
8
  export CI_BUILD_ID=12
9
9
  export CI_BRANCH=master
10
+ echo \$\ export\ FOO
11
+ export FOO
10
12
  export VX_ROOT=$(pwd)
11
13
  mkdir -p ${VX_ROOT}/data/name
12
14
  mkdir -p ${VX_ROOT}/code/name
@@ -52,6 +54,6 @@ bundle install
52
54
  echo \$\ bundle\ clean\ --force
53
55
  bundle clean --force
54
56
 
55
- # before deploy
57
+ # before script
56
58
  echo \$\ echo\ before\ deploy
57
59
  echo before deploy
@@ -1,4 +1,8 @@
1
1
 
2
- # deploy
2
+ # script
3
3
  echo \$\ cap\ staging\ deploy
4
- cap staging deploy
4
+ cap staging deploy
5
+
6
+ # after success
7
+ echo \$\ echo\ after\ deploy
8
+ echo after deploy
@@ -8,4 +8,7 @@ script: rake
8
8
 
9
9
  after_script: echo after script
10
10
 
11
- deploy: cap staging deploy
11
+ deploy:
12
+ shell: cap staging deploy
13
+
14
+ after_deploy: echo after deploy
@@ -6,5 +6,5 @@ export CI_BRANCH=master
6
6
  export VX_ROOT=$(pwd)
7
7
  cd ${VX_ROOT}/code/name
8
8
 
9
- # after deploy
9
+ # after script
10
10
  test -f $HOME/.casher/bin/casher && /opt/rbenv/versions/1.9.3-p547/bin/ruby $HOME/.casher/bin/casher push http://example.com/master/rvm-1.9.3-gemfile.tgz
@@ -52,4 +52,4 @@ bundle install
52
52
  echo \$\ bundle\ clean\ --force
53
53
  bundle clean --force
54
54
 
55
- # before deploy
55
+ # before script
@@ -1,4 +1,8 @@
1
1
 
2
- # deploy
2
+ # script
3
3
  echo \$\ cap\ staging\ deploy
4
- cap staging deploy
4
+ cap staging deploy
5
+
6
+ # after success
7
+ echo \$\ echo\ after\ deploy
8
+ echo after deploy
@@ -30,13 +30,8 @@ cache:
30
30
  directories:
31
31
  - ~/.cache
32
32
 
33
- artifacts:
34
- - ../app/foo.txt
35
- - /app/*.txt
36
- - app/
37
- - prefix: $CI_JOB_ID/
38
-
39
- deploy: "cap deploy production"
33
+ deploy:
34
+ shell: "cap deploy production"
40
35
 
41
36
  after_deploy: echo after deploy
42
37
  before_deploy: echo before deploy
@@ -4,9 +4,9 @@ describe "(integration) ruby" do
4
4
  let(:build_configuration) {
5
5
  Vx::Builder::BuildConfiguration.from_yaml(config)
6
6
  }
7
- let(:matrix) { Vx::Builder::Matrix.new build_configuration }
7
+ let(:matrix) { Vx::Builder.matrix build_configuration }
8
8
  let(:task) { create :task }
9
- let(:script) { Vx::Builder::Script.new(task, source) }
9
+ let(:script) { Vx::Builder.script(task, source) }
10
10
  subject { matrix }
11
11
 
12
12
  def write_script_to_filter(prefix)
@@ -26,18 +26,17 @@ describe "(integration) ruby" do
26
26
  context "language" do
27
27
  let(:config) { fixture("integration/ruby/language/config.yml") }
28
28
 
29
- its(:build_configurations) { should have(1).item }
29
+ its(:build) { should have(1).item }
30
30
 
31
31
  context "first configuration" do
32
- let(:source) { matrix.build_configurations.first }
32
+ let(:source) { matrix.build.first }
33
33
  subject { script }
34
34
 
35
35
  before { write_script_to_filter "language/" }
36
36
 
37
- it { should_not be_deploy }
38
37
  its(:to_before_script) { should eq fixture("integration/ruby/language/before_script.sh") }
39
- its(:to_script) { should eq fixture("integration/ruby/language/script.sh") }
40
- its(:to_after_script) { should eq fixture("integration/ruby/language/after_script.sh") }
38
+ its(:to_script) { should eq fixture("integration/ruby/language/script.sh") }
39
+ its(:to_after_script) { should eq fixture("integration/ruby/language/after_script.sh") }
41
40
  end
42
41
  end
43
42
 
@@ -46,7 +45,7 @@ describe "(integration) ruby" do
46
45
 
47
46
  context "configuration" do
48
47
  let(:task) { create :task, deploy: true }
49
- let(:source) { matrix.deploy_configuration("master") }
48
+ let(:source) { Vx::Builder.deploy(matrix, branch: "master").build }
50
49
  subject { script }
51
50
 
52
51
  before { write_script_to_filter "deploy/d." }
@@ -55,45 +54,42 @@ describe "(integration) ruby" do
55
54
  expect(source).to be
56
55
  end
57
56
 
58
- it { should be_deploy }
59
57
  its(:to_before_script) { should eq fixture("integration/ruby/deploy/d.before_script.sh") }
60
- its(:to_script) { should eq fixture("integration/ruby/deploy/d.script.sh") }
61
- its(:to_after_script) { should eq fixture("integration/ruby/deploy/d.after_script.sh") }
58
+ its(:to_script) { should eq fixture("integration/ruby/deploy/d.script.sh") }
59
+ its(:to_after_script) { should eq fixture("integration/ruby/deploy/d.after_script.sh") }
62
60
  end
63
61
  end
64
62
 
65
63
  context "matrix" do
66
64
  let(:config) { fixture("integration/ruby/matrix/config.yml") }
67
65
 
68
- its(:build_configurations) { should have(2).item }
66
+ its(:build) { should have(2).item }
69
67
 
70
68
  context "0th configuration" do
71
- let(:source) { matrix.build_configurations[0] }
69
+ let(:source) { matrix.build[0] }
72
70
  subject { script }
73
71
 
74
72
  before { write_script_to_filter "matrix/0." }
75
73
 
76
- it { should_not be_deploy }
77
74
  its(:to_before_script) { should eq fixture("integration/ruby/matrix/0.before_script.sh") }
78
75
  its(:to_script) { should eq fixture("integration/ruby/matrix/0.script.sh") }
79
76
  its(:to_after_script) { should eq fixture("integration/ruby/matrix/0.after_script.sh") }
80
77
  end
81
78
 
82
79
  context "1th configuration" do
83
- let(:source) { matrix.build_configurations[1] }
80
+ let(:source) { matrix.build[1] }
84
81
  subject { script }
85
82
 
86
83
  before { write_script_to_filter "matrix/1." }
87
84
 
88
- it { should_not be_deploy }
89
85
  its(:to_before_script) { should eq fixture("integration/ruby/matrix/1.before_script.sh") }
90
86
  its(:to_script) { should eq fixture("integration/ruby/matrix/1.script.sh") }
91
87
  its(:to_after_script) { should eq fixture("integration/ruby/matrix/1.after_script.sh") }
92
88
  end
93
89
 
94
90
  context "deploy configuration" do
95
- let(:task) { create :task, deploy: true }
96
- let(:source) { matrix.deploy_configuration("master") }
91
+ let(:task) { create :task }
92
+ let(:source) { Vx::Builder.deploy(matrix, branch: "master").build }
97
93
  subject { script }
98
94
 
99
95
  before { write_script_to_filter "matrix/d." }
@@ -102,7 +98,6 @@ describe "(integration) ruby" do
102
98
  expect(source).to be
103
99
  end
104
100
 
105
- it { should be_deploy }
106
101
  its(:to_before_script) { should eq fixture("integration/ruby/matrix/d.before_script.sh") }
107
102
  its(:to_script) { should eq fixture("integration/ruby/matrix/d.script.sh") }
108
103
  its(:to_after_script) { should eq fixture("integration/ruby/matrix/d.after_script.sh") }
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vx::Builder::BuildConfiguration::Cache do
4
+ let(:params) { { "directories" => ['/a', '/b'] } }
5
+ let(:env) { described_class.new params }
6
+ subject { env }
7
+
8
+ its(:attributes) { should eq("directories"=>["/a", "/b"], "enabled"=>true) }
9
+
10
+ context "attributes" do
11
+ context "when cache is valid hash" do
12
+ let(:params) { {"directories" => ['/a']} }
13
+ it { should be_enabled }
14
+ its(:directories) { should eq ['/a'] }
15
+ end
16
+
17
+ context "when cache is invalid hash" do
18
+ let(:params) { {"key" => ['/a']} }
19
+ it { should be_enabled }
20
+ its(:directories) { should eq [] }
21
+ end
22
+
23
+ context "when is nil" do
24
+ let(:params) { nil }
25
+ it { should be_enabled }
26
+ its(:directories) { should eq [] }
27
+ end
28
+
29
+ context "when is false value" do
30
+ let(:params) { false }
31
+ it { should_not be_enabled }
32
+ its(:directories){ should eq [] }
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe Vx::Builder::BuildConfiguration::Deploy::Base 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(get_branch nil).to eq []
13
+ end
14
+
15
+ it "should be if string" do
16
+ expect(get_branch "master").to eq ['master']
17
+ end
18
+
19
+ it "should be if array" do
20
+ expect(get_branch [:master, :staging]).to eq %w{ master staging }
21
+ end
22
+
23
+ def get_branch(branch)
24
+ described_class.new(params.merge("branch" => branch)).branch
25
+ end
26
+ end
27
+
28
+ context ".loaded" do
29
+ subject { described_class.loaded }
30
+ it { should have(1).items }
31
+ end
32
+
33
+ end