Skip to content

Commit

Permalink
Merge pull request travis-ci#91 from travis-ci/global-env
Browse files Browse the repository at this point in the history
Support new format of specifying env vars
  • Loading branch information
joshk committed Aug 7, 2012
2 parents a5c5d1c + cd9b3df commit 79a7e75
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
29 changes: 28 additions & 1 deletion lib/travis/model/build/matrix/config.rb
Expand Up @@ -19,7 +19,7 @@ def size
def to_a
@as_array ||= begin
keys.inject([]) do |result, key|
values = config[key]
values = normalize_config_values(key, config[key])
values = [values] unless values.is_a?(Array)

if values
Expand All @@ -33,6 +33,33 @@ def to_a
end
alias to_ary to_a

def normalize_config_values(key, values)
method_name = "normalize_#{key}_values"
values = send(method_name, values) if respond_to?(method_name)
values
end

def normalize_env_values(values)
global = nil

if values.is_a?(Hash) && (values[:global] || values[:matrix])
global = values[:global]
values = values[:matrix]
end

if global
global = [global] unless global.is_a?(Array)
else
return values
end

values = [values] unless values.is_a?(Array)
values.map do |line|
line = [line] unless line.is_a?(Array)
line + global
end
end

# TODO: I'm lazy and I don't want to change tests for now,
# it can be removed later, especially when some tests
# that actually test Matrix::Config stop using Build
Expand Down
28 changes: 28 additions & 0 deletions spec/travis/model/build/matrix_spec.rb
Expand Up @@ -110,6 +110,23 @@
yml
}

let(:env_global_config) {
YAML.load <<-yml
script: "rake ci"
rvm:
- 1.9.2
- 1.9.3
gemfile:
- gemfiles/rails-4.0.0
env:
global:
- TOKEN=abcdef
matrix:
- FOO=bar
- BAR=baz
yml
}

let(:multiple_tests_config) {
YAML.load <<-yml
script: "rake ci"
Expand Down Expand Up @@ -262,6 +279,17 @@ def encrypt_config_env(config, repository)
end

describe :expand_matrix do
it 'adds global entries in env to all of the matrix elements' do
build = Factory(:build, :config => env_global_config)

build.expand_matrix_config(build.matrix_config).should == [
[[:rvm, '1.9.2'], [:gemfile, 'gemfiles/rails-4.0.0'], [:env, ['FOO=bar', 'TOKEN=abcdef']]],
[[:rvm, '1.9.2'], [:gemfile, 'gemfiles/rails-4.0.0'], [:env, ['BAR=baz', 'TOKEN=abcdef']]],
[[:rvm, '1.9.3'], [:gemfile, 'gemfiles/rails-4.0.0'], [:env, ['FOO=bar', 'TOKEN=abcdef']]],
[[:rvm, '1.9.3'], [:gemfile, 'gemfiles/rails-4.0.0'], [:env, ['BAR=baz', 'TOKEN=abcdef']]]
]
end

it 'sets the config to the jobs (no config)' do
build = Factory(:build, :config => {})
build.matrix.map(&:config).should == [{}]
Expand Down

0 comments on commit 79a7e75

Please sign in to comment.