This repository has been archived by the owner on Sep 6, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
70 additions
and
62 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
namespace :pod do | ||
desc 'Lint the Pod' | ||
task :lint do |task| | ||
print_info 'Linting the pod spec' | ||
plain(%Q(pod lib lint "#{POD_NAME}.podspec" --quick), task) | ||
Utils.print_info 'Linting the pod spec' | ||
Utils.run(%Q(pod lib lint "#{POD_NAME}.podspec" --quick), task) | ||
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 |
---|---|---|
@@ -1,58 +1,68 @@ | ||
# run a command, pipe output through 'xcpretty' and store the output in CI artifacts | ||
def xcpretty(cmd, task, subtask = '') | ||
name = (task.name + (subtask.empty? ? '' : "_#{subtask}")).gsub(/[:-]/, "_") | ||
command = [*cmd].join(' && ') | ||
xcpretty = `which xcpretty` | ||
|
||
if ENV['CI'] | ||
sh "set -o pipefail && (#{command}) | tee \"#{ENV['CIRCLE_ARTIFACTS']}/#{name}_raw.log\" | xcpretty --color --report junit --output \"#{ENV['CIRCLE_TEST_REPORTS']}/xcode/#{name}.xml\"" | ||
elsif xcpretty && $?.success? | ||
sh "set -o pipefail && (#{command}) | xcpretty -c" | ||
else | ||
sh command | ||
end | ||
end | ||
class Utils | ||
|
||
# run a command and store the output in CI artifacts | ||
def plain(cmd, task, subtask = '') | ||
name = (task.name + (subtask.empty? ? '' : "_#{subtask}")).gsub(/[:-]/, "_") | ||
command = [*cmd].join(' && ') | ||
# run a command using xcrun and xcpretty if applicable | ||
def self.run(cmd, task, subtask = '', xcrun: false, xcpretty: false, direct: false) | ||
commands = xcrun ? [*cmd].map { |cmd| | ||
"#{version_select} xcrun #{cmd}" | ||
} : [*cmd] | ||
|
||
if ENV['CI'] | ||
sh "set -o pipefail && (#{command}) | tee \"#{ENV['CIRCLE_ARTIFACTS']}/#{name}_raw.log\"" | ||
else | ||
sh command | ||
if xcpretty | ||
xcpretty(commands, task, subtask) | ||
elsif !direct | ||
plain(commands, task, subtask) | ||
else | ||
`#{commands.join(' && ')}` | ||
end | ||
end | ||
end | ||
|
||
# select the xcode version we want/support | ||
def version_select | ||
xcodes = `mdfind "kMDItemCFBundleIdentifier = 'com.apple.dt.Xcode' && kMDItemVersion = '8.*'"`.chomp.split("\n") | ||
if xcodes.empty? | ||
raise "\n[!!!] You need to have Xcode 8.x to compile SwiftGen.\n\n" | ||
# print an info header | ||
def self.print_info(str) | ||
(red,clr) = (`tput colors`.chomp.to_i >= 8) ? %W(\e[33m \e[m) : ["", ""] | ||
puts red, "== #{str.chomp} ==", clr | ||
end | ||
|
||
# Order by version and get the latest one | ||
vers = lambda { |path| `mdls -name kMDItemVersion -raw "#{path}"` } | ||
latest_xcode_version = xcodes.sort { |p1, p2| vers.call(p1) <=> vers.call(p2) }.last | ||
%Q(DEVELOPER_DIR="#{latest_xcode_version}/Contents/Developer") | ||
end | ||
|
||
# run a command using xcrun and xcpretty if applicable | ||
def xcrun(cmd, task, subtask = '') | ||
commands = [*cmd].map { |cmd| | ||
"#{version_select} xcrun #{cmd}" | ||
} | ||
## [ Private helper functions ] ################################################## | ||
|
||
# run a command, pipe output through 'xcpretty' and store the output in CI artifacts | ||
def self.xcpretty(cmd, task, subtask) | ||
name = (task.name + (subtask.empty? ? '' : "_#{subtask}")).gsub(/[:-]/, "_") | ||
command = [*cmd].join(' && ') | ||
|
||
if commands.join.match('xcodebuild') | ||
xcpretty(commands, task, subtask) | ||
else | ||
plain(commands, task, subtask) | ||
if ENV['CI'] | ||
Rake.sh "set -o pipefail && (#{command}) | tee \"#{ENV['CIRCLE_ARTIFACTS']}/#{name}_raw.log\" | xcpretty --color --report junit --output \"#{ENV['CIRCLE_TEST_REPORTS']}/xcode/#{name}.xml\"" | ||
elsif system('which xcpretty > /dev/null') | ||
Rake.sh "set -o pipefail && (#{command}) | xcpretty -c" | ||
else | ||
Rake.sh command | ||
end | ||
end | ||
end | ||
private_class_method :xcpretty | ||
|
||
# run a command and store the output in CI artifacts | ||
def self.plain(cmd, task, subtask) | ||
name = (task.name + (subtask.empty? ? '' : "_#{subtask}")).gsub(/[:-]/, "_") | ||
command = [*cmd].join(' && ') | ||
|
||
if ENV['CI'] | ||
Rake.sh "set -o pipefail && (#{command}) | tee \"#{ENV['CIRCLE_ARTIFACTS']}/#{name}_raw.log\"" | ||
else | ||
Rake.sh command | ||
end | ||
end | ||
private_class_method :plain | ||
|
||
# select the xcode version we want/support | ||
def self.version_select | ||
xcodes = `mdfind "kMDItemCFBundleIdentifier = 'com.apple.dt.Xcode' && kMDItemVersion = '8.*'"`.chomp.split("\n") | ||
if xcodes.empty? | ||
raise "\n[!!!] You need to have Xcode 8.x to compile SwiftGen.\n\n" | ||
end | ||
|
||
# Order by version and get the latest one | ||
vers = lambda { |path| `mdls -name kMDItemVersion -raw "#{path}"` } | ||
latest_xcode_version = xcodes.sort { |p1, p2| vers.call(p1) <=> vers.call(p2) }.last | ||
%Q(DEVELOPER_DIR="#{latest_xcode_version}/Contents/Developer") | ||
end | ||
private_class_method :version_select | ||
|
||
# print an info header | ||
def print_info(str) | ||
(red,clr) = (`tput colors`.chomp.to_i >= 8) ? %W(\e[33m \e[m) : ["", ""] | ||
puts red, "== #{str.chomp} ==", clr | ||
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 |
---|---|---|
@@ -1,13 +1,13 @@ | ||
namespace :xcode do | ||
desc 'Build using Xcode' | ||
task :build do |task| | ||
print_info 'Compile using Xcode' | ||
xcrun(%Q(xcodebuild -workspace "#{WORKSPACE}.xcworkspace" -scheme "#{TARGET_NAME}" -configuration "#{CONFIGURATION}" build-for-testing), task) | ||
Utils.print_info 'Compile using Xcode' | ||
Utils.run(%Q(xcodebuild -workspace "#{WORKSPACE}.xcworkspace" -scheme "#{TARGET_NAME}" -configuration "#{CONFIGURATION}" build-for-testing), task, xcrun: true, xcpretty: true) | ||
end | ||
|
||
desc 'Run Xcode Unit Tests' | ||
task :test => :build do |task| | ||
print_info 'Run the unit tests using Xcode' | ||
xcrun(%Q(xcodebuild -workspace "#{WORKSPACE}.xcworkspace" -scheme "#{TARGET_NAME}" -configuration "#{CONFIGURATION}" test-without-building), task) | ||
Utils.print_info 'Run the unit tests using Xcode' | ||
Utils.run(%Q(xcodebuild -workspace "#{WORKSPACE}.xcworkspace" -scheme "#{TARGET_NAME}" -configuration "#{CONFIGURATION}" test-without-building), task, xcrun: true, xcpretty: true) | ||
end | ||
end |