perkins 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.DS_Store +0 -0
- data/.env.example +4 -0
- data/.gitignore +19 -0
- data/.pryrc +3 -0
- data/.rspec +2 -0
- data/Gemfile +18 -0
- data/LICENSE.txt +22 -0
- data/README.md +71 -0
- data/Rakefile +28 -0
- data/TODO.md +4 -0
- data/bin/perkins +6 -0
- data/db/migrate/20150130143030_create_repo.rb +18 -0
- data/db/migrate/20150130143050_create_builds.rb +20 -0
- data/db/schema.rb +38 -0
- data/examples/config.rb +12 -0
- data/examples/database.yml +17 -0
- data/examples/mongo.yml +13 -0
- data/lib/core_ext/hash/compact.rb +8 -0
- data/lib/core_ext/hash/deep_merge.rb +15 -0
- data/lib/core_ext/hash/deep_symbolize_keys.rb +20 -0
- data/lib/core_ext/object/false.rb +5 -0
- data/lib/core_ext/string/indent.rb +5 -0
- data/lib/core_ext/string/unindent.rb +5 -0
- data/lib/perkins/.DS_Store +0 -0
- data/lib/perkins/application.rb +40 -0
- data/lib/perkins/assets/images/github.svg +4 -0
- data/lib/perkins/assets/images/spinner.svg +23 -0
- data/lib/perkins/assets/javascripts/app.js +9 -0
- data/lib/perkins/assets/javascripts/log_view.js.coffee +95 -0
- data/lib/perkins/assets/javascripts/perkings.js.coffee +40 -0
- data/lib/perkins/assets/javascripts/vendor/ansiparse.js +187 -0
- data/lib/perkins/assets/javascripts/vendor/jquery.timeago.js +189 -0
- data/lib/perkins/assets/javascripts/vendor/log.js +2 -0
- data/lib/perkins/assets/javascripts/vendor/minispade.js +55 -0
- data/lib/perkins/assets/stylesheets/app.css +2 -0
- data/lib/perkins/assets/stylesheets/log.css.scss +115 -0
- data/lib/perkins/assets/stylesheets/styles.css.scss +199 -0
- data/lib/perkins/auth/github.rb +181 -0
- data/lib/perkins/build/data/env.rb +84 -0
- data/lib/perkins/build/data/var.rb +60 -0
- data/lib/perkins/build/data.rb +167 -0
- data/lib/perkins/build/script/bundler.rb +76 -0
- data/lib/perkins/build/script/go.rb +100 -0
- data/lib/perkins/build/script/helpers.rb +39 -0
- data/lib/perkins/build/script/jdk.rb +43 -0
- data/lib/perkins/build/script/ruby.rb +31 -0
- data/lib/perkins/build/script/rvm.rb +73 -0
- data/lib/perkins/build/script/stages.rb +28 -0
- data/lib/perkins/build/script/templates/footer.sh +3 -0
- data/lib/perkins/build/script/templates/header.sh +201 -0
- data/lib/perkins/build/script/templates/xcode.sh +21 -0
- data/lib/perkins/build/script.rb +167 -0
- data/lib/perkins/build/shell/dsl.rb +104 -0
- data/lib/perkins/build/shell/node.rb +121 -0
- data/lib/perkins/build/shell.rb +16 -0
- data/lib/perkins/build.rb +27 -0
- data/lib/perkins/build_report.rb +11 -0
- data/lib/perkins/cli.rb +42 -0
- data/lib/perkins/commit.rb +30 -0
- data/lib/perkins/dsl/app_proxy.rb +23 -0
- data/lib/perkins/dsl.rb +12 -0
- data/lib/perkins/listener.rb +38 -0
- data/lib/perkins/logger.rb +12 -0
- data/lib/perkins/notifier.rb +5 -0
- data/lib/perkins/repo.rb +145 -0
- data/lib/perkins/runner.rb +124 -0
- data/lib/perkins/server.rb +314 -0
- data/lib/perkins/thor_utils.rb +79 -0
- data/lib/perkins/version.rb +3 -0
- data/lib/perkins/views/401.haml +1 -0
- data/lib/perkins/views/builds.haml +46 -0
- data/lib/perkins/views/index.haml +6 -0
- data/lib/perkins/views/layout.haml +53 -0
- data/lib/perkins/views/menu.haml +18 -0
- data/lib/perkins/views/orgs.haml +101 -0
- data/lib/perkins/views/profile.haml +31 -0
- data/lib/perkins/views/readme.md +20 -0
- data/lib/perkins/views/repos/config.haml +72 -0
- data/lib/perkins/views/repos/github.haml +76 -0
- data/lib/perkins/views/repos/menu.haml +17 -0
- data/lib/perkins/views/repos/repo.haml +64 -0
- data/lib/perkins/views/repos/spinner.haml +3 -0
- data/lib/perkins/webhooks/github.rb +12 -0
- data/lib/perkins/worker.rb +33 -0
- data/lib/perkins.rb +36 -0
- data/perkins.gemspec +52 -0
- data/spec/fixtures/.travis.yml +8 -0
- data/spec/fixtures/config.yml +6 -0
- data/spec/lib/build/build_spec.rb +58 -0
- data/spec/lib/commit_spec.rb +6 -0
- data/spec/lib/dsl_spec.rb +17 -0
- data/spec/lib/listener_spec.rb +30 -0
- data/spec/lib/repo_spec.rb +110 -0
- data/spec/lib/runner_spec.rb +76 -0
- data/spec/lib/server_spec.rb +108 -0
- data/spec/spec_helper.rb +67 -0
- data/spec/support/auth.rb +30 -0
- data/spec/support/github_api.rb +177 -0
- metadata +503 -0
@@ -0,0 +1,76 @@
|
|
1
|
+
module Perkins
|
2
|
+
module Build
|
3
|
+
class Script
|
4
|
+
module Bundler
|
5
|
+
DEFAULT_BUNDLER_ARGS = "--jobs=3 --retry=3"
|
6
|
+
|
7
|
+
def cache_slug
|
8
|
+
super << "--gemfile-" << config[:gemfile].to_s
|
9
|
+
end
|
10
|
+
|
11
|
+
def use_directory_cache?
|
12
|
+
super || data.cache?(:bundler)
|
13
|
+
end
|
14
|
+
|
15
|
+
def setup
|
16
|
+
super
|
17
|
+
|
18
|
+
gemfile? do |sh|
|
19
|
+
sh.set "BUNDLE_GEMFILE", "$PWD/#{config[:gemfile]}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def announce
|
24
|
+
super
|
25
|
+
cmd "bundle --version", timing: false
|
26
|
+
end
|
27
|
+
|
28
|
+
def install
|
29
|
+
gemfile? do |sh|
|
30
|
+
sh.if "-f #{config[:gemfile]}.lock" do |sub|
|
31
|
+
directory_cache.add(sub, bundler_path) if data.cache?(:bundler)
|
32
|
+
sub.cmd bundler_command("--deployment"), fold: "install.bundler", retry: true
|
33
|
+
end
|
34
|
+
|
35
|
+
sh.else do |sub|
|
36
|
+
# Cache bundler if it has been explicitly enabled
|
37
|
+
directory_cache.add(sub, bundler_path) if data.cache?(:bundler, false)
|
38
|
+
sub.cmd bundler_command, fold: "install.bundler", retry: true
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def prepare_cache
|
44
|
+
cmd("bundle clean") if bundler_path
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def gemfile?(*args, &block)
|
50
|
+
self.if "-f #{config[:gemfile]}", *args, &block
|
51
|
+
end
|
52
|
+
|
53
|
+
def bundler_args_path
|
54
|
+
args = Array(bundler_args).join(" ")
|
55
|
+
path = args[/--path[= ](\S+)/, 1]
|
56
|
+
path ||= "vendor/bundle" #if args.include?("--deployment")
|
57
|
+
path
|
58
|
+
end
|
59
|
+
|
60
|
+
def bundler_path
|
61
|
+
bundler_args_path || "${BUNDLE_PATH:-vendor/bundle}"
|
62
|
+
end
|
63
|
+
|
64
|
+
def bundler_command(args = nil)
|
65
|
+
args = bundler_args || [DEFAULT_BUNDLER_ARGS, args].compact
|
66
|
+
args = [args].flatten << "--path=#{bundler_path}" if data.cache?(:bundler) && !bundler_args_path
|
67
|
+
["bundle install", *args].compact.join(" ")
|
68
|
+
end
|
69
|
+
|
70
|
+
def bundler_args
|
71
|
+
config[:bundler_args]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
module Perkins
|
2
|
+
module Build
|
3
|
+
class Script
|
4
|
+
class Go < Script
|
5
|
+
DEFAULTS = {
|
6
|
+
gobuild_args: '-v',
|
7
|
+
go: '1.3.1'
|
8
|
+
}
|
9
|
+
|
10
|
+
def cache_slug
|
11
|
+
super << "--go-" << config[:go].to_s
|
12
|
+
end
|
13
|
+
|
14
|
+
def pre_setup
|
15
|
+
puts "configure"
|
16
|
+
end
|
17
|
+
|
18
|
+
def configure
|
19
|
+
puts "configure"
|
20
|
+
end
|
21
|
+
|
22
|
+
def export
|
23
|
+
super
|
24
|
+
"export GO_VERSION=#{go_version}"
|
25
|
+
end
|
26
|
+
|
27
|
+
def announce
|
28
|
+
super
|
29
|
+
'gvm version && ' <<
|
30
|
+
'go version && ' <<
|
31
|
+
'go env'
|
32
|
+
end
|
33
|
+
|
34
|
+
def setup
|
35
|
+
super
|
36
|
+
"gvm get &&" <<
|
37
|
+
"gvm update && source #{HOME_DIR}/.gvm/scripts/gvm && " <<
|
38
|
+
"gvm install #{go_version} --binary || gvm install #{go_version} && " <<
|
39
|
+
"gvm use #{go_version} && "
|
40
|
+
# Prepend *our* GOPATH entry so that built binaries and packages are
|
41
|
+
# easier to find and our `git clone`'d libraries are found by the
|
42
|
+
# `go` commands.
|
43
|
+
source_path = repo.url.gsub(/https\:\/\/|\.git/, "")
|
44
|
+
source_owner_path = source_path.split('/')[0..1].join("/")
|
45
|
+
local_path = self.repo.working_dir + self.repo.name
|
46
|
+
"export GOPATH=#{HOME_DIR}/gopath:$GOPATH && " <<
|
47
|
+
#binding.pry
|
48
|
+
"mkdir -p #{HOME_DIR}/gopath/src/#{source_owner_path} && " <<
|
49
|
+
"cp -r #{local_path} #{HOME_DIR}/gopath/src/#{source_owner_path} && " <<
|
50
|
+
"export BUILD_DIR=#{HOME_DIR}/gopath/src/#{source_path} && " <<
|
51
|
+
"cd #{HOME_DIR}/gopath/src/#{source_path}"
|
52
|
+
end
|
53
|
+
|
54
|
+
def install
|
55
|
+
if uses_make?
|
56
|
+
'true'
|
57
|
+
else
|
58
|
+
"go get #{config[:gobuild_args]} ./..."
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def script
|
63
|
+
if uses_make?
|
64
|
+
'make'
|
65
|
+
else
|
66
|
+
"go test #{config[:gobuild_args]} ./..."
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def uses_make?(*args)
|
73
|
+
self.if '-f GNUmakefile || -f makefile || -f Makefile || -f BSDmakefile', *args
|
74
|
+
end
|
75
|
+
|
76
|
+
def go_version
|
77
|
+
version = config[:go].to_s
|
78
|
+
case version
|
79
|
+
when '1'
|
80
|
+
'go1.3.1'
|
81
|
+
when '1.0'
|
82
|
+
'go1.0.3'
|
83
|
+
when '1.2'
|
84
|
+
'go1.2.2'
|
85
|
+
when '1.3'
|
86
|
+
'go1.3.1'
|
87
|
+
when /^[0-9]\.[0-9\.]+/
|
88
|
+
"go#{config[:go]}"
|
89
|
+
else
|
90
|
+
if config[:go].is_a?(Travis::Yaml::Nodes::VersionList)
|
91
|
+
config[:go].first
|
92
|
+
else
|
93
|
+
config[:go]
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Perkins
|
2
|
+
module Build
|
3
|
+
class Script
|
4
|
+
module Helpers
|
5
|
+
Shell::Dsl.instance_methods(false).each do |name|
|
6
|
+
define_method(name) do |*args, &block|
|
7
|
+
options = args.last if args.last.is_a?(Hash)
|
8
|
+
sh.send(name, *args, &stacking(&block)) unless sh.blank?
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def sh
|
13
|
+
stack.last
|
14
|
+
end
|
15
|
+
|
16
|
+
def failure(message)
|
17
|
+
echo message
|
18
|
+
raw 'false'
|
19
|
+
end
|
20
|
+
|
21
|
+
def stacking
|
22
|
+
->(sh) {
|
23
|
+
stack.push(sh)
|
24
|
+
yield(sh) if block_given?
|
25
|
+
stack.pop
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
def before_install
|
30
|
+
puts "before install"
|
31
|
+
end
|
32
|
+
|
33
|
+
def announce?(stage)
|
34
|
+
stage && stage != :after_result
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Perkins
|
2
|
+
module Build
|
3
|
+
class Script
|
4
|
+
module Jdk
|
5
|
+
def export
|
6
|
+
super
|
7
|
+
set 'TRAVIS_JDK_VERSION', config[:jdk], echo: false if uses_jdk?
|
8
|
+
end
|
9
|
+
|
10
|
+
def setup
|
11
|
+
super
|
12
|
+
cmd "jdk_switcher use #{config[:jdk]}", assert: true, timing: false if uses_jdk?
|
13
|
+
self.if '-f build.gradle' do
|
14
|
+
set 'TERM', 'dumb', echo: false
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def announce
|
19
|
+
super
|
20
|
+
if uses_java?
|
21
|
+
cmd "java -version", timing: false
|
22
|
+
cmd "javac -version", timing: false
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def cache_slug
|
27
|
+
return super unless uses_jdk?
|
28
|
+
super << "--jdk-" << config[:jdk].to_s
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def uses_java?
|
34
|
+
true
|
35
|
+
end
|
36
|
+
|
37
|
+
def uses_jdk?
|
38
|
+
!!config[:jdk]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Perkins
|
2
|
+
module Build
|
3
|
+
class Script
|
4
|
+
class Ruby < Script
|
5
|
+
DEFAULTS = {
|
6
|
+
rvm: 'default',
|
7
|
+
gemfile: 'Gemfile'
|
8
|
+
}
|
9
|
+
|
10
|
+
include Jdk
|
11
|
+
include RVM
|
12
|
+
include Bundler
|
13
|
+
|
14
|
+
def announce
|
15
|
+
super
|
16
|
+
cmd 'gem --version', timing: false
|
17
|
+
end
|
18
|
+
|
19
|
+
def script
|
20
|
+
gemfile? then: 'bundle exec rake', else: 'rake'
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def uses_java?
|
26
|
+
uses_jdk?
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module Perkins
|
2
|
+
module Build
|
3
|
+
class Script
|
4
|
+
module RVM
|
5
|
+
def cache_slug
|
6
|
+
super << "--rvm-" << ruby_version.to_s
|
7
|
+
end
|
8
|
+
|
9
|
+
def export
|
10
|
+
super
|
11
|
+
set 'TRAVIS_RUBY_VERSION', config[:rvm], echo: false
|
12
|
+
end
|
13
|
+
|
14
|
+
def setup
|
15
|
+
super
|
16
|
+
config[:ruby] ? setup_chruby : setup_rvm
|
17
|
+
end
|
18
|
+
|
19
|
+
def announce
|
20
|
+
super
|
21
|
+
cmd 'ruby --version'
|
22
|
+
if config[:ruby]
|
23
|
+
cmd 'chruby --version'
|
24
|
+
else
|
25
|
+
cmd 'rvm --version'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def ruby_version
|
32
|
+
config[:rvm].to_s.gsub(/-(1[89]|2[01])mode$/, '-d\1')
|
33
|
+
end
|
34
|
+
|
35
|
+
def setup_chruby
|
36
|
+
echo 'BETA: Using chruby to select Ruby version. This is currently a beta feature and may change at any time."', color: :yellow
|
37
|
+
cmd "curl -sLo ~/chruby.sh https://gist.githubusercontent.com/henrikhodne/a01cd7367b12a59ee051/raw/chruby.sh", echo: false
|
38
|
+
cmd "source ~/chruby.sh", echo: false
|
39
|
+
cmd "chruby #{config[:ruby]}"
|
40
|
+
end
|
41
|
+
|
42
|
+
def setup_rvm
|
43
|
+
file '$rvm_path/user/db', %w(
|
44
|
+
rvm_remote_server_url3=https://s3.amazonaws.com/travis-rubies/binaries
|
45
|
+
rvm_remote_server_type3=rubies
|
46
|
+
rvm_remote_server_verify_downloads3=1
|
47
|
+
).join("\n")
|
48
|
+
|
49
|
+
if ruby_version =~ /ruby-head/
|
50
|
+
fold("rvm.1") do
|
51
|
+
echo 'Setting up latest %s' % ruby_version, ansi: :yellow
|
52
|
+
cmd "rvm get stable", assert: false if ruby_version == 'jruby-head'
|
53
|
+
set 'ruby_alias', "`rvm alias show #{ruby_version} 2>/dev/null`"
|
54
|
+
cmd "rvm alias delete #{ruby_version}", assert: false
|
55
|
+
cmd "rvm remove ${ruby_alias:-#{ruby_version}} --gems", assert: false
|
56
|
+
cmd "rvm remove #{ruby_version} --gems --fuzzy", assert: false
|
57
|
+
cmd "rvm install #{ruby_version} --binary"
|
58
|
+
end
|
59
|
+
cmd "rvm use #{ruby_version}"
|
60
|
+
elsif ruby_version == 'default'
|
61
|
+
self.if "-f .ruby-version" do |sh|
|
62
|
+
sh.echo 'BETA: Using Ruby version from .ruby-version. This is a beta feature and may be removed in the future.', color: :yellow
|
63
|
+
fold("rvm.1") { sh.cmd "rvm use . --install --binary --fuzzy" }
|
64
|
+
end
|
65
|
+
self.else "rvm use default"
|
66
|
+
else
|
67
|
+
fold("rvm.1") { cmd "rvm use #{ruby_version} --install --binary --fuzzy" }
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Perkins
|
2
|
+
module Build
|
3
|
+
class Script
|
4
|
+
module Stages
|
5
|
+
|
6
|
+
def run_stages
|
7
|
+
STAGES[:builtin].each { |stage| run_builtin_stage(stage) }
|
8
|
+
STAGES[:custom].each { |stage| run_stage(stage) }
|
9
|
+
end
|
10
|
+
|
11
|
+
def run_builtin_stage(stage)
|
12
|
+
self.send(stage)
|
13
|
+
end
|
14
|
+
|
15
|
+
def run_stage(stage)
|
16
|
+
puts "call #{stage}"
|
17
|
+
call_custom_stage(stage)
|
18
|
+
end
|
19
|
+
|
20
|
+
def call_custom_stage(stage)
|
21
|
+
#binding.pry
|
22
|
+
@config.send(stage).present? ? cmd(@config.send(stage)) : self.send(stage)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,201 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
source $HOME/.profile
|
3
|
+
|
4
|
+
ANSI_RED="\033[31;1m"
|
5
|
+
ANSI_GREEN="\033[32;1m"
|
6
|
+
ANSI_RESET="\033[0m"
|
7
|
+
ANSI_CLEAR="\033[0K"
|
8
|
+
|
9
|
+
TRAVIS_TEST_RESULT=
|
10
|
+
TRAVIS_CMD=
|
11
|
+
|
12
|
+
function travis_cmd() {
|
13
|
+
local assert output display retry timing cmd result
|
14
|
+
|
15
|
+
cmd=$1
|
16
|
+
TRAVIS_CMD=$cmd
|
17
|
+
shift
|
18
|
+
|
19
|
+
while true; do
|
20
|
+
case "$1" in
|
21
|
+
--assert) assert=true; shift ;;
|
22
|
+
--echo) output=true; shift ;;
|
23
|
+
--display) display=$2; shift 2;;
|
24
|
+
--retry) retry=true; shift ;;
|
25
|
+
--timing) timing=true; shift ;;
|
26
|
+
*) break ;;
|
27
|
+
esac
|
28
|
+
done
|
29
|
+
|
30
|
+
if [[ -n "$timing" ]]; then
|
31
|
+
travis_time_start
|
32
|
+
fi
|
33
|
+
|
34
|
+
if [[ -n "$output" ]]; then
|
35
|
+
echo "\$ ${display:-$cmd}"
|
36
|
+
fi
|
37
|
+
|
38
|
+
if [[ -n "$retry" ]]; then
|
39
|
+
travis_retry eval "$cmd"
|
40
|
+
else
|
41
|
+
eval "$cmd"
|
42
|
+
fi
|
43
|
+
result=$?
|
44
|
+
|
45
|
+
if [[ -n "$timing" ]]; then
|
46
|
+
travis_time_finish
|
47
|
+
fi
|
48
|
+
|
49
|
+
if [[ -n "$assert" ]]; then
|
50
|
+
travis_assert $result
|
51
|
+
fi
|
52
|
+
|
53
|
+
travis_result $result
|
54
|
+
return $result
|
55
|
+
}
|
56
|
+
|
57
|
+
travis_time_start() {
|
58
|
+
travis_timer_id=$(printf %08x $(( RANDOM * RANDOM )))
|
59
|
+
travis_start_time=$(travis_nanoseconds)
|
60
|
+
echo -en "travis_time:start:$travis_timer_id\r${ANSI_CLEAR}"
|
61
|
+
}
|
62
|
+
|
63
|
+
travis_time_finish() {
|
64
|
+
local result=$?
|
65
|
+
travis_end_time=$(travis_nanoseconds)
|
66
|
+
local duration=$(($travis_end_time-$travis_start_time))
|
67
|
+
echo -en "travis_time:end:$travis_timer_id:start=$travis_start_time,finish=$travis_end_time,duration=$duration\r${ANSI_CLEAR}"
|
68
|
+
return $result
|
69
|
+
}
|
70
|
+
|
71
|
+
function travis_nanoseconds() {
|
72
|
+
local cmd="date"
|
73
|
+
local format="+%s%N"
|
74
|
+
local os=$(uname)
|
75
|
+
|
76
|
+
if hash gdate > /dev/null 2>&1; then
|
77
|
+
cmd="gdate" # use gdate if available
|
78
|
+
elif [[ "$os" = Darwin ]]; then
|
79
|
+
format="+%s000000000" # fallback to second precision on darwin (does not support %N)
|
80
|
+
fi
|
81
|
+
|
82
|
+
$cmd -u $format
|
83
|
+
}
|
84
|
+
|
85
|
+
travis_assert() {
|
86
|
+
local result=${1:-$?}
|
87
|
+
if [ $result -ne 0 ]; then
|
88
|
+
echo -e "\n${ANSI_RED}The command \"$TRAVIS_CMD\" failed and exited with $result during $TRAVIS_STAGE.${ANSI_RESET}\n\nYour build has been stopped."
|
89
|
+
travis_terminate 2
|
90
|
+
fi
|
91
|
+
}
|
92
|
+
|
93
|
+
travis_result() {
|
94
|
+
local result=$1
|
95
|
+
export TRAVIS_TEST_RESULT=$(( ${TRAVIS_TEST_RESULT:-0} | $(($result != 0)) ))
|
96
|
+
if [ $result -eq 0 ]; then
|
97
|
+
echo -e "\n${ANSI_GREEN}The command \"$TRAVIS_CMD\" exited with $result.${ANSI_RESET}"
|
98
|
+
else
|
99
|
+
echo -e "\n${ANSI_RED}The command \"$TRAVIS_CMD\" exited with $result.${ANSI_RESET}"
|
100
|
+
fi
|
101
|
+
}
|
102
|
+
|
103
|
+
travis_terminate() {
|
104
|
+
pkill -9 -P $$ &> /dev/null || true
|
105
|
+
exit $1
|
106
|
+
}
|
107
|
+
|
108
|
+
travis_wait() {
|
109
|
+
local timeout=$1
|
110
|
+
|
111
|
+
if [[ $timeout =~ ^[0-9]+$ ]]; then
|
112
|
+
# looks like an integer, so we assume it's a timeout
|
113
|
+
shift
|
114
|
+
else
|
115
|
+
# default value
|
116
|
+
timeout=20
|
117
|
+
fi
|
118
|
+
|
119
|
+
local cmd="$@"
|
120
|
+
local log_file=travis_wait_$$.log
|
121
|
+
|
122
|
+
$cmd &>$log_file &
|
123
|
+
local cmd_pid=$!
|
124
|
+
|
125
|
+
travis_jigger $! $timeout $cmd &
|
126
|
+
local jigger_pid=$!
|
127
|
+
local result
|
128
|
+
|
129
|
+
{
|
130
|
+
wait $cmd_pid 2>/dev/null
|
131
|
+
result=$?
|
132
|
+
ps -p$jigger_pid &>/dev/null && kill $jigger_pid
|
133
|
+
} || return 1
|
134
|
+
|
135
|
+
if [ $result -eq 0 ]; then
|
136
|
+
echo -e "\n${ANSI_GREEN}The command \"$TRAVIS_CMD\" exited with $result.${ANSI_RESET}"
|
137
|
+
else
|
138
|
+
echo -e "\n${ANSI_RED}The command \"$TRAVIS_CMD\" exited with $result.${ANSI_RESET}"
|
139
|
+
fi
|
140
|
+
|
141
|
+
echo -e "\n${ANSI_GREEN}Log:${ANSI_RESET}\n"
|
142
|
+
cat $log_file
|
143
|
+
|
144
|
+
return $result
|
145
|
+
}
|
146
|
+
|
147
|
+
travis_jigger() {
|
148
|
+
# helper method for travis_wait()
|
149
|
+
local cmd_pid=$1
|
150
|
+
shift
|
151
|
+
local timeout=$1 # in minutes
|
152
|
+
shift
|
153
|
+
local count=0
|
154
|
+
|
155
|
+
# clear the line
|
156
|
+
echo -e "\n"
|
157
|
+
|
158
|
+
while [ $count -lt $timeout ]; do
|
159
|
+
count=$(($count + 1))
|
160
|
+
echo -ne "Still running $count of $timeout: $@\r"
|
161
|
+
sleep 60
|
162
|
+
done
|
163
|
+
|
164
|
+
echo -e "\n${ANSI_RED}Timeout ${timeout} minutes reached. Terminating \"$@\"${ANSI_RESET}\n"
|
165
|
+
kill -9 $cmd_pid
|
166
|
+
}
|
167
|
+
|
168
|
+
travis_retry() {
|
169
|
+
local result=0
|
170
|
+
local count=1
|
171
|
+
while [ $count -le 3 ]; do
|
172
|
+
[ $result -ne 0 ] && {
|
173
|
+
echo -e "\n${ANSI_RED}The command \"$@\" failed. Retrying, $count of 3.${ANSI_RESET}\n" >&2
|
174
|
+
}
|
175
|
+
"$@"
|
176
|
+
result=$?
|
177
|
+
[ $result -eq 0 ] && break
|
178
|
+
count=$(($count + 1))
|
179
|
+
sleep 1
|
180
|
+
done
|
181
|
+
|
182
|
+
[ $count -gt 3 ] && {
|
183
|
+
echo -e "\n${ANSI_RED}The command \"$@\" failed 3 times.${ANSI_RESET}\n" >&2
|
184
|
+
}
|
185
|
+
|
186
|
+
return $result
|
187
|
+
}
|
188
|
+
|
189
|
+
travis_fold() {
|
190
|
+
local action=$1
|
191
|
+
local name=$2
|
192
|
+
echo -en "travis_fold:${action}:${name}\r${ANSI_CLEAR}"
|
193
|
+
}
|
194
|
+
|
195
|
+
decrypt() {
|
196
|
+
echo $1 | base64 -d | openssl rsautl -decrypt -inkey ~/.ssh/id_rsa.repo
|
197
|
+
}
|
198
|
+
|
199
|
+
mkdir -p <%= BUILD_DIR %>
|
200
|
+
cd <%= @working_dir %>
|
201
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
mkdir ~/bin
|
2
|
+
cat > ~/bin/xcodebuild <<EOF
|
3
|
+
#!/usr/bin/env perl
|
4
|
+
|
5
|
+
my $status = 1;
|
6
|
+
|
7
|
+
open my $fh, "-|", @ARGV
|
8
|
+
or die "unable to run command: $!\n";
|
9
|
+
|
10
|
+
while (my $line = readline($fh)) {
|
11
|
+
print $line;
|
12
|
+
$status = 0 if $line =~ /^\*\* TEST SUCCEEDED \*\*$/;
|
13
|
+
}
|
14
|
+
|
15
|
+
close $fh;
|
16
|
+
|
17
|
+
exit $status;
|
18
|
+
EOF
|
19
|
+
chmod +x ~/bin/xcodebuild
|
20
|
+
|
21
|
+
export PATH="$HOME/bin:$PATH"
|