Permalink
Browse files

Merge pull request #5 from qnyp/feature/testflight

add testflight task
  • Loading branch information...
2 parents 0cdbec0 + 891c89c commit 5718bd76af3a099137ded0eca3892afe93f771f6 @juno juno committed Jun 8, 2012
Showing with 128 additions and 0 deletions.
  1. +1 −0 lib/alloy.rb
  2. +41 −0 lib/alloy/chore/testflight.rb
  3. +5 −0 lib/alloy/cli.rb
  4. +71 −0 lib/alloy/config.rb
  5. +10 −0 lib/templates/alloy.json.erb
View
@@ -5,6 +5,7 @@ module Alloy
module Chore
autoload :CoffeeScript, 'alloy/chore/coffee_script'
+ autoload :TestFlight, 'alloy/chore/testflight'
end
module Task
@@ -0,0 +1,41 @@
+require 'alloy'
+require 'colored'
+
+module Alloy::Chore
+ class TestFlight
+ PERL_COLOR_FILTER = %Q{| perl -pe 's/^\\[DEBUG\\].*$/\\e[35m$&\\e[0m/g;s/^\\[INFO\\].*$/\\e[36m$&\\e[0m/g;s/^\\[WARN\\].*$/\\e[33m$&\\e[0m/g;s/^\\[ERROR\\].*$/\\e[31m$&\\e[0m/g;'}
+
+ def self.run
+ config = Alloy::Config.new('./alloy.json')
+ puts "Takeoff to TestFlight... ".blue
+ begin
+ Dir.chdir('build/iphone')
+ system %Q{bash -c "rm -rf #{Dir::getwd}/#{config.xcode_build_dstroot}" #{PERL_COLOR_FILTER}}
+ system %Q{bash -c "mkdir #{config.xcode_build_dstroot}" #{PERL_COLOR_FILTER}}
+ system %Q{bash -c "#{build_arg(config)}" #{PERL_COLOR_FILTER}}
+ system %Q{bash -c "#{package_arg(config)}" #{PERL_COLOR_FILTER}}
+ system %Q{bash -c "#{flight_arg(config)}" #{PERL_COLOR_FILTER}}
+ system %Q{bash -c "rm -rf #{Dir::getwd}/#{config.xcode_build_dstroot}" #{PERL_COLOR_FILTER}}
+ rescue => e
+ puts e.backtrace.join("\n")
+ puts e.message.red
+ system %Q{bash -c "rm -rf ./#{config.xcode_build_dstroot}" #{PERL_COLOR_FILTER}}
+ system %Q{killall "TestFlight Faild"}
+ end
+
+ end
+
+ def self.build_arg(config)
+ "xcodebuild -target '#{config.app_name}' -sdk iphoneos -configuration '#{config.xcode_build_configuration}' install DSTROOT=#{config.xcode_build_dstroot}"
+ end
+
+ def self.package_arg(config)
+ "xcrun -sdk iphoneos PackageApplication '#{config.xcode_build_dstroot}/Applications/#{config.app_name}.app' -o '#{Dir::getwd}/#{config.xcode_build_dstroot}/#{config.app_name}.ipa' --sign '#{config.xcode_build_signing_identity}' --embed '#{config.xcode_build_mobileprovision_path}'"
+ end
+
+ def self.flight_arg(config)
+ "curl 'http://testflightapp.com/api/builds.json' -F 'file=@#{Dir::getwd}/#{config.xcode_build_dstroot}/#{config.app_name}.ipa' -F 'api_token=#{config.testflight_api_token}' -F 'team_token=#{config.testflight_team_token}' -F 'notes=`git log -5`' -F 'notify=True'"
+ end
+
+ end
+end
View
@@ -21,6 +21,11 @@ def coffee
Chore::CoffeeScript.run
end
+ desc 'testflight', 'Upload to TestFlight'
+ def testflight
+ Chore::TestFlight.run
+ end
+
desc 'init', 'Generate alloy.json'
def init
template('alloy.json.erb', 'alloy.json')
View
@@ -196,6 +196,77 @@ def project_root
@json['project_root']
end
+ # Public: Returns Xcode Build Signing Identity string.
+ #
+ # Examples
+ #
+ # xcode_build_signing_identity
+ # # => "iPhone Distribution: [Author]"
+ #
+ # Returns build_signing_identity String.
+ def xcode_build_signing_identity
+ @json['xcode']['build_signing_identity']
+ end
+
+ # Public: Returns Xcode Build Mobileprovision Path string.
+ #
+ # Examples
+ #
+ # xcode_build_mobileprovision_path
+ # # => "/Library/MobileDevice/Provisioning Profiles/[AppName].mobileprovision"
+ #
+ # Returns build_mobileprovision_path String.
+ def xcode_build_mobileprovision_path
+ @json['xcode']['build_mobileprovision_path']
+ end
+
+ # Public: Returns Xcode Build Configuration string.
+ #
+ # Examples
+ #
+ # xcode_build_configuration
+ # # => "Release"
+ #
+ # Returns build_configuration String.
+ def xcode_build_configuration
+ @json['xcode']['build_configuration']
+ end
+
+ # Public: Returns Xcode Build Dstroot string.
+ #
+ # Examples
+ #
+ # xcode_build_dstroot
+ # # => "dstroot"
+ #
+ # Returns build_dstroot String.
+ def xcode_build_dstroot
+ @json['xcode']['build_dstroot']
+ end
+
+ # Public: Returns TestFlight Api Token string.
+ #
+ # Examples
+ #
+ # testflight_api_token
+ # # => "********************************_*******"
+ #
+ # Returns api_token String.
+ def testflight_api_token
+ @json['testflight']['api_token']
+ end
+
+ # Public: Returns TestFlight Team Token string.
+ #
+ # Examples
+ #
+ # testflight_team_token
+ # # => "********************************_******************************************"
+ #
+ # Returns team_token String.
+ def testflight_team_token
+ @json['testflight']['team_token']
+ end
private
@@ -22,5 +22,15 @@ android_sdk_path = candidates.find { |i| i != nil }
"android": {
"sdk_path": "<%= android_sdk_path %>",
"avd_id": "1"
+ },
+ "xcode": {
+ "build_sign": "iPhone Distribution: [Author]",
+ "build_mobileprovision": "/Library/MobileDevice/Provisioning Profiles/[AppName].mobileprovision",
+ "build_configuration": "Release",
+ "build_dstroot": "dstroot"
+ },
+ "testflight": {
+ "api_token": "********************************_*******",
+ "team_token": "********************************_******************************************"
}
}

0 comments on commit 5718bd7

Please sign in to comment.