-
Notifications
You must be signed in to change notification settings - Fork 58
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
1 parent
a63622b
commit 8d83daf
Showing
8 changed files
with
154 additions
and
76 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,79 +1,12 @@ | ||
def xcpretty(cmd, task) | ||
name = task.name.gsub(/:/,"_") | ||
xcpretty = `which xcpretty` | ||
#!/usr/bin/rake | ||
|
||
if ENV['CI'] | ||
sh "set -o pipefail && #{cmd} | 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 && #{cmd} | xcpretty -c" | ||
else | ||
sh cmd | ||
end | ||
end | ||
## [ Constants ] ############################################################## | ||
|
||
def plain(cmd, task) | ||
name = task.name.gsub(/:/,"_") | ||
if ENV['CI'] | ||
sh "set -o pipefail && #{cmd} | tee \"#{ENV['CIRCLE_ARTIFACTS']}/#{name}_raw.log\"" | ||
else | ||
sh cmd | ||
end | ||
end | ||
WORKSPACE = 'StencilSwiftKit' | ||
TARGET_NAME = 'Tests' | ||
CONFIGURATION = 'Debug' | ||
POD_NAME = 'StencilSwiftKit' | ||
TEST_PATH = "Tests/#{POD_NAME}Tests" | ||
|
||
namespace :spm do | ||
desc 'Build using SPM' | ||
task :build do |task| | ||
plain("swift build", task) | ||
end | ||
|
||
desc 'Run SPM Unit Tests' | ||
task :test => :build do |task| | ||
plain("swift test", task) | ||
end | ||
end | ||
|
||
namespace :xcode do | ||
desc 'Build using Xcode' | ||
task :build do |task| | ||
xcpretty("xcodebuild -workspace StencilSwiftKit.xcworkspace -scheme Tests build-for-testing", task) | ||
end | ||
|
||
desc 'Run Xcode Unit Tests' | ||
task :test => :build do |task| | ||
xcpretty("xcodebuild -workspace StencilSwiftKit.xcworkspace -scheme Tests test-without-building", task) | ||
end | ||
end | ||
|
||
namespace :lint do | ||
desc 'Install swiftlint' | ||
task :install do |task| | ||
swiftlint = `which swiftlint` | ||
|
||
if !(swiftlint && $?.success?) | ||
url = 'https://github.com/realm/SwiftLint/releases/download/0.16.1/SwiftLint.pkg' | ||
tmppath = '/tmp/SwiftLint.pkg' | ||
|
||
plain("curl -Lo #{tmppath} #{url}", task) | ||
plain("sudo installer -pkg #{tmppath} -target /", task) | ||
end | ||
end | ||
|
||
desc 'Lint the code' | ||
task :code => :install do |task| | ||
plain("swiftlint lint --no-cache --strict --path Sources", task) | ||
end | ||
|
||
desc 'Lint the tests' | ||
task :tests => :install do |task| | ||
plain("swiftlint lint --no-cache --strict --path Tests/StencilSwiftKitTests", task) | ||
end | ||
end | ||
|
||
namespace :pod do | ||
desc 'Lint the Pod' | ||
task :lint do |task| | ||
plain("pod lib lint StencilSwiftKit.podspec --quick", task) | ||
end | ||
end | ||
|
||
task :default => "xcode:test" | ||
task :default => 'xcode:test' |
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,26 @@ | ||
namespace :lint do | ||
desc 'Install swiftlint' | ||
task :install do |task| | ||
if !system('which swiftlint > /dev/null') | ||
url = 'https://github.com/realm/SwiftLint/releases/download/0.16.1/SwiftLint.pkg' | ||
tmppath = '/tmp/SwiftLint.pkg' | ||
|
||
Utils.run([ | ||
"curl -Lo #{tmppath} #{url}", | ||
"sudo installer -pkg #{tmppath} -target /" | ||
], task) | ||
end | ||
end | ||
|
||
desc 'Lint the code' | ||
task :code => :install do |task| | ||
Utils.print_info 'Linting the code' | ||
Utils.run(%Q(swiftlint lint --no-cache --strict --path Sources), task) | ||
end | ||
|
||
desc 'Lint the tests' | ||
task :tests => :install do |task| | ||
Utils.print_info 'Linting the unit test code' | ||
Utils.run(%Q(swiftlint lint --no-cache --strict --path "#{TEST_PATH}"), 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace :pod do | ||
desc 'Lint the Pod' | ||
task :lint do |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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace :spm do | ||
desc 'Build using SPM' | ||
task :build do |task| | ||
Utils.print_info 'Compile using SPM' | ||
Utils.run("swift build", task, xcrun: true) | ||
end | ||
|
||
desc 'Run SPM Unit Tests' | ||
task :test => :build do |task| | ||
Utils.print_info 'Run the unit tests using SPM' | ||
Utils.run("swift test", task, xcrun: true) | ||
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,68 @@ | ||
class Utils | ||
|
||
# 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 xcpretty | ||
xcpretty(commands, task, subtask) | ||
elsif !direct | ||
plain(commands, task, subtask) | ||
else | ||
`#{commands.join(' && ')}` | ||
end | ||
end | ||
|
||
# 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 | ||
|
||
## [ 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 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 | ||
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 | ||
|
||
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,13 @@ | ||
namespace :xcode do | ||
desc 'Build using Xcode' | ||
task :build do |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| | ||
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 |