vx-builder 0.0.27 → 0.0.28
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/vx/builder/build_configuration/cache.rb +48 -0
- data/lib/vx/builder/build_configuration/env.rb +43 -0
- data/lib/vx/builder/build_configuration.rb +113 -0
- data/lib/vx/builder/matrix.rb +112 -0
- data/lib/vx/builder/script/env.rb +1 -1
- data/lib/vx/builder/version.rb +1 -1
- data/lib/vx/builder.rb +6 -4
- data/spec/fixtures/travis.yml +23 -13
- data/spec/lib/builder/build_configuration_spec.rb +99 -0
- data/spec/lib/builder/matrix_spec.rb +226 -0
- data/spec/support/create.rb +1 -1
- metadata +9 -9
- data/lib/vx/builder/source/constants.rb +0 -12
- data/lib/vx/builder/source/matrix.rb +0 -116
- data/lib/vx/builder/source/serializable.rb +0 -43
- data/lib/vx/builder/source.rb +0 -118
- data/spec/lib/builder/source_matrix_spec.rb +0 -222
- data/spec/lib/builder/source_spec.rb +0 -223
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84b253cffa5e036ddd0fb814840cf117f33f282f
|
4
|
+
data.tar.gz: d2d046cb4c403a212810654fd4b9dfe7a35a07e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05d0a7efa18bd2bd798703874cc8604e33e0debf81df8219bb082a576f01984ee747247c8200560994a05d5df0d3052a38d5dde190657c52696d031e71444edf
|
7
|
+
data.tar.gz: e95b0904223534d3ae08b96cf7c51429d1a337ce1a109bd0191598245dde5738744948aed6a96e4c6252967796ffa0301f828055f15648ee47292f7cda0188d3
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Vx
|
2
|
+
module Builder
|
3
|
+
class BuildConfiguration
|
4
|
+
class Cache
|
5
|
+
|
6
|
+
attr_reader :attributes
|
7
|
+
|
8
|
+
def initialize(new_cache)
|
9
|
+
normalize_attributes(new_cache)
|
10
|
+
end
|
11
|
+
|
12
|
+
def directories
|
13
|
+
@attributes["directories"]
|
14
|
+
end
|
15
|
+
|
16
|
+
def enabled?
|
17
|
+
@attributes["enabled"]
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def normalize_attributes(new_cache)
|
23
|
+
|
24
|
+
@attributes =
|
25
|
+
case new_cache
|
26
|
+
when nil
|
27
|
+
{
|
28
|
+
"directories" => [],
|
29
|
+
"enabled" => true,
|
30
|
+
}
|
31
|
+
when Hash
|
32
|
+
{
|
33
|
+
"directories" => Array(new_cache["directories"]).flatten.map(&:to_s),
|
34
|
+
"enabled" => true,
|
35
|
+
}
|
36
|
+
else
|
37
|
+
{
|
38
|
+
"directories" => [],
|
39
|
+
"enabled" => false
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Vx
|
2
|
+
module Builder
|
3
|
+
class BuildConfiguration
|
4
|
+
class Env
|
5
|
+
|
6
|
+
attr_reader :attributes
|
7
|
+
|
8
|
+
def initialize(new_env)
|
9
|
+
normalize_attributes(new_env)
|
10
|
+
end
|
11
|
+
|
12
|
+
def matrix
|
13
|
+
@attributes["matrix"]
|
14
|
+
end
|
15
|
+
|
16
|
+
def global
|
17
|
+
@attributes["global"]
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def normalize_attributes(new_env)
|
23
|
+
|
24
|
+
@attributes =
|
25
|
+
case new_env
|
26
|
+
when Hash
|
27
|
+
{
|
28
|
+
"matrix" => Array(new_env['matrix']),
|
29
|
+
"global" => Array(new_env['global'])
|
30
|
+
}
|
31
|
+
else
|
32
|
+
{
|
33
|
+
"matrix" => Array(new_env).flatten.map(&:to_s),
|
34
|
+
"global" => []
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
Dir[File.expand_path("../build_configuration/*.rb", __FILE__)].each do |f|
|
4
|
+
require f
|
5
|
+
end
|
6
|
+
|
7
|
+
module Vx
|
8
|
+
module Builder
|
9
|
+
class BuildConfiguration
|
10
|
+
|
11
|
+
ATTRIBUTES = %w{
|
12
|
+
rvm
|
13
|
+
scala
|
14
|
+
jdk
|
15
|
+
language
|
16
|
+
|
17
|
+
gemfile
|
18
|
+
services
|
19
|
+
image
|
20
|
+
|
21
|
+
before_install
|
22
|
+
before_script
|
23
|
+
script
|
24
|
+
after_success
|
25
|
+
}
|
26
|
+
|
27
|
+
class << self
|
28
|
+
def from_yaml(yaml)
|
29
|
+
hash = YAML.load(yaml)
|
30
|
+
new hash
|
31
|
+
end
|
32
|
+
|
33
|
+
def from_file(file)
|
34
|
+
if File.readable? file
|
35
|
+
from_yaml File.read(file)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
attr_reader :env, :cache
|
41
|
+
|
42
|
+
def initialize(new_attributes = {}, matrix_attributes = {})
|
43
|
+
new_attributes = {} unless new_attributes.is_a?(Hash)
|
44
|
+
|
45
|
+
@env = Env.new(new_attributes["env"])
|
46
|
+
@cache = Cache.new(new_attributes["cache"])
|
47
|
+
@matrix_attributes = matrix_attributes
|
48
|
+
|
49
|
+
build_attributes new_attributes
|
50
|
+
end
|
51
|
+
|
52
|
+
def matrix_attributes
|
53
|
+
@matrix_attributes.inject({}) do |a,pair|
|
54
|
+
k,v = pair
|
55
|
+
if k == 'env'
|
56
|
+
v = v["matrix"].first
|
57
|
+
end
|
58
|
+
if v
|
59
|
+
a[k] = v
|
60
|
+
end
|
61
|
+
a
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# for tests
|
66
|
+
def matrix_id
|
67
|
+
matrix_attributes.to_a.map{|i| i.join(":") }.sort.join(", ")
|
68
|
+
end
|
69
|
+
|
70
|
+
def to_hash
|
71
|
+
attributes.merge("env" => env.attributes)
|
72
|
+
.merge("cache" => cache.attributes)
|
73
|
+
end
|
74
|
+
|
75
|
+
def to_yaml
|
76
|
+
to_hash.to_yaml
|
77
|
+
end
|
78
|
+
|
79
|
+
def env_matrix
|
80
|
+
env.matrix
|
81
|
+
end
|
82
|
+
|
83
|
+
def language
|
84
|
+
@attributes["language"].first
|
85
|
+
end
|
86
|
+
|
87
|
+
def cached_directories
|
88
|
+
@cache.enabled? and @cache.directories
|
89
|
+
end
|
90
|
+
|
91
|
+
(ATTRIBUTES - %w{ language }).each do |attr|
|
92
|
+
define_method attr do
|
93
|
+
attributes[attr]
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
private
|
98
|
+
|
99
|
+
def attributes
|
100
|
+
@attributes
|
101
|
+
end
|
102
|
+
|
103
|
+
def build_attributes(new_attributes)
|
104
|
+
@attributes = ATTRIBUTES.inject({}) do |ac, attribute_name|
|
105
|
+
attribute = new_attributes[attribute_name]
|
106
|
+
ac[attribute_name] = Array(attribute)
|
107
|
+
ac
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
module Vx
|
2
|
+
module Builder
|
3
|
+
Matrix = Struct.new(:build_configuration) do
|
4
|
+
|
5
|
+
KEYS = %w{
|
6
|
+
rvm
|
7
|
+
gemfile
|
8
|
+
scala
|
9
|
+
jdk
|
10
|
+
|
11
|
+
image
|
12
|
+
env_matrix:env
|
13
|
+
}
|
14
|
+
|
15
|
+
def keys
|
16
|
+
extract_keys_from_builds_configuration.map(&:first).sort
|
17
|
+
end
|
18
|
+
|
19
|
+
def build_configurations
|
20
|
+
new_attributes = build_configuration.to_hash.dup
|
21
|
+
attributes_for_new_build_configurations_with_merged_env.map do |matrix_attributes|
|
22
|
+
new_attributes.merge!(matrix_attributes)
|
23
|
+
BuildConfiguration.new new_attributes, matrix_attributes
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def attributes_for_new_build_configurations_with_merged_env
|
28
|
+
attrs = attributes_for_new_build_configurations
|
29
|
+
attrs = [{}] if attrs.empty?
|
30
|
+
attrs.map! do |a|
|
31
|
+
env = a["env"]
|
32
|
+
a["env"] = {
|
33
|
+
"global" => Array(env) + build_configuration.env.global,
|
34
|
+
"matrix" => Array(env)
|
35
|
+
}
|
36
|
+
a
|
37
|
+
end
|
38
|
+
|
39
|
+
attrs
|
40
|
+
end
|
41
|
+
|
42
|
+
def attributes_for_new_build_configurations
|
43
|
+
permutate_and_build_pairs.inject([]) do |ac, pairs|
|
44
|
+
ac << pairs.inject({}) do |a,pair|
|
45
|
+
a[pair.key] = pair.value
|
46
|
+
a
|
47
|
+
end
|
48
|
+
ac
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def permutate_and_build_pairs
|
53
|
+
pairs = extract_keys_from_builds_configuration.map do |key_name, values|
|
54
|
+
values.map{|v| Pair.new(key_name, v) }
|
55
|
+
end
|
56
|
+
|
57
|
+
if not_matrix?(pairs)
|
58
|
+
[pairs.flatten]
|
59
|
+
else
|
60
|
+
array_permutations(pairs).map do |it|
|
61
|
+
if it.is_a?(Array)
|
62
|
+
it.flatten
|
63
|
+
else
|
64
|
+
[it]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end.sort_by(&:to_s)
|
68
|
+
end
|
69
|
+
|
70
|
+
def extract_keys_from_builds_configuration
|
71
|
+
KEYS.inject([]) do |a, key|
|
72
|
+
key_method, key_name = key.split(":")
|
73
|
+
key_name ||= key_method
|
74
|
+
|
75
|
+
value = build_configuration.public_send(key_method)
|
76
|
+
unless value.empty?
|
77
|
+
a << [key_name, value]
|
78
|
+
end
|
79
|
+
|
80
|
+
a
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
def not_matrix?(pairs)
|
87
|
+
pairs.all?{|i| i.size == 1 }
|
88
|
+
end
|
89
|
+
|
90
|
+
def array_permutations(array, index=0)
|
91
|
+
# index is 0 by default : start at the beginning, more elegant.
|
92
|
+
return array[-1] if index == array.size - 1 # Return last element if at end.
|
93
|
+
|
94
|
+
result = []
|
95
|
+
|
96
|
+
array[index].each do |element| # For each array
|
97
|
+
array_permutations(array, index + 1).each do |x| # Permute permute permute
|
98
|
+
result << [element, x]
|
99
|
+
end
|
100
|
+
end
|
101
|
+
result
|
102
|
+
end
|
103
|
+
|
104
|
+
Pair = Struct.new(:key, :value) do
|
105
|
+
def to_s
|
106
|
+
[key, value].join(":")
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
data/lib/vx/builder/version.rb
CHANGED
data/lib/vx/builder.rb
CHANGED
@@ -2,10 +2,12 @@ require File.expand_path("../builder/version", __FILE__)
|
|
2
2
|
|
3
3
|
module Vx
|
4
4
|
module Builder
|
5
|
-
autoload :Source,
|
6
|
-
autoload :Script,
|
7
|
-
autoload :Task,
|
8
|
-
autoload :Configuration,
|
5
|
+
autoload :Source, File.expand_path("../builder/source", __FILE__)
|
6
|
+
autoload :Script, File.expand_path("../builder/script", __FILE__)
|
7
|
+
autoload :Task, File.expand_path("../builder/task", __FILE__)
|
8
|
+
autoload :Configuration, File.expand_path("../builder/configuration", __FILE__)
|
9
|
+
autoload :BuildConfiguration, File.expand_path("../builder/build_configuration", __FILE__)
|
10
|
+
autoload :Matrix, File.expand_path("../builder/matrix", __FILE__)
|
9
11
|
|
10
12
|
module Helper
|
11
13
|
autoload :Config, File.expand_path("../builder/helper/config", __FILE__)
|
data/spec/fixtures/travis.yml
CHANGED
@@ -1,22 +1,32 @@
|
|
1
|
-
rvm:
|
2
|
-
|
3
|
-
gemfile:
|
4
|
-
|
5
|
-
before_script:
|
6
|
-
|
7
|
-
before_install:
|
8
|
-
|
1
|
+
rvm: 2.0.0
|
2
|
+
|
3
|
+
gemfile: 'Gemfile'
|
4
|
+
|
5
|
+
before_script: "echo before_script"
|
6
|
+
|
7
|
+
before_install: "echo before_install"
|
8
|
+
|
9
9
|
script: "RAILS_ENV=test ls -1 && echo DONE!"
|
10
10
|
|
11
|
-
after_success:
|
12
|
-
- "echo after success"
|
11
|
+
after_success: "echo after success"
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
services: "rabbitmq"
|
14
|
+
|
15
|
+
scala: "2.10.3"
|
16
|
+
|
17
|
+
jdk: "openjdk7"
|
17
18
|
|
18
19
|
image:
|
19
20
|
- one
|
20
21
|
- two
|
21
22
|
|
22
23
|
language: ruby
|
24
|
+
|
25
|
+
env:
|
26
|
+
global: 'global'
|
27
|
+
matrix: 'matrix'
|
28
|
+
|
29
|
+
cache:
|
30
|
+
directories:
|
31
|
+
- ~/.cache
|
32
|
+
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Vx::Builder::BuildConfiguration do
|
4
|
+
let(:default_content) { YAML.load fixture('travis.yml') }
|
5
|
+
let(:content) { default_content }
|
6
|
+
let(:config) { described_class.new content }
|
7
|
+
subject { config }
|
8
|
+
|
9
|
+
its(:to_hash) { should_not be_empty }
|
10
|
+
its(:rvm) { should eq %w{ 2.0.0 } }
|
11
|
+
its(:gemfile) { should eq %w{ Gemfile } }
|
12
|
+
its(:before_script) { should eq ["echo before_script"] }
|
13
|
+
its(:before_install) { should eq ["echo before_install"] }
|
14
|
+
its(:script) { should eq ["RAILS_ENV=test ls -1 && echo DONE!"] }
|
15
|
+
its(:after_success) { should eq ["echo after success"] }
|
16
|
+
its(:image) { should eq %w{ one two } }
|
17
|
+
its(:language) { should eq 'ruby' }
|
18
|
+
its(:services) { should eq %w{ rabbitmq } }
|
19
|
+
its(:scala) { should eq %w{ 2.10.3 } }
|
20
|
+
its(:jdk) { should eq %w{ openjdk7 } }
|
21
|
+
|
22
|
+
context "to_hash" do
|
23
|
+
subject { config.to_hash }
|
24
|
+
|
25
|
+
it { should eq(
|
26
|
+
{
|
27
|
+
"after_success" => ["echo after success"],
|
28
|
+
"before_install" => ["echo before_install"],
|
29
|
+
"before_script" => ["echo before_script"],
|
30
|
+
"cache" => {
|
31
|
+
"directories" => ["~/.cache"],
|
32
|
+
"enabled" => true
|
33
|
+
},
|
34
|
+
"env" => {
|
35
|
+
"matrix" => ["matrix"],
|
36
|
+
"global" => ["global"]
|
37
|
+
},
|
38
|
+
"gemfile" => ["Gemfile"],
|
39
|
+
"image" => ["one", "two"],
|
40
|
+
"jdk" => ['openjdk7'],
|
41
|
+
"language" => ["ruby"],
|
42
|
+
"rvm" => ["2.0.0"],
|
43
|
+
"scala" => ['2.10.3'],
|
44
|
+
"script" => ["RAILS_ENV=test ls -1 && echo DONE!"],
|
45
|
+
"services" => ['rabbitmq']
|
46
|
+
}
|
47
|
+
) }
|
48
|
+
end
|
49
|
+
|
50
|
+
context "env" do
|
51
|
+
subject { config.env }
|
52
|
+
|
53
|
+
context "when is array" do
|
54
|
+
let(:content) { { 'env' => %w{ 1 2 3 } } }
|
55
|
+
its(:matrix) { should eq %w{1 2 3} }
|
56
|
+
its(:global) { should eq [] }
|
57
|
+
end
|
58
|
+
|
59
|
+
context "when is hash" do
|
60
|
+
let(:content) { { 'env' => {
|
61
|
+
'global' => "global",
|
62
|
+
"matrix" => "matrix"
|
63
|
+
} } }
|
64
|
+
its(:matrix) { should eq %w{matrix} }
|
65
|
+
its(:global) { should eq %w{global} }
|
66
|
+
end
|
67
|
+
|
68
|
+
context "when is empty" do
|
69
|
+
let(:content) { {} }
|
70
|
+
its(:matrix) { should eq [] }
|
71
|
+
its(:global) { should eq [] }
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context "cache" do
|
76
|
+
subject { config.cache }
|
77
|
+
|
78
|
+
context "when directories present" do
|
79
|
+
let(:content) { { "cache" => {
|
80
|
+
"directories" => ["~/.cache"]
|
81
|
+
} } }
|
82
|
+
its(:directories) { should eq ["~/.cache"] }
|
83
|
+
its(:enabled?) { should be_true }
|
84
|
+
end
|
85
|
+
|
86
|
+
context "when directories is not exists" do
|
87
|
+
let(:content) { {} }
|
88
|
+
its(:directories) { should eq [] }
|
89
|
+
its(:enabled?) { should be_true }
|
90
|
+
end
|
91
|
+
|
92
|
+
context "when disabled" do
|
93
|
+
let(:content) { { "cache" => false } }
|
94
|
+
its(:directories) { should eq [] }
|
95
|
+
its(:enabled?) { should be_false }
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|