Skip to content

Instantly share code, notes, and snippets.

@ericdagenais
Forked from oppara/Rakefile
Last active February 21, 2018 00:36
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ericdagenais/1525227 to your computer and use it in GitHub Desktop.
Save ericdagenais/1525227 to your computer and use it in GitHub Desktop.
Titanium Mobile Rakefile Build and TestFlight API Script for iOS
DEV_PROVISIONING_UUID = 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'
DEV_SIGN = 'Your Signing Name'
ADHOC_PROVISIONING_UUID = 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'
ADHOC_SIGN = 'Your Signing Name'
DEV_APP_DEVICE = 'ipad' # or iphone, universal
IPHONE_SDK_VERSION = '5.0'
TF_TEAM_TOKEN = 'insert TestFlight team token here'
TF_API_TOKEN = 'insert TestFlight API token here'
TF_DIST_LISTS = 'Core Dev'
PIECEABLE_EMAIL = 'name@example.com'
import 'titanium_build.rake'
#
# Titanium Mobile Rakefile Build and TestFlight API Script for iOS
#
# +Helps to automate building packages, zipping debug symbols, and TestFlight uploads
#
# +Also provides a convenient command line interface to the Titanium build system
# which comes in handy when using a text editor
#
# https://gist.github.com/1525227
#
# Eric Dagenais
# 2012-05-20
#
# Quickstart:
# 1a. Create a file named 'Rakefile' with the contents between =begin and =end (not including
# =begin and =end)
# 1b. Replace the placeholders with the appropriate values and save the file at the root level
# of your Titanium project (the same folder where tiapp.xml resides)
# 2. 'rake run' will run the app in the simulator
# 3. 'rake testflight' will upload the adhoc build and debug symbols to TestFlight
# 4. 'rake -T' for complete usage
#
=begin
DEV_PROVISIONING_UUID = 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'
DEV_SIGN = 'Your Signing Name'
ADHOC_PROVISIONING_UUID = 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'
ADHOC_SIGN = 'Your Signing Name'
DEV_APP_DEVICE = 'ipad' # or iphone, universal
IPHONE_SDK_VERSION = '5.0'
TF_TEAM_TOKEN = 'insert TestFlight team token here'
TF_API_TOKEN = 'insert TestFlight API token here'
TF_DIST_LISTS = 'Core Dev'
PIECEABLE_EMAIL = 'name@example.com'
import 'titanium_build.rake'
=end
require 'rubygems'
require 'json'
require 'rexml/document'
require 'uri'
xmlConfig = REXML::Document.new(File.new('tiapp.xml')).elements
devAppName = "#{xmlConfig["ti:app/name"].text}"
devAppId = "#{xmlConfig["ti:app/id"].text}"
xmlVersion = "#{xmlConfig["ti:app/version"].text}"
sdkVersion = "#{xmlConfig["ti:app/sdk-version"].text}"
BUILDER = "/Library/Application Support/Titanium/mobilesdk/osx/#{sdkVersion}/iphone/builder.py"
PROJDIR = "#{Dir.pwd}/"
RAKELOG = "build/iphone/rake.log"
version = "#{devAppName}-#{xmlVersion}"
if(File.directory?("build/adhoc/#{version}"))
version = "#{version}-#{Time.now.strftime("%Y%m%d-%H%M%S")}"
puts "WARNING: build for version #{xmlVersion} already exists, adding timestamp ==> #{version}"
end
desc "Same as run"
task :default => [:run]
desc "Build and run app in simulator (development)"
task :run do
sh BUILDER, 'run', PROJDIR, IPHONE_SDK_VERSION, devAppId, devAppName, DEV_APP_DEVICE
end
desc "Build and run app in simulator (development)"
task :run4 do
sh BUILDER, 'run', PROJDIR, "4.3", devAppId, devAppName, DEV_APP_DEVICE
end
desc "Build full app for simulator (development)"
task :buildfull do
sh BUILDER, 'buildfull', IPHONE_SDK_VERSION, PROJDIR, devAppId, devAppName, DEV_APP_DEVICE
end
desc "Build and install app on device via iTunes (development)"
task :install do
sh BUILDER, 'install', IPHONE_SDK_VERSION, PROJDIR, devAppId, devAppName, DEV_PROVISIONING_UUID, DEV_SIGN, DEV_APP_DEVICE
end
desc "Build distribution app package for device (adhoc)"
task :distribute do
Dir.mkdir(File.dirname(RAKELOG)) unless File.directory?(File.dirname(RAKELOG))
puts "[INFO] Building #{version}..."
sh "'#{BUILDER}' 'distribute' #{IPHONE_SDK_VERSION} '#{PROJDIR}' '#{devAppId}' '#{devAppName}' #{ADHOC_PROVISIONING_UUID} '#{ADHOC_SIGN}' '#{PROJDIR}build/adhoc' #{DEV_APP_DEVICE} > #{RAKELOG}"
puts "[INFO] App package: build/iphone/build/Release-iphoneos/#{devAppName}.app"
end
desc "Build distribution ipa file for device and dSYM zip file (adhoc)"
task :adhoc => [:distribute] do
puts "[INFO] Archiving #{version}..."
FileUtils.mkdir_p "build/adhoc/#{version}"
File.open("build/adhoc/#{version}/version.txt",'w') do |f|
f.puts(version)
end
sh "/usr/bin/xcrun -sdk iphoneos PackageApplication -v build/iphone/build/Release-iphoneos/#{devAppName}.app -o '#{PROJDIR}build/adhoc/#{version}/#{version}.ipa' >> #{RAKELOG}"
FileUtils.cp File.expand_path("~/Library/MobileDevice/Provisioning Profiles/#{ADHOC_PROVISIONING_UUID}.mobileprovision"), "build/adhoc/#{version}/#{devAppName}-dev.mobileprovision"
sh "ditto -ck --keepParent --sequesterRsrc build/adhoc/#{version} build/adhoc/#{version}.zip >> #{RAKELOG}"
sh "ditto -ck --keepParent --sequesterRsrc build/iphone/build/Release-iphoneos/#{devAppName}.app.dSYM build/adhoc/#{version}-dSYM.zip >> #{RAKELOG}"
puts "[INFO] Zipped AdHoc IPA package: build/adhoc/#{version}.zip"
puts "[INFO] Zipped dSYM: build/adhoc/#{version}-dSYM.zip"
end
namespace :log do
desc "View the rake log"
task :log do
sh "cat #{RAKELOG}"
end
desc "View the build log"
task :buildlog do
sh "cat build/iphone/build/build.log"
end
end
desc "Same as log:log"
task :log => ["log:log"]
desc "Clean the build"
task :clean do
FileUtils.rm_rf "build/iphone"
FileUtils.mkdir_p "build/iphone"
puts "[INFO] Cleaned build/iphone"
end
namespace :testflight do
desc "Build and submit a distribution archive and debug symbols to TestFlight"
task :submit => [:adhoc] do
submittf version
puts "[INFO] Submission to TestFlight complete [#{version}]"
end
desc "Submit the previously built adhoc archive and debug symbols to TestFlight"
task :submitlast do
latest = getLatest
submittf latest[latest.length-1]
puts "[INFO] Submission to TestFlight complete [#{version}]"
end
# Deploy a specific build version to TestFlight (ipa and dSYM); upon success, open the edit page for the TestFlight build in a web browser
def submittf(version)
responsefile = "build/adhoc/#{version}/testflight.json"
releasenotes = File.read("RELEASE_NOTES.txt")
sh 'curl', '-o', "#{responsefile}", 'http://testflightapp.com/api/builds.json', '-F', "file=@build/adhoc/#{version}/#{version}.ipa", '-F', "api_token=#{TF_API_TOKEN}", '-F', "team_token=#{TF_TEAM_TOKEN}", '-F', "notes=#{releasenotes}", '-F', 'notify=False', '-F', "distribution_lists=#{TF_DIST_LISTS}" do |ok, status|
# '-F', "dsym=@build/adhoc/#{version}-dSYM.zip",
ok or fail "Testflight deployment failed"
end
response = nil
begin
json = File.read(responsefile)
response = JSON.parse(json)
rescue
end
if !response.nil? && !response['config_url'].nil?
puts json
response['config_url']['/complete/'] = '/edit/'
sh 'open', response['config_url']
else
sh 'open', 'https://testflightapp.com/dashboard/builds/'
end
end
end
desc "Same as testflight:submit"
task :testflight => ["testflight:submit"]
namespace :pieceable do
desc "Build and submit a distribution archive to Pieceable Software"
task :submit => [:buildfull] do
submitpc devAppName, version
puts "[INFO] Submission to Pieceable Software complete [#{version}]"
end
def submitpc(devAppName, version)
responsefile = "build/#{version}/pieceable.txt"
Dir.mkdir(File.dirname(responsefile)) unless File.directory?(File.dirname(responsefile))
sh "ditto -cz build/iphone/build/Debug-iphonesimulator/#{devAppName}.app - | curl -o #{responsefile} http://www.pieceable.com/view/publish -F 'email=#{PIECEABLE_EMAIL}' -F 'file=@-'"
text = File.read(responsefile)
puts text
urls = URI.extract(text)
if urls.length > 0
sh 'open', urls[urls.length-1]
end
end
end
desc "Same as pieceable:submit"
task :pieceable => ["pieceable:submit"]
def getLatest
(Dir.glob("build/adhoc/*/").max_by {|f| File.mtime(f)}).split(File::SEPARATOR)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment