Skip to content

Instantly share code, notes, and snippets.

@DenTelezhkin
Last active December 8, 2016 10:08
Show Gist options
  • Save DenTelezhkin/b3adef5cabd067129b89 to your computer and use it in GitHub Desktop.
Save DenTelezhkin/b3adef5cabd067129b89 to your computer and use it in GitHub Desktop.
Rakefile for iTunesConnect upload and testing, iOS

What's this stuff about?

This is a build script for installing dependencies, running tests, and uploading your iOS application builds to Apple's iTunesConnect & Testflight.

Used technologies

  • CocoaPods
  • XCTest
  • Ruby gems: xcpretty, deliver, shenzhen
  • Apple's iTunesConnect&Testflight

Setup

You'll also need to setup Deliverfile to make deliver gem work, instructions

Usage

rake # run tests

rake ci # clean, reinstall CocoaPods, run tests

rake itunesconnect # Clean, reinstall Cocoapods, run tests, make build and upload it to iTunesConnect.

rake itunesconnect configuration=Stable # The same as above, but with build configuration Stable
require 'shenzhen'
require 'xcpretty'
require 'cocoapods'
require 'deliver'
workspace_file = "MyWorkspace.xcworkspace"
scheme_name = "MyScheme"
configuration = "Release"
# iTunesConnect user, used by deliver ruby gem. It will be securely stored on keychain after first run.
# Password is asked once, and also saved for this user.
# read more https://github.com/KrauseFx/deliver
deliver_user = 'ITUNES_CONNECT_EMAIL'
def run(command, min_exit_status = 0)
puts "Executing: `#{command}`"
system(command)
return $?.exitstatus
end
def runDeliverFromUser()
cmd = 'deliver'
deliver_status = 0
fork do
ENV['DELIVER_USER'] = deliver_user;
$deliver_status = system(cmd);
end
child_pid = Process.wait
$deliver_status
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 "Get configuration"
task :configuration do
configuration = ENV['configuration']
configuration ||= "Release"
puts "Using configuration: " + configuration
end
desc "Run #{scheme_name} tests"
task :run_tests do
$tests_success = run("set -o pipefail && xcodebuild -scheme \"#{scheme_name}\" -workspace #{workspace_file} -sdk iphonesimulator -destination 'name=iPhone 6' 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 ipa to iTunesConnect"
task itunesconnect: ['clean','dependencies','run_tests','configuration'] do
if ($tests_success == 0)
runDeliverFromUser()
Rake::Task['clean_ipa'].invoke
exit(-1) unless $deliver_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: :run_tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment