Skip to content

Commit

Permalink
added testflight_mode and testflight block defintions (like app.devel…
Browse files Browse the repository at this point in the history
…opment, app.release).

added notify option, defaults to false.
record testflight_mode between builds to ensure configurations are re-written when necessary.
  • Loading branch information
joenoon committed Sep 24, 2012
1 parent 71e198f commit da9ef76
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 6 deletions.
12 changes: 9 additions & 3 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,15 @@ SDK and be submitted to the TestFlight platform.

Motion::Project::App.setup do |app|
# ...
app.testflight.sdk = 'vendor/TestFlight'
app.testflight.api_token = '<insert your API token here>'
app.testflight.team_token = '<insert your team token here>'
app.development do
# ...
app.testflight do
app.testflight.sdk = 'vendor/TestFlight'
app.testflight.api_token = '<insert your API token here>'
app.testflight.team_token = '<insert your team token here>'
app.testflight.notify = true # default is false
end
end
end

You can retrieve the values for +api_token+ and +team_token+ in your TestFlight account page.
Expand Down
53 changes: 50 additions & 3 deletions lib/motion/project/testflight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
end

class TestFlightConfig
attr_accessor :sdk, :api_token, :team_token, :distribution_lists
attr_accessor :sdk, :api_token, :team_token, :distribution_lists, :notify

def initialize(config)
@config = config
Expand Down Expand Up @@ -75,23 +75,38 @@ def create_launcher
end

module Motion; module Project; class Config

attr_accessor :testflight_mode

variable :testflight

def testflight
@testflight ||= TestFlightConfig.new(self)
yield if block_given? && testflight?
@testflight
end

def testflight?
@testflight_mode == true
end

end; end; end

namespace 'testflight' do
desc "Submit an archive to TestFlight"
task :submit => 'archive' do
task :submit do

App.config_without_setup.testflight_mode = true

# Retrieve configuration settings.
prefs = App.config.testflight
App.fail "A value for app.testflight.api_token is mandatory" unless prefs.api_token
App.fail "A value for app.testflight.team_token is mandatory" unless prefs.team_token
distribution_lists = (prefs.distribution_lists ? prefs.distribution_lists.join(',') : nil)
notes = ENV['notes']
App.fail "Submission notes must be provided via the `notes' environment variable. Example: rake testflight notes='w00t'" unless notes

Rake::Task["archive"].invoke

# An archived version of the .dSYM bundle is needed.
app_dsym = App.config.app_bundle('iPhoneOS').sub(/\.app$/, '.dSYM')
Expand All @@ -102,12 +117,44 @@ def testflight
end
end

curl = "/usr/bin/curl http://testflightapp.com/api/builds.json -F file=@\"#{App.config.archive}\" -F dsym=@\"#{app_dsym_zip}\" -F api_token='#{prefs.api_token}' -F team_token='#{prefs.team_token}' -F notes=\"#{notes}\" -F notify=True"
curl = "/usr/bin/curl http://testflightapp.com/api/builds.json -F file=@\"#{App.config.archive}\" -F dsym=@\"#{app_dsym_zip}\" -F api_token='#{prefs.api_token}' -F team_token='#{prefs.team_token}' -F notes=\"#{notes}\" -F notify=#{prefs.notify ? "True" : "False"}"
curl << " -F distribution_lists='#{distribution_lists}'" if distribution_lists
App.info 'Run', curl
sh curl
end

desc "Records if the device build is created in testflight mode, so some things can be cleaned up between mode switches"
task :record_mode do
testflight_mode = App.config_without_setup.testflight_mode ? "True" : "False"

platform = 'iPhoneOS'
bundle_path = App.config.app_bundle(platform)
build_dir = File.join(App.config.versionized_build_dir(platform))
FileUtils.mkdir_p(build_dir)
previous_testflight_mode_file = File.join(build_dir, '.testflight_mode')

previous_testflight_mode = "False"
if File.exist?(previous_testflight_mode_file)
previous_testflight_mode = File.read(previous_testflight_mode_file).strip
end
if previous_testflight_mode != testflight_mode
App.info "Testflight", "Cleaning executable, Info.plist, and PkgInfo for mode change (was: #{previous_testflight_mode}, now: #{testflight_mode})"
[
App.config.app_bundle_executable(platform), # main_exec
File.join(bundle_path, 'Info.plist'), # bundle_info_plist
File.join(bundle_path, 'PkgInfo') # bundle_pkginfo
].each do |path|
rm_rf(path) if File.exist?(path)
end
end
File.open(previous_testflight_mode_file, 'w') do |f|
f.write testflight_mode
end
end
end

desc 'Same as testflight:submit'
task 'testflight' => 'testflight:submit'

# record testflight mode before every device build
task 'build:device' => 'testflight:record_mode'

0 comments on commit da9ef76

Please sign in to comment.