Class: FastlaneCore::ItunesTransporter

Inherits:
Object
  • Object
show all
Defined in:
fastlane_core/lib/fastlane_core/itunes_transporter.rb

Constant Summary collapse

PROVIDER_REGEX =

Matches a line in the provider table: “12 Initech Systems Inc LG89CQY559”

/^\d+\s{2,}.+\s{2,}[^\s]+$/
TWO_STEP_HOST_PREFIX =
"deliver.appspecific"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user = nil, password = nil, use_shell_script = false, provider_short_name = nil, jwt = nil) ⇒ ItunesTransporter

Returns a new instance of the iTunesTransporter. If no username or password given, it will be taken from the #CredentialsManager::AccountManager

Parameters:

  • use_shell_script (defaults to: false)

    if true, forces use of the iTMSTransporter shell script. if false, allows a direct call to the iTMSTransporter Java app (preferred). see: github.com/fastlane/fastlane/pull/4003

  • provider_short_name (defaults to: nil)

    The provider short name to be given to the iTMSTransporter to identify the correct team for this work. The provider short name is usually your Developer Portal team ID, but in certain cases it is different! see: github.com/fastlane/fastlane/issues/1524#issuecomment-196370628 for more information about how to use the iTMSTransporter to list your provider short names



416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
# File 'fastlane_core/lib/fastlane_core/itunes_transporter.rb', line 416

def initialize(user = nil, password = nil, use_shell_script = false, provider_short_name = nil, jwt = nil)
  # Xcode 6.x doesn't have the same iTMSTransporter Java setup as later Xcode versions, so
  # we can't default to using the newer direct Java invocation strategy for those versions.
  use_shell_script ||= Helper.is_mac? && Helper.xcode_version.start_with?('6.')
  use_shell_script ||= Helper.windows?
  use_shell_script ||= Feature.enabled?('FASTLANE_ITUNES_TRANSPORTER_USE_SHELL_SCRIPT')

  if jwt.to_s.empty?
    @user = user
    @password = password || load_password_for_transporter
  end

  @jwt = jwt

  @transporter_executor = use_shell_script ? ShellScriptTransporterExecutor.new : JavaTransporterExecutor.new
  @provider_short_name = provider_short_name
end

Class Method Details

.hide_transporter_outputObject

This will be called from the Deliverfile, and disables the logging of the transporter output



396
397
398
# File 'fastlane_core/lib/fastlane_core/itunes_transporter.rb', line 396

def self.hide_transporter_output
  @hide_transporter_output = !FastlaneCore::Globals.verbose?
end

.hide_transporter_output?Boolean

Returns:



400
401
402
# File 'fastlane_core/lib/fastlane_core/itunes_transporter.rb', line 400

def self.hide_transporter_output?
  @hide_transporter_output
end

Instance Method Details

#download(app_id, dir = nil) ⇒ Bool

Downloads the latest version of the app metadata package from iTC.

Parameters:

  • app_id (Integer)

    The unique App ID

  • dir (String) (defaults to: nil)

    the path in which the package file should be stored

Returns:

  • (Bool)

    True if everything worked fine

Raises:

  • (Deliver::TransporterTransferError)

    when something went wrong when transferring



440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
# File 'fastlane_core/lib/fastlane_core/itunes_transporter.rb', line 440

def download(app_id, dir = nil)
  dir ||= "/tmp"

  password_placeholder = @jwt.nil? ? 'YourPassword' : nil
  jwt_placeholder = @jwt.nil? ? nil : 'YourJWT'

  UI.message("Going to download app metadata from App Store Connect")
  command = @transporter_executor.build_download_command(@user, @password, app_id, dir, @provider_short_name, @jwt)
  UI.verbose(@transporter_executor.build_download_command(@user, password_placeholder, app_id, dir, @provider_short_name, jwt_placeholder))

  begin
    result = @transporter_executor.execute(command, ItunesTransporter.hide_transporter_output?)
  rescue TransporterRequiresApplicationSpecificPasswordError => ex
    handle_two_step_failure(ex)
    return download(app_id, dir)
  end

  return result if Helper.test?

  itmsp_path = File.join(dir, "#{app_id}.itmsp")
  successful = result && File.directory?(itmsp_path)

  if successful
    UI.success("✅ Successfully downloaded the latest package from App Store Connect to #{itmsp_path}")
  else
    handle_error(@password)
  end

  successful
end

#provider_idsObject



507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
# File 'fastlane_core/lib/fastlane_core/itunes_transporter.rb', line 507

def provider_ids
  password_placeholder = @jwt.nil? ? 'YourPassword' : nil
  jwt_placeholder = @jwt.nil? ? nil : 'YourJWT'

  command = @transporter_executor.build_provider_ids_command(@user, @password, @jwt)
  UI.verbose(@transporter_executor.build_provider_ids_command(@user, password_placeholder, jwt_placeholder))

  lines = []
  begin
    result = @transporter_executor.execute(command, ItunesTransporter.hide_transporter_output?) { |xs| lines = xs }
    return result if Helper.test?
  rescue TransporterRequiresApplicationSpecificPasswordError => ex
    handle_two_step_failure(ex)
    return provider_ids
  end

  lines.map { |line| provider_pair(line) }.compact.to_h
end

#upload(app_id, dir) ⇒ Bool

Uploads the modified package back to App Store Connect

Parameters:

  • app_id (Integer)

    The unique App ID

  • dir (String)

    the path in which the package file is located

Returns:

  • (Bool)

    True if everything worked fine

Raises:

  • (Deliver::TransporterTransferError)

    when something went wrong when transferring



477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
# File 'fastlane_core/lib/fastlane_core/itunes_transporter.rb', line 477

def upload(app_id, dir)
  actual_dir = File.join(dir, "#{app_id}.itmsp")

  UI.message("Going to upload updated app to App Store Connect")
  UI.success("This might take a few minutes. Please don't interrupt the script.")

  password_placeholder = @jwt.nil? ? 'YourPassword' : nil
  jwt_placeholder = @jwt.nil? ? nil : 'YourJWT'

  command = @transporter_executor.build_upload_command(@user, @password, actual_dir, @provider_short_name, @jwt)
  UI.verbose(@transporter_executor.build_upload_command(@user, password_placeholder, actual_dir, @provider_short_name, jwt_placeholder))

  begin
    result = @transporter_executor.execute(command, ItunesTransporter.hide_transporter_output?)
  rescue TransporterRequiresApplicationSpecificPasswordError => ex
    handle_two_step_failure(ex)
    return upload(app_id, dir)
  end

  if result
    UI.header("Successfully uploaded package to App Store Connect. It might take a few minutes until it's visible online.")

    FileUtils.rm_rf(actual_dir) unless Helper.test? # we don't need the package any more, since the upload was successful
  else
    handle_error(@password)
  end

  result
end