Install dependencies and run tests
rake
Dependencies, tests, archive in Release configuration and upload to TestFlight
rake testflight
Same as previous task, but Stable configuration.
rake testflight configuration=Stable
require 'shenzhen' | |
require 'xcpretty' | |
require 'cocoapods' | |
require 'date' | |
testflight_api_token = "TESTFLIGHT_API_TOKEN" | |
testflight_team_token = "TESTFLIGHT_TEAM_TOKEN" | |
workspace_file = "MyWorkspace.xcworkspace" | |
scheme_name = "MySchemeName" | |
testflight_distribution_lists = "MY_DISTRIBUTION_LIST" | |
def run(command, min_exit_status = 0) | |
puts "Executing: `#{command}`" | |
system(command) | |
return $?.exitstatus | |
end | |
desc "Cleaning environment" | |
task :clean do | |
run("rm -rf Build && rm -rf DerivedData && rm -rf Pods && rm -rf #{workspace_file}") | |
end | |
desc "install dependencies" | |
task :dependencies do | |
run("pod install") | |
end | |
desc "Run #{scheme_name} tests" | |
task :run_tests do | |
$tests_success = run("set -o pipefail && xcodebuild -scheme \"#{scheme_name}\" -workspace \"#{workspace_file}\" -destination 'name=iPhone Retina (4-inch),OS=7.1' clean test | xcpretty -tc") | |
end | |
desc "Clean ipa artefacts" | |
task :clean_ipa do | |
run("rm -rf *.ipa && rm -rf *.app.dSYM.zip") | |
end | |
desc "Upload application to Testflight" | |
task :testflight => ['clean','dependencies','run_tests'] do | |
if ($tests_success == 0) | |
configuration = ENV['configuration'] | |
configuration ||= "Release" | |
puts "Using configuration: " + configuration | |
build_status = run("ipa build -s #{scheme_name} --configuration #{configuration}") | |
upload_time = Time.now.strftime("%d/%m/%Y") | |
upload_status = run("ipa distribute:testflight -a #{testflight_api_token} -T #{testflight_team_token} -l \"#{testflight_distribution_lists}\" --notify -m '#{scheme_name}-#{configuration} #{upload_time}.'") | |
Rake::Task['clean_ipa'].invoke | |
exit(-1) unless build_status==0 && upload_status == 0 | |
else | |
puts "\033[0;31m! #{scheme_name} unit tests failed" | |
exit(-1) | |
end | |
end | |
desc "Test and compile #{scheme_name}" | |
task :ci => ['clean','dependencies','run_tests'] do | |
puts "\033[0;31m! #{scheme_name} unit tests failed" unless $tests_success == 0 | |
if ($tests_success == 0) | |
puts "\033[0;32m** All is good!" | |
else | |
exit(-1) | |
end | |
end | |
task default: 'ci' |