This repository has been archived by the owner on May 10, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #315 from travis-ci/sf-refactor-build-config
Refactor build config
- Loading branch information
Showing
24 changed files
with
895 additions
and
783 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
require 'travis/model/build/config/env' | ||
require 'travis/model/build/config/language' | ||
require 'travis/model/build/config/matrix' | ||
require 'travis/model/build/config/obfuscate' | ||
|
||
class Build | ||
class Config | ||
NORMALIZERS = [Env, Language] | ||
|
||
DEFAULT_LANG = 'ruby' | ||
|
||
ENV_KEYS = [:rvm, :gemfile, :env, :otp_release, :php, :node_js, :scala, :jdk, :python, :perl, :compiler, :go, :xcode_sdk, :xcode_scheme, :ghc] | ||
|
||
EXPANSION_KEYS_FEATURE = [:os] | ||
|
||
EXPANSION_KEYS_LANGUAGE = { | ||
'c' => [:compiler], | ||
'clojure' => [:lein, :jdk], | ||
'cpp' => [:compiler], | ||
'erlang' => [:otp_release], | ||
'go' => [:go], | ||
'groovy' => [:jdk], | ||
'haskell' => [:ghc], | ||
'java' => [:jdk], | ||
'node_js' => [:node_js], | ||
'objective-c' => [:rvm, :gemfile, :xcode_sdk, :xcode_scheme], | ||
'perl' => [:perl], | ||
'php' => [:php], | ||
'python' => [:python], | ||
'ruby' => [:rvm, :gemfile, :jdk], | ||
'scala' => [:scala, :jdk] | ||
} | ||
|
||
EXPANSION_KEYS_UNIVERSAL = [:env, :branch] | ||
|
||
def self.matrix_keys_for(config, options = {}) | ||
keys = matrix_keys(config, options) | ||
keys & config.keys.map(&:to_sym) | ||
end | ||
|
||
def self.matrix_keys(config, options = {}) | ||
lang = Array(config.symbolize_keys[:language]).first | ||
keys = ENV_KEYS | ||
keys &= EXPANSION_KEYS_LANGUAGE.fetch(lang, EXPANSION_KEYS_LANGUAGE[DEFAULT_LANG]) | ||
keys << :os if options[:multi_os] | ||
keys | EXPANSION_KEYS_UNIVERSAL | ||
end | ||
|
||
attr_reader :config, :options | ||
|
||
def initialize(config, options = {}) | ||
@config = (config || {}).deep_symbolize_keys | ||
@options = options | ||
end | ||
|
||
def normalize | ||
NORMALIZERS.inject(config) do |config, normalizer| | ||
normalizer.new(config, options).run | ||
end | ||
end | ||
|
||
def obfuscate | ||
Obfuscate.new(config, options).run | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
require 'core_ext/hash/compact' | ||
|
||
class Build | ||
class Config | ||
class Env < Struct.new(:config, :options) | ||
def run | ||
case config[:env] | ||
when Hash | ||
config.merge(normalize_hash(config[:env])).compact | ||
when Array | ||
config.merge(env: config[:env].map { |value| normalize_value(value) }) | ||
else | ||
config | ||
end | ||
end | ||
|
||
def normalize_hash(env) | ||
if env[:global] || env[:matrix] | ||
{ global_env: normalize_values(env[:global]), env: normalize_values(env[:matrix]) } | ||
else | ||
{ env: normalize_values(env) } | ||
end | ||
end | ||
|
||
def normalize_values(values) | ||
values = [values].compact unless values.is_a?(Array) | ||
values.map { |value| normalize_value(value) } unless values.empty? | ||
end | ||
|
||
def normalize_value(value) | ||
case value | ||
when Hash | ||
to_env_var(value) | ||
when Array | ||
value.map { |value| to_env_var(value) } | ||
else | ||
value | ||
end | ||
end | ||
|
||
def to_env_var(hash) | ||
if hash.is_a?(Hash) && !hash.key?(:secure) | ||
hash.map { |name, value| "#{name}=#{value}" }.join(' ') | ||
else | ||
hash | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require 'active_support/core_ext/array/wrap' | ||
|
||
class Build | ||
class Config | ||
class Language < Struct.new(:config, :options) | ||
def run | ||
config[:language] = Array.wrap(config[:language]).first || DEFAULT_LANG | ||
config.select { |key, value| include_key?(key) } | ||
end | ||
|
||
private | ||
|
||
def include_key?(key) | ||
matrix_keys.include?(key) || !known_env_key?(key) | ||
end | ||
|
||
def matrix_keys | ||
Config.matrix_keys(config, options) | ||
end | ||
|
||
def known_env_key?(key) | ||
(ENV_KEYS | EXPANSION_KEYS_FEATURE).include?(key) | ||
end | ||
end | ||
end | ||
end | ||
|
Oops, something went wrong.