forked from travis-ci/travis-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.rb
86 lines (72 loc) · 2.37 KB
/
init.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
module Travis
module CLI
class Compile < RepoCommand
description "compiles a build script from .travis.yml"
attr_accessor :slug
def setup
error "run command is not available on #{RUBY_VERSION}" if RUBY_VERSION < '1.9.3'
$:.unshift File.expand_path('../lib', __FILE__)
require 'travis/build'
end
def run(*arg)
@slug = find_slug
if match_data = /\A(?<build>\d+)(\.(?<job>\d+))?\z/.match(arg.first)
set_up_config(match_data)
elsif arg.length > 0
warn "#{arg.first} does not look like a job number. Last build's first job is assumed."
@config = last_build.jobs[0].config
else
## No arg case; use .travis.yml from $PWD
config = travis_config
global_env = sanitize_global_env(config)
if config.has_key? 'matrix'
warn 'matrix key is ignored'
config.delete_if { |k,v| k == 'matrix' }
end
unless config['os'].respond_to? :scan
warn "'os' key is unsupported in local build script compilation. Setting to default, 'linux'."
config['os'] = 'linux'
end
set_up_env(config, global_env)
end
puts Travis::Build.script(data).compile(true)
end
private
def data
{
:config => @config,
:repository => {
:slug => slug
}
}
end
def set_up_config(match_data)
@build = build(match_data[:build])
@job_number = match_data[:job].to_i - 1
@config = @build.jobs[@job_number].config
end
def sanitize_global_env(config)
global_env = []
if config.has_key? 'env'
if config['env']['matrix']
warn 'env.matrix key is ignored'
end
global_env = config['env'].fetch('global', [])
global_env.delete_if { |v| v.is_a? Hash }
end
['rvm', 'jvm'].each { | key |
if config.has_key? key
if config[key].is_a? Array then
config[key] = config[key].first
end
end
}
global_env
end
def set_up_env(config, global_env)
@config = config.delete_if {|k,v| k == 'env' }
@config['env'] = global_env
end
end
end
end