Class: Pod::Command::Submit
- Inherits:
-
Pod::Command
- Object
- Pod::Command
- Pod::Command::Submit
- Defined in:
- lib/pod/command/submit.rb
Instance Method Summary collapse
- #create_package(target, apple_id) ⇒ Object
- #credentials(bundle_identifier) ⇒ Object
- #execute(command) ⇒ Object
- #find_best_configuration(target) ⇒ Object
-
#initialize(argv) ⇒ Submit
constructor
A new instance of Submit.
- #login(bundle_identifier) ⇒ Object
- #metadata(apple_id, checksum, size) ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(argv) ⇒ Submit
Returns a new instance of Submit.
20 21 22 23 |
# File 'lib/pod/command/submit.rb', line 20 def initialize(argv) @target_name = argv.shift_argument unless argv.arguments.empty? super end |
Instance Method Details
#create_package(target, apple_id) ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/pod/command/submit.rb', line 60 def create_package(target, apple_id) ipa = "#{target}.ipa" size = File.size(ipa) checksum = Digest::MD5.file(ipa) FileUtils.mkdir_p("Package.itmsp") FileUtils.copy_entry(ipa, "Package.itmsp/#{ipa}") File.write("Package.itmsp/metadata.xml", (apple_id, checksum, size)) end |
#credentials(bundle_identifier) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/pod/command/submit.rb', line 47 def credentials(bundle_identifier) username = `security find-generic-password -wl #{bundle_identifier}.cocoapods-submit.username`.chomp return login(bundle_identifier) if $?.to_i > 0 password = `security find-generic-password -wl #{bundle_identifier}.cocoapods-submit.password`.chomp return login(bundle_identifier) if $?.to_i > 0 apple_id = `security find-generic-password -wl #{bundle_identifier}.cocoapods-submit.apple-id`.chomp return login(bundle_identifier) if $?.to_i > 0 return [username, password, apple_id] end |
#execute(command) ⇒ Object
11 12 13 14 |
# File 'lib/pod/command/submit.rb', line 11 def execute(command) puts "#{"==>".magenta} #{command}" abort unless system(command) end |
#find_best_configuration(target) ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/pod/command/submit.rb', line 71 def find_best_configuration(target) identifiers = target.build_configurations.map { |c| c.build_settings["PROVISIONING_PROFILE"] } profiles = identifiers.map { |uuid| CocoapodsSubmit::ProvisioningProfile.from_uuid uuid } ranks = profiles.map &:rank return target.build_configurations[ranks.each_with_index.max[1]] end |
#login(bundle_identifier) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/pod/command/submit.rb', line 25 def login(bundle_identifier) puts "You will now have to login to iTunes Connect. Don't worry. Your credentials will be securly stored in your keychain." print "Username: " username = $stdin.gets.chomp abort "Username is required" if username.empty? print "Password for #{username}: " password = STDIN.noecho(&:gets).chomp abort "Password is required" if password.empty? puts "" print "Apple-ID for #{bundle_identifier} (you can find it in iTunes Connect): " apple_id = $stdin.gets.chomp abort "Apple-ID is required" if apple_id.empty? `security add-generic-password -a #{bundle_identifier}.cocoapods-submit.username -s #{bundle_identifier}.cocoapods-submit.username -w #{username}` `security add-generic-password -a #{bundle_identifier}.cocoapods-submit.password -s #{bundle_identifier}.cocoapods-submit.password -w #{password}` `security add-generic-password -a #{bundle_identifier}.cocoapods-submit.apple-id -s #{bundle_identifier}.cocoapods-submit.apple-id -w #{apple_id}` return [username, password, apple_id] end |
#metadata(apple_id, checksum, size) ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/pod/command/submit.rb', line 136 def (apple_id, checksum, size) %Q(<?xml version="1.0" encoding="UTF-8"?> <package version="software4.7" xmlns="http://apple.com/itunes/importer"> <software_assets apple_id="#{apple_id}"> <asset type="bundle"> <data_file> <file_name>#{@target_name}.ipa</file_name> <checksum type="md5">#{checksum}</checksum> <size>#{size}</size> </data_file> </asset> </software_assets> </package>) end |
#run ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/pod/command/submit.rb', line 79 def run workspaces = Dir.entries(".").select { |s| s.end_with? ".xcworkspace" } abort "pod submit only supports one .xcworkspace in the current directory" unless workspaces.count == 1 workspace = Xcodeproj::Workspace.new_from_xcworkspace(workspaces[0]) project = Xcodeproj::Project.open workspace.file_references.first.path schemes = Xcodeproj::Project.schemes project.path targets = project.targets.select { |t| t.product_type == "com.apple.product-type.application" } if @target_name targets = targets.select { |t| t.name == @target_name } abort "Target #{@target_name} not found" if targets.count == 0 end if targets.count > 1 puts "Could not auto determine the target to submit. Please specify your target like:" puts "" for target in targets puts " * pod submit #{target.name}" end puts "" abort end @target = targets.first @target_name = @target.name configuration = find_best_configuration @target abort "No build configuration found for target #{@target}." unless configuration # grap info.plist and extract bundle identifier relative_info_path = @target.build_configuration_list["Release"].build_settings["INFOPLIST_FILE"] info_path = File.join File.dirname(project.path), relative_info_path info_plist = Plist::parse_xml(info_path) identifier = info_plist["CFBundleIdentifier"] info_plist["CFBundleVersion"] = (info_plist["CFBundleVersion"].to_i + 1).to_s File.write info_path, info_plist.to_plist username, password, apple_id = credentials(identifier) execute "ipa build --verbose --scheme #{@target_name} --configuration #{configuration.name} | xcpretty -c && exit ${PIPESTATUS[0]}" execute "ipa info #{@target_name}.ipa" transporter = File.join `xcode-select --print-path`.chomp, "/../Applications/Application\\ Loader.app/Contents/MacOS/itms/bin/iTMSTransporter" create_package(@target_name, apple_id) execute "#{transporter} -m verify -f Package.itmsp -u #{username} -p #{password}" execute "#{transporter} -m upload -f Package.itmsp -u #{username} -p #{password}" `rm -rf Package.itmsp #{@target_name}.ipa #{@target_name}.app.dSYM.zip` time = Time.now.strftime "%Y%m%d%H%m%S" execute "git add ." execute "git commit -am 'Submitted to iTunes Connect submit-#{time}-#{@target.name}-#{info_plist["CFBundleShortVersionString"]}-#{info_plist["CFBundleVersion"]}'" execute "git tag submit-#{time}-#{@target.name}-#{info_plist["CFBundleShortVersionString"]}-#{info_plist["CFBundleVersion"]}" execute "git push && git push --tags" end |