Skip to content

Commit

Permalink
fix to generate p8 file for every calling altool
Browse files Browse the repository at this point in the history
  • Loading branch information
freddi-kit committed Sep 10, 2022
1 parent 711eb3c commit 747178f
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions fastlane_core/lib/fastlane_core/itunes_transporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def execute(command, hide_output)
def build_upload_command(username, password, source = "/tmp", provider_short_name = "", jwt = nil, platform = nil, api_key = nil)
use_api_key = !api_key.nil?
[
("API_PRIVATE_KEYS_DIR=#{api_key[:key_filepath]}" if use_api_key),
("API_PRIVATE_KEYS_DIR=#{Dir.tmpdir}" if use_api_key),
"xcrun altool",
"--upload-app",
("-u #{username.shellescape}" unless use_api_key),
Expand Down Expand Up @@ -691,8 +691,19 @@ def upload(app_id = nil, dir = nil, package_path: nil, asset_path: nil, platform

password_placeholder = @jwt.nil? ? 'YourPassword' : nil
jwt_placeholder = @jwt.nil? ? nil : 'YourJWT'
api_key_placeholder = nil unless !@api_key.nil?
api_key_placeholder = { key_id: "YourKeyID", issuer_id: "YourIssuerID", key_filepath: "YourKeyFilepath" } if !@api_key.nil?

# Handle AppStore Connect API
use_api_key = !@api_key.nil?
api_key_placeholder = nil unless use_api_key
api_key_placeholder = { key_id: "YourKeyID", issuer_id: "YourIssuerID" } if use_api_key

if use_api_key
# Specified p8 needs to be generated to call altool
tmp_p8_file_path = File.join(Dir.tmpdir, "AuthKey_#{@api_key[:key_id]}.p8")
p8 = File.open(tmp_p8_file_path, "w")
p8.write(@api_key[:key])
p8.close
end

command = @transporter_executor.build_upload_command(@user, @password, actual_dir, @provider_short_name, @jwt, platform, @api_key)
UI.verbose(@transporter_executor.build_upload_command(@user, password_placeholder, actual_dir, @provider_short_name, jwt_placeholder, platform, api_key_placeholder))
Expand All @@ -702,6 +713,11 @@ def upload(app_id = nil, dir = nil, package_path: nil, asset_path: nil, platform
rescue TransporterRequiresApplicationSpecificPasswordError => ex
handle_two_step_failure(ex)
return upload(app_id, dir, package_path: package_path, asset_path: asset_path)
ensure
if use_api_key
tmp_p8_file_path = File.join(Dir.tmpdir, "AuthKey_#{@api_key[:key_id]}.p8")
FileUtils.rm_f(tmp_p8_file_path)
end
end

if result
Expand Down

0 comments on commit 747178f

Please sign in to comment.