travis-xcodebuild 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1f4b6b1c058bbf3508fdae66110ac5cb2aa8c19f
4
+ data.tar.gz: 657f5b84cdc644ed2cf6a05468281fd3246255ec
5
+ SHA512:
6
+ metadata.gz: 09760f24dd2a97d3479e895898f5888ec88a85b89ceeae2910413024fe87dac4c43d570f73b3869f88e0c4946f1b55c44dd5e2fc6ebeb17235b5e840f8bcdc4e
7
+ data.tar.gz: e66705ce8e3406bc10ded35b8a6866b1406b1e3f9e8d622954be1bbb87e8fcc0f4535dc393bf2232207ef18af9109b032a1ab620a6d33eb985b44b9f18ee50c7
@@ -0,0 +1,34 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /lib/bundler/man/
26
+
27
+ # for a library or gem, you might want to ignore these files since the code is
28
+ # intended to run in multiple environments; otherwise, check them in:
29
+ # Gemfile.lock
30
+ # .ruby-version
31
+ # .ruby-gemset
32
+
33
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
+ .rvmrc
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Justin Mutter
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,4 @@
1
+ travis-xcodebuild
2
+ =================
3
+
4
+ Gem for running builds on Travis-CI with xcodebuild instead of xctool
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ if $0 == __FILE__
4
+ $:.unshift File.expand_path('../../lib', __FILE__)
5
+ end
6
+
7
+ require 'travis-xcodebuild'
8
+
9
+ runner = TravisXcodebuild::Runner.new
10
+ runner.run
@@ -0,0 +1,21 @@
1
+ # This is Travis-CI's implementation instead of the current activesupport version
2
+ # https://github.com/travis-ci/travis-build/blob/master/lib/core_ext/hash/deep_symbolize_keys.rb
3
+ class Hash
4
+ def deep_symbolize_keys
5
+ inject({}) { |result, (key, value)|
6
+ result[(key.to_sym rescue key) || key] = case value
7
+ when Array
8
+ value.map { |value| value.is_a?(Hash) ? value.deep_symbolize_keys : value }
9
+ when Hash
10
+ value.deep_symbolize_keys
11
+ else
12
+ value
13
+ end
14
+ result
15
+ }
16
+ end unless Hash.method_defined?(:deep_symbolize_keys)
17
+
18
+ def deep_symbolize_keys!
19
+ replace(deep_symbolize_keys)
20
+ end unless Hash.method_defined?(:deep_symbolize_keys!)
21
+ end
@@ -0,0 +1,22 @@
1
+ require 'yaml'
2
+ require 'travis-xcodebuild/logging'
3
+ require 'travis-xcodebuild/runner'
4
+ require 'core_ext/deep_symbolize_keys'
5
+
6
+ module TravisXcodebuild
7
+
8
+ class << self
9
+ def config
10
+ @config ||= begin
11
+ load_file = YAML::load_file('.travis.yml') if File.exists?('.travis.yml')
12
+ config = load_file.deep_symbolize_keys || {}
13
+ %w[project workspace scheme sdk].each do |var|
14
+ envar = ENV["TRAVIS_XCODE_#{var.upcase}"]
15
+ config[:"xcode_#{var}"] = envar if envar && !envar.empty?
16
+ end
17
+ config
18
+ end
19
+ end
20
+ end
21
+
22
+ end
@@ -0,0 +1,34 @@
1
+ require 'colorize'
2
+
3
+ module TravisXcodebuild
4
+ module Logging
5
+
6
+ def log_info(string)
7
+ puts "[info] #{string}".white
8
+ puts
9
+ end
10
+
11
+ def log_warning(string)
12
+ puts "[warning] #{string}".yellow
13
+ puts
14
+ end
15
+
16
+ def log_failure(string)
17
+ puts "[failure] #{string}".red
18
+ puts
19
+ end
20
+
21
+ def log_success(string)
22
+ puts "[success] #{string}".green
23
+ puts
24
+ end
25
+
26
+ def log_analyzer(warnings)
27
+ return unless warnings.length > 0
28
+ puts "[analyzer] Found clang analyzer warnings in the following files:".yellow
29
+ warnings.each { |warning| puts " - #{warning}".yellow }
30
+ puts
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,140 @@
1
+ require 'pty'
2
+
3
+ module TravisXcodebuild
4
+
5
+ class Runner
6
+ include Logging
7
+
8
+ #captures the number of files in group 1
9
+ CLANG_ISSUES_REGEX = /\((\d) commands with analyzer issues\)/
10
+ NO_FAILURES_REGEX = /with 0 failures/
11
+ TEST_FAILED_REGEX = /TEST FAILED/
12
+
13
+ attr_reader :output, :analyzer_alerts, :stage
14
+
15
+ def initialize(options = {})
16
+ @output = []
17
+ @pid = nil
18
+ @options = options
19
+ end
20
+
21
+ def analyzer_alerts
22
+ @analyzer_alerts ||= begin
23
+ alerts = []
24
+ @output.each_with_index do |line, index|
25
+ if match = CLANG_ISSUES_REGEX.match(line)
26
+ start_index = index - match[1].to_i
27
+ end_index = index - 1
28
+ alerts += @output[start_index..end_index]
29
+ end
30
+ end
31
+ alerts.collect { |line| line.gsub!(/Analyze /, "")}
32
+ end
33
+ end
34
+
35
+ def run
36
+ run_xcodebuild
37
+ finish_build
38
+ end
39
+
40
+ private
41
+
42
+ def run_xcodebuild
43
+ run_external "xcodebuild #{target} #{destination} clean analyze test | tee output.txt | xcpretty -c; exit ${PIPESTATUS[0]}"
44
+ end
45
+
46
+ def finish_build
47
+ verify_xcodebuild
48
+ verify_analyzer
49
+ end
50
+
51
+ def verify_xcodebuild
52
+ status = PTY.check(@pid)
53
+ if status.nil?
54
+ log_warning "Unable to get xcodebuild exit status, checking log for test results..."
55
+ if @output.last =~ NO_FAILURES_REGEX
56
+ log_success "Looks like all the tests passed :)"
57
+ else
58
+ if @output.last =~ TEST_FAILED_REGEX
59
+ log_failure "TEST FAILED detected, exiting with non-zero status code"
60
+ else
61
+ log_warning "Unable to determine test status from build log, did something terrible happen?"
62
+ end
63
+ exit 1
64
+ end
65
+ elsif status.exitstatus > 0
66
+ exit status.exitstatus
67
+ end
68
+ end
69
+
70
+ def verify_analyzer
71
+ log_analyzer analyzer_alerts
72
+ if analyzer_fails_build?
73
+ threshold = config[:clang_analyzer][:threshold] || 0
74
+ if analyzer_alerts.length > threshold
75
+ log_failure "Analyzer warnings exceeded threshold of #{threshold}, failing build"
76
+ exit 1
77
+ end
78
+ end
79
+ end
80
+
81
+ def run_external(cmd)
82
+ log_info "Running: \n#{cmd}"
83
+ begin
84
+ PTY.spawn( cmd ) do |output, input, pid|
85
+ @pid = pid
86
+ begin
87
+ output.each do |line|
88
+ print line
89
+ string = colorless(line).strip
90
+ @output << string if string.length > 0
91
+ end
92
+ rescue Errno::EIO
93
+ puts "Errno:EIO error, did the process finish giving output?"
94
+ end
95
+ end
96
+ rescue PTY::ChildExited
97
+ puts "The child process exited!"
98
+ end
99
+ end
100
+
101
+ def colorless(string)
102
+ string.gsub(/\e\[(\d+);?(\d*)m/, '')
103
+ end
104
+
105
+ def destination_specifier
106
+ if config[:xcode_sdk].start_with?("macosx")
107
+ destination_specifier = 'platform=OS X'
108
+ else
109
+ name = ENV['IOS_PLATFORM_NAME'] || 'iPad'
110
+ os = config[:xcode_sdk].scan(/\d+\.\d+/).first || 'latest'
111
+ destination_specifier = "platform=iOS Simulator,name=#{name},OS=#{os}"
112
+ end
113
+ destination_specifier
114
+ end
115
+
116
+ def destination
117
+ "-destination '#{destination_specifier}'"
118
+ end
119
+
120
+ def target
121
+ target_str = ""
122
+ %w[project workspace scheme].each do |var|
123
+ target_str << " -#{var} #{config[:"xcode_#{var}"]}" if config[:"xcode_#{var}"]
124
+ end
125
+ target_str
126
+ end
127
+
128
+ def config
129
+ TravisXcodebuild.config
130
+ end
131
+
132
+ def analyzer_fails_build?
133
+ if config[:clang_analyzer]
134
+ config[:clang_analyzer][:fail_build]
135
+ end
136
+ end
137
+
138
+ end
139
+
140
+ end
@@ -0,0 +1,18 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "travis-xcodebuild"
3
+ spec.version = "0.0.2"
4
+ spec.authors = ["Justin Mutter"]
5
+ spec.email = ["justin@shopify.com"]
6
+ spec.required_ruby_version = '>= 1.8.7'
7
+ spec.description = "Run builds on Travis-CI using `xcodebuild` and `xcpretty` instead of `xctool`"
8
+ spec.summary = "xcodebuild runner for Travis-CI"
9
+ spec.homepage = "https://github.com/j-mutter/travis-xcodebuild"
10
+ spec.license = "MIT"
11
+
12
+ spec.files = `git ls-files`.split($/)
13
+ spec.executables << 'travis-xcodebuild'
14
+
15
+ spec.add_development_dependency "bundler", "~> 1.3"
16
+ spec.add_runtime_dependency "xcpretty"
17
+ spec.add_runtime_dependency "colorize"
18
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: travis-xcodebuild
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Justin Mutter
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: xcpretty
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: colorize
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Run builds on Travis-CI using `xcodebuild` and `xcpretty` instead of
56
+ `xctool`
57
+ email:
58
+ - justin@shopify.com
59
+ executables:
60
+ - travis-xcodebuild
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".gitignore"
65
+ - LICENSE
66
+ - README.md
67
+ - bin/travis-xcodebuild
68
+ - lib/core_ext/deep_symbolize_keys.rb
69
+ - lib/travis-xcodebuild.rb
70
+ - lib/travis-xcodebuild/logging.rb
71
+ - lib/travis-xcodebuild/runner.rb
72
+ - travis-xcodebuild.gemspec
73
+ homepage: https://github.com/j-mutter/travis-xcodebuild
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: 1.8.7
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.2.2
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: xcodebuild runner for Travis-CI
97
+ test_files: []
98
+ has_rdoc: