fastlane 2.159.0 → 2.164.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +74 -74
  3. data/cert/lib/cert/options.rb +28 -1
  4. data/cert/lib/cert/runner.rb +50 -33
  5. data/deliver/lib/deliver/app_screenshot_iterator.rb +4 -4
  6. data/deliver/lib/deliver/module.rb +2 -0
  7. data/deliver/lib/deliver/options.rb +20 -4
  8. data/deliver/lib/deliver/queue_worker.rb +14 -29
  9. data/deliver/lib/deliver/runner.rb +36 -8
  10. data/deliver/lib/deliver/upload_metadata.rb +51 -10
  11. data/deliver/lib/deliver/upload_price_tier.rb +7 -2
  12. data/deliver/lib/deliver/upload_screenshots.rb +28 -13
  13. data/fastlane/lib/fastlane/actions/actions_helper.rb +20 -1
  14. data/fastlane/lib/fastlane/actions/app_store_build_number.rb +39 -3
  15. data/fastlane/lib/fastlane/actions/app_store_connect_api_key.rb +15 -1
  16. data/fastlane/lib/fastlane/actions/check_app_store_metadata.rb +1 -0
  17. data/fastlane/lib/fastlane/actions/clean_build_artifacts.rb +1 -0
  18. data/fastlane/lib/fastlane/actions/docs/capture_android_screenshots.md +2 -2
  19. data/fastlane/lib/fastlane/actions/docs/capture_ios_screenshots.md +2 -2
  20. data/fastlane/lib/fastlane/actions/docs/create_app_online.md +1 -1
  21. data/fastlane/lib/fastlane/actions/docs/frame_screenshots.md +3 -2
  22. data/fastlane/lib/fastlane/actions/docs/run_tests.md +2 -2
  23. data/fastlane/lib/fastlane/actions/docs/sync_code_signing.md +12 -3
  24. data/fastlane/lib/fastlane/actions/docs/upload_to_play_store.md +2 -2
  25. data/fastlane/lib/fastlane/actions/docs/upload_to_testflight.md +1 -1
  26. data/fastlane/lib/fastlane/actions/download_dsyms.rb +31 -6
  27. data/fastlane/lib/fastlane/actions/ensure_git_status_clean.rb +13 -2
  28. data/fastlane/lib/fastlane/actions/get_certificates.rb +1 -0
  29. data/fastlane/lib/fastlane/actions/get_provisioning_profile.rb +1 -0
  30. data/fastlane/lib/fastlane/actions/import_from_git.rb +9 -1
  31. data/fastlane/lib/fastlane/actions/is_ci.rb +1 -1
  32. data/fastlane/lib/fastlane/actions/latest_testflight_build_number.rb +15 -0
  33. data/fastlane/lib/fastlane/actions/register_device.rb +46 -5
  34. data/fastlane/lib/fastlane/actions/register_devices.rb +50 -16
  35. data/fastlane/lib/fastlane/actions/set_changelog.rb +31 -3
  36. data/fastlane/lib/fastlane/actions/sync_code_signing.rb +1 -0
  37. data/fastlane/lib/fastlane/actions/upload_to_app_store.rb +3 -2
  38. data/fastlane/lib/fastlane/fast_file.rb +74 -23
  39. data/fastlane/lib/fastlane/plugins/template/.rubocop.yml +1 -0
  40. data/fastlane/lib/fastlane/version.rb +1 -1
  41. data/fastlane/swift/Deliverfile.swift +1 -1
  42. data/fastlane/swift/DeliverfileProtocol.swift +13 -5
  43. data/fastlane/swift/Fastlane.swift +170 -44
  44. data/fastlane/swift/Gymfile.swift +1 -1
  45. data/fastlane/swift/GymfileProtocol.swift +1 -1
  46. data/fastlane/swift/LaneFileProtocol.swift +28 -36
  47. data/fastlane/swift/MainProcess.swift +1 -1
  48. data/fastlane/swift/Matchfile.swift +1 -1
  49. data/fastlane/swift/MatchfileProtocol.swift +20 -4
  50. data/fastlane/swift/Precheckfile.swift +1 -1
  51. data/fastlane/swift/PrecheckfileProtocol.swift +9 -1
  52. data/fastlane/swift/Scanfile.swift +1 -1
  53. data/fastlane/swift/ScanfileProtocol.swift +1 -1
  54. data/fastlane/swift/Screengrabfile.swift +1 -1
  55. data/fastlane/swift/ScreengrabfileProtocol.swift +1 -1
  56. data/fastlane/swift/Snapshotfile.swift +1 -1
  57. data/fastlane/swift/SnapshotfileProtocol.swift +1 -1
  58. data/fastlane/swift/main.swift +1 -1
  59. data/fastlane_core/lib/fastlane_core/analytics/analytics_session.rb +6 -7
  60. data/fastlane_core/lib/fastlane_core/device_manager.rb +8 -4
  61. data/fastlane_core/lib/fastlane_core/helper.rb +1 -1
  62. data/fastlane_core/lib/fastlane_core/keychain_importer.rb +3 -3
  63. data/frameit/lib/frameit/editor.rb +1 -0
  64. data/gym/lib/gym/generators/package_command_generator_xcode7.rb +2 -2
  65. data/match/lib/match/.commands_generator.rb.swp +0 -0
  66. data/match/lib/match/.importer.rb.swp +0 -0
  67. data/{spaceship/lib/spaceship/connect_api/models/.app.rb.swp → match/lib/match/.options.rb.swp} +0 -0
  68. data/match/lib/match/generator.rb +6 -1
  69. data/match/lib/match/importer.rb +63 -18
  70. data/match/lib/match/migrate.rb +13 -2
  71. data/match/lib/match/nuke.rb +65 -22
  72. data/match/lib/match/options.rb +33 -2
  73. data/match/lib/match/runner.rb +38 -10
  74. data/match/lib/match/spaceship_ensure.rb +27 -21
  75. data/match/lib/match/storage/google_cloud_storage.rb +20 -3
  76. data/match/lib/match/storage/s3_storage.rb +19 -3
  77. data/pilot/lib/pilot/options.rb +2 -2
  78. data/precheck/lib/precheck/options.rb +16 -0
  79. data/precheck/lib/precheck/runner.rb +20 -1
  80. data/scan/lib/scan/detect_values.rb +5 -8
  81. data/scan/lib/scan/runner.rb +2 -1
  82. data/sigh/lib/assets/resign.sh +1 -1
  83. data/sigh/lib/sigh/download_all.rb +16 -4
  84. data/sigh/lib/sigh/options.rb +21 -0
  85. data/sigh/lib/sigh/runner.rb +81 -39
  86. data/snapshot/lib/assets/SnapshotHelper.swift +4 -0
  87. data/snapshot/lib/snapshot/simulator_launchers/simulator_launcher_base.rb +2 -1
  88. data/spaceship/README.md +1 -1
  89. data/spaceship/lib/spaceship/client.rb +9 -4
  90. data/spaceship/lib/spaceship/connect_api.rb +25 -0
  91. data/spaceship/lib/spaceship/connect_api/api_client.rb +12 -3
  92. data/spaceship/lib/spaceship/connect_api/client.rb +13 -3
  93. data/spaceship/lib/spaceship/connect_api/models/app.rb +17 -9
  94. data/spaceship/lib/spaceship/connect_api/models/app_info.rb +1 -0
  95. data/spaceship/lib/spaceship/connect_api/models/app_screenshot.rb +3 -1
  96. data/spaceship/lib/spaceship/connect_api/models/app_screenshot_set.rb +2 -2
  97. data/spaceship/lib/spaceship/connect_api/models/app_store_version.rb +3 -5
  98. data/spaceship/lib/spaceship/connect_api/models/app_store_version_localization.rb +3 -5
  99. data/spaceship/lib/spaceship/connect_api/models/beta_tester.rb +2 -1
  100. data/spaceship/lib/spaceship/connect_api/models/certificate.rb +42 -0
  101. data/spaceship/lib/spaceship/connect_api/models/device.rb +5 -0
  102. data/spaceship/lib/spaceship/connect_api/models/profile.rb +7 -1
  103. data/spaceship/lib/spaceship/connect_api/models/user_invitation.rb +59 -0
  104. data/spaceship/lib/spaceship/connect_api/provisioning/provisioning.rb +45 -2
  105. data/spaceship/lib/spaceship/connect_api/testflight/testflight.rb +13 -0
  106. data/spaceship/lib/spaceship/connect_api/token.rb +6 -1
  107. data/spaceship/lib/spaceship/connect_api/tunes/tunes.rb +15 -7
  108. data/spaceship/lib/spaceship/connect_api/users/users.rb +40 -0
  109. data/spaceship/lib/spaceship/helper/net_http_generic_request.rb +11 -5
  110. data/supply/lib/supply/uploader.rb +1 -1
  111. metadata +21 -19
  112. data/spaceship/lib/spaceship/connect_api/models/.app_store_version.rb.swp +0 -0
@@ -4,28 +4,38 @@ require_relative 'module'
4
4
  module Match
5
5
  # Ensures the certificate and profiles are also available on App Store Connect
6
6
  class SpaceshipEnsure
7
- def initialize(user, team_id, team_name)
8
- # We'll try to manually fetch the password
9
- # to tell the user that a password is optional
10
- require 'credentials_manager/account_manager'
7
+ attr_accessor :team_id
11
8
 
12
- keychain_entry = CredentialsManager::AccountManager.new(user: user)
9
+ def initialize(user, team_id, team_name, api_token)
10
+ UI.message("Verifying that the certificate and profile are still valid on the Dev Portal...")
13
11
 
14
- if keychain_entry.password(ask_if_missing: false).to_s.length == 0
15
- UI.important("You can also run `fastlane match` in readonly mode to not require any access to the")
16
- UI.important("Developer Portal. This way you only share the keys and credentials")
17
- UI.command("fastlane match --readonly")
18
- UI.important("More information https://docs.fastlane.tools/actions/match/#access-control")
19
- end
12
+ if api_token
13
+ UI.message("Creating authorization token for App Store Connect API")
14
+ Spaceship::ConnectAPI.token = api_token
15
+ self.team_id = team_id
16
+ else
17
+ # We'll try to manually fetch the password
18
+ # to tell the user that a password is optional
19
+ require 'credentials_manager/account_manager'
20
20
 
21
- # Prompts select team if multiple teams and none specified
22
- UI.message("Verifying that the certificate and profile are still valid on the Dev Portal...")
23
- Spaceship::ConnectAPI.login(user, use_portal: true, use_tunes: false, portal_team_id: team_id, team_name: team_name)
21
+ keychain_entry = CredentialsManager::AccountManager.new(user: user)
22
+
23
+ if keychain_entry.password(ask_if_missing: false).to_s.length == 0
24
+ UI.important("You can also run `fastlane match` in readonly mode to not require any access to the")
25
+ UI.important("Developer Portal. This way you only share the keys and credentials")
26
+ UI.command("fastlane match --readonly")
27
+ UI.important("More information https://docs.fastlane.tools/actions/match/#access-control")
28
+ end
29
+
30
+ # Prompts select team if multiple teams and none specified
31
+ Spaceship::ConnectAPI.login(user, use_portal: true, use_tunes: false, portal_team_id: team_id, team_name: team_name)
32
+ self.team_id = Spaceship::ConnectAPI.client.portal_team_id
33
+ end
24
34
  end
25
35
 
26
36
  # The team ID of the currently logged in team
27
37
  def team_id
28
- return Spaceship::ConnectAPI.client.portal_team_id
38
+ return @team_id
29
39
  end
30
40
 
31
41
  def bundle_identifier_exists(username: nil, app_identifier: nil, platform: nil)
@@ -45,12 +55,8 @@ module Match
45
55
  UI.user_error!("Couldn't find bundle identifier '#{app_identifier}' for the user '#{username}'")
46
56
  end
47
57
 
48
- def certificates_exists(username: nil, certificate_ids: [], platform: nil)
49
- if platform == :catalyst.to_s
50
- platform = :macos.to_s
51
- end
52
-
53
- Spaceship.certificate.all(mac: platform == "macos").each do |cert|
58
+ def certificates_exists(username: nil, certificate_ids: [])
59
+ Spaceship::ConnectAPI::Certificate.all.each do |cert|
54
60
  certificate_ids.delete(cert.id)
55
61
  end
56
62
  return if certificate_ids.empty?
@@ -23,6 +23,8 @@ module Match
23
23
  attr_reader :username
24
24
  attr_reader :team_id
25
25
  attr_reader :team_name
26
+ attr_reader :api_key_path
27
+ attr_reader :api_key
26
28
 
27
29
  # Managed values
28
30
  attr_accessor :gc_storage
@@ -44,7 +46,9 @@ module Match
44
46
  readonly: params[:readonly],
45
47
  username: params[:username],
46
48
  team_id: params[:team_id],
47
- team_name: params[:team_name]
49
+ team_name: params[:team_name],
50
+ api_key_path: params[:api_key_path],
51
+ api_key: params[:api_key]
48
52
  )
49
53
  end
50
54
 
@@ -56,7 +60,9 @@ module Match
56
60
  readonly: nil,
57
61
  username: nil,
58
62
  team_id: nil,
59
- team_name: nil)
63
+ team_name: nil,
64
+ api_key_path: nil,
65
+ api_key: nil)
60
66
  @type = type if type
61
67
  @platform = platform if platform
62
68
  @google_cloud_project_id = google_cloud_project_id if google_cloud_project_id
@@ -67,6 +73,9 @@ module Match
67
73
  @team_id = team_id
68
74
  @team_name = team_name
69
75
 
76
+ @api_key_path = api_key_path
77
+ @api_key = api_key
78
+
70
79
  @google_cloud_keys_file = ensure_keys_file_exists(google_cloud_keys_file, google_cloud_project_id)
71
80
 
72
81
  if self.google_cloud_keys_file.to_s.length > 0
@@ -106,11 +115,19 @@ module Match
106
115
  # see `prefixed_working_directory` comments for more details
107
116
  return self.team_id
108
117
  else
109
- spaceship = SpaceshipEnsure.new(self.username, self.team_id, self.team_name)
118
+ UI.user_error!("The `team_id` option is required. fastlane cannot automatically determine portal team id via the App Store Connect API (yet)") if self.team_id.to_s.empty?
119
+
120
+ spaceship = SpaceshipEnsure.new(self.username, self.team_id, self.team_name, self.api_token)
110
121
  return spaceship.team_id
111
122
  end
112
123
  end
113
124
 
125
+ def api_token
126
+ api_token ||= Spaceship::ConnectAPI::Token.create(self.api_key) if self.api_key
127
+ api_token ||= Spaceship::ConnectAPI::Token.from_json_file(self.api_key_path) if self.api_key_path
128
+ return api_token
129
+ end
130
+
114
131
  def prefixed_working_directory
115
132
  # We fall back to "*", which means certificates and profiles
116
133
  # from all teams that use this bucket would be installed. This is not ideal, but
@@ -19,6 +19,8 @@ module Match
19
19
  attr_reader :username
20
20
  attr_reader :team_id
21
21
  attr_reader :team_name
22
+ attr_reader :api_key_path
23
+ attr_reader :api_key
22
24
 
23
25
  def self.configure(params)
24
26
  s3_region = params[:s3_region]
@@ -43,7 +45,9 @@ module Match
43
45
  readonly: params[:readonly],
44
46
  username: params[:username],
45
47
  team_id: params[:team_id],
46
- team_name: params[:team_name]
48
+ team_name: params[:team_name],
49
+ api_key_path: params[:api_key_path],
50
+ api_key: params[:api_key]
47
51
  )
48
52
  end
49
53
 
@@ -55,7 +59,9 @@ module Match
55
59
  readonly: nil,
56
60
  username: nil,
57
61
  team_id: nil,
58
- team_name: nil)
62
+ team_name: nil,
63
+ api_key_path: nil,
64
+ api_key: nil)
59
65
  @s3_bucket = s3_bucket
60
66
  @s3_region = s3_region
61
67
  @s3_client = Fastlane::Helper::S3ClientHelper.new(access_key: s3_access_key, secret_access_key: s3_secret_access_key, region: s3_region)
@@ -64,6 +70,8 @@ module Match
64
70
  @username = username
65
71
  @team_id = team_id
66
72
  @team_name = team_name
73
+ @api_key_path = api_key_path
74
+ @api_key = api_key
67
75
  end
68
76
 
69
77
  # To make debugging easier, we have a custom exception here
@@ -180,10 +188,18 @@ module Match
180
188
  # see `prefixed_working_directory` comments for more details
181
189
  return self.team_id
182
190
  else
183
- spaceship = SpaceshipEnsure.new(self.username, self.team_id, self.team_name)
191
+ UI.user_error!("The `team_id` option is required. fastlane cannot automatically determine portal team id via the App Store Connect API (yet)") if self.team_id.to_s.empty?
192
+
193
+ spaceship = SpaceshipEnsure.new(self.username, self.team_id, self.team_name, api_token)
184
194
  return spaceship.team_id
185
195
  end
186
196
  end
197
+
198
+ def api_token
199
+ api_token ||= Spaceship::ConnectAPI::Token.create(self.api_key) if self.api_key
200
+ api_token ||= Spaceship::ConnectAPI::Token.from_json_file(self.api_key_path) if self.api_key_path
201
+ return api_token
202
+ end
187
203
  end
188
204
  end
189
205
  end
@@ -12,7 +12,7 @@ module Pilot
12
12
  [
13
13
  FastlaneCore::ConfigItem.new(key: :api_key_path,
14
14
  env_name: "PILOT_API_KEY_PATH",
15
- description: "Path to your App Store Connect API key JSON file",
15
+ description: "Path to your App Store Connect API Key JSON file (https://docs.fastlane.tools/app-store-connect-api/#using-fastlane-api-key-json-file)",
16
16
  optional: true,
17
17
  conflicting_options: [:username],
18
18
  verify_block: proc do |value|
@@ -20,7 +20,7 @@ module Pilot
20
20
  end),
21
21
  FastlaneCore::ConfigItem.new(key: :api_key,
22
22
  env_name: "PILOT_API_KEY",
23
- description: "Path to your App Store Connect API key JSON file",
23
+ description: "Your App Store Connect API Key information (https://docs.fastlane.tools/app-store-connect-api/#use-return-value-and-pass-in-as-an-option)",
24
24
  type: Hash,
25
25
  optional: true,
26
26
  sensitive: true,
@@ -25,6 +25,22 @@ module Precheck
25
25
  user ||= CredentialsManager::AppfileConfig.try_fetch_value(:apple_id)
26
26
 
27
27
  [
28
+ FastlaneCore::ConfigItem.new(key: :api_key_path,
29
+ env_name: "PRECHECK_API_KEY_PATH",
30
+ description: "Path to your App Store Connect API Key JSON file (https://docs.fastlane.tools/app-store-connect-api/#using-fastlane-api-key-json-file)",
31
+ optional: true,
32
+ conflicting_options: [:username],
33
+ verify_block: proc do |value|
34
+ UI.user_error!("Couldn't find API key JSON file at path '#{value}'") unless File.exist?(value)
35
+ end),
36
+ FastlaneCore::ConfigItem.new(key: :api_key,
37
+ env_name: "PRECHECK_API_KEY",
38
+ description: "Your App Store Connect API Key information (https://docs.fastlane.tools/app-store-connect-api/#use-return-value-and-pass-in-as-an-option)",
39
+ type: Hash,
40
+ optional: true,
41
+ sensitive: true,
42
+ conflicting_options: [:api_key_path, :username]),
43
+
28
44
  FastlaneCore::ConfigItem.new(key: :app_identifier,
29
45
  short_option: "-a",
30
46
  env_name: "PRECHECK_APP_IDENTIFIER",
@@ -18,7 +18,20 @@ module Precheck
18
18
  hide_keys: [:output_path],
19
19
  title: "Summary for precheck #{Fastlane::VERSION}")
20
20
 
21
- unless Spaceship::Tunes.client
21
+ if api_token
22
+
23
+ # As of 2020-09-15, App Store Connect API does not have support for IAPs yet
24
+ # This means that API Key will fail if checking for IAPs.
25
+ #
26
+ # There is also a check in Deliver::Runner for this.
27
+ # Please remove check in Deliver when the API support IAPs.
28
+ if Precheck.config[:include_in_app_purchases]
29
+ UI.user_error!("Precheck cannot check In-app purchases with the App Store Connect API Key (yet). Exclude In-app purchases from precheck or use Apple ID login")
30
+ end
31
+
32
+ UI.message("Creating authorization token for App Store Connect API")
33
+ Spaceship::ConnectAPI.token = api_token
34
+ elsif Spaceship::Tunes.client.nil?
22
35
  # Team selection passed though FASTLANE_ITC_TEAM_ID and FASTLANE_ITC_TEAM_NAME environment variables
23
36
  # Prompts select team if multiple teams and none specified
24
37
  UI.message("Starting login with user '#{Precheck.config[:username]}'")
@@ -58,6 +71,12 @@ module Precheck
58
71
  return true
59
72
  end
60
73
 
74
+ def api_token
75
+ @api_token ||= Spaceship::ConnectAPI::Token.create(Precheck.config[:api_key]) if Precheck.config[:api_key]
76
+ @api_token ||= Spaceship::ConnectAPI::Token.from_json_file(Precheck.config[:api_key_path]) if Precheck.config[:api_key_path]
77
+ return @api_token
78
+ end
79
+
61
80
  def print_items_not_checked(processor_result: nil)
62
81
  names = processor_result.items_not_checked.map(&:friendly_name)
63
82
  UI.message("😶 Metadata fields not checked by any rule: #{names.join(', ')}".yellow) if names.length > 0
@@ -187,15 +187,12 @@ module Scan
187
187
  end
188
188
  end
189
189
 
190
+ # Convert array to lazy enumerable (evaluate map only when needed)
190
191
  # grab the first unempty evaluated array
191
- if default
192
- Scan.devices = [matches, default].lazy.map { |x|
193
- arr = x.call
194
- arr unless arr.empty?
195
- }.reject(&:nil?).first
196
- else
197
- Scan.devices = []
198
- end
192
+ Scan.devices = [matches, default].lazy.reject(&:nil?).map { |x|
193
+ arr = x.call
194
+ arr unless arr.empty?
195
+ }.reject(&:nil?).first
199
196
  end
200
197
 
201
198
  def self.min_xcode8?
@@ -16,6 +16,7 @@ module Scan
16
16
  class Runner
17
17
  def initialize
18
18
  @test_command_generator = TestCommandGenerator.new
19
+ @device_boot_datetime = DateTime.now
19
20
  end
20
21
 
21
22
  def run
@@ -184,7 +185,7 @@ module Scan
184
185
  UI.header("Collecting system logs")
185
186
  Scan.devices.each do |device|
186
187
  log_identity = "#{device.name}_#{device.os_type}_#{device.os_version}"
187
- FastlaneCore::Simulator.copy_logs(device, log_identity, Scan.config[:output_directory])
188
+ FastlaneCore::Simulator.copy_logs(device, log_identity, Scan.config[:output_directory], @device_boot_datetime)
188
189
  end
189
190
  end
190
191
 
@@ -535,7 +535,7 @@ function resign {
535
535
  fi
536
536
 
537
537
  # Check for and resign OnDemandResource folders
538
- ODR_DIR="$(dirname $APP_PATH)/OnDemandResources"
538
+ ODR_DIR="$(dirname "$APP_PATH")/OnDemandResources"
539
539
  if [ -d "$ODR_DIR" ]; then
540
540
  for assetpack in "$ODR_DIR"/*
541
541
  do
@@ -9,10 +9,16 @@ module Sigh
9
9
  class DownloadAll
10
10
  # Download all valid provisioning profiles
11
11
  def download_all(download_xcode_profiles: false)
12
- UI.message("Starting login with user '#{Sigh.config[:username]}'")
13
- Spaceship.login(Sigh.config[:username], nil)
14
- Spaceship.select_team
15
- UI.message("Successfully logged in")
12
+ if (token = api_token)
13
+ UI.message("Creating authorization token for App Store Connect API")
14
+ Spaceship::ConnectAPI.token = token
15
+ else
16
+ # Team selection passed though FASTLANE_ITC_TEAM_ID and FASTLANE_ITC_TEAM_NAME environment variables
17
+ # Prompts select team if multiple teams and none specified
18
+ UI.message("Starting login with user '#{Sigh.config[:username]}'")
19
+ Spaceship::ConnectAPI.login(Sigh.config[:username], nil, use_portal: true, use_tunes: false)
20
+ UI.message("Successfully logged in")
21
+ end
16
22
 
17
23
  if download_xcode_profiles
18
24
  UI.deprecated("The App Store Connect API does not support querying for Xcode managed profiles: --download_code_profiles is deprecated")
@@ -53,6 +59,12 @@ module Sigh
53
59
  download_profiles(profiles)
54
60
  end
55
61
 
62
+ def api_token
63
+ api_token ||= Spaceship::ConnectAPI::Token.create(Sigh.config[:api_key]) if Sigh.config[:api_key]
64
+ api_token ||= Spaceship::ConnectAPI::Token.from_json_file(Sigh.config[:api_key_path]) if Sigh.config[:api_key_path]
65
+ return api_token
66
+ end
67
+
56
68
  # @param profiles [Array] Array of all the provisioning profiles we want to download
57
69
  def download_profiles(profiles)
58
70
  UI.important("No profiles available for download") if profiles.empty?
@@ -54,6 +54,25 @@ module Sigh
54
54
  code_gen_sensitive: true,
55
55
  default_value: CredentialsManager::AppfileConfig.try_fetch_value(:app_identifier),
56
56
  default_value_dynamic: true),
57
+
58
+ # App Store Connect API
59
+ FastlaneCore::ConfigItem.new(key: :api_key_path,
60
+ env_name: "SIGH_API_KEY_PATH",
61
+ description: "Path to your App Store Connect API Key JSON file (https://docs.fastlane.tools/app-store-connect-api/#using-fastlane-api-key-json-file)",
62
+ optional: true,
63
+ conflicting_options: [:api_key],
64
+ verify_block: proc do |value|
65
+ UI.user_error!("Couldn't find API key JSON file at path '#{value}'") unless File.exist?(value)
66
+ end),
67
+ FastlaneCore::ConfigItem.new(key: :api_key,
68
+ env_name: "SIGH_API_KEY",
69
+ description: "Your App Store Connect API Key information (https://docs.fastlane.tools/app-store-connect-api/#use-return-value-and-pass-in-as-an-option)",
70
+ type: Hash,
71
+ optional: true,
72
+ sensitive: true,
73
+ conflicting_options: [:api_key_path]),
74
+
75
+ # Apple ID
57
76
  FastlaneCore::ConfigItem.new(key: :username,
58
77
  short_option: "-u",
59
78
  env_name: "SIGH_USERNAME",
@@ -82,6 +101,8 @@ module Sigh
82
101
  verify_block: proc do |value|
83
102
  ENV["FASTLANE_TEAM_NAME"] = value.to_s
84
103
  end),
104
+
105
+ # Other options
85
106
  FastlaneCore::ConfigItem.new(key: :provisioning_name,
86
107
  short_option: "-n",
87
108
  env_name: "SIGH_PROVISIONING_PROFILE_NAME",
@@ -17,11 +17,16 @@ module Sigh
17
17
  hide_keys: [:output_path],
18
18
  title: "Summary for sigh #{Fastlane::VERSION}")
19
19
 
20
- # Team selection passed though FASTLANE_ITC_TEAM_ID and FASTLANE_ITC_TEAM_NAME environment variables
21
- # Prompts select team if multiple teams and none specified
22
- UI.message("Starting login with user '#{Sigh.config[:username]}'")
23
- Spaceship::ConnectAPI.login(Sigh.config[:username], nil, use_portal: true, use_tunes: false)
24
- UI.message("Successfully logged in")
20
+ if api_token
21
+ UI.message("Creating authorization token for App Store Connect API")
22
+ Spaceship::ConnectAPI.token = api_token
23
+ else
24
+ # Team selection passed though FASTLANE_ITC_TEAM_ID and FASTLANE_ITC_TEAM_NAME environment variables
25
+ # Prompts select team if multiple teams and none specified
26
+ UI.message("Starting login with user '#{Sigh.config[:username]}'")
27
+ Spaceship::ConnectAPI.login(Sigh.config[:username], nil, use_portal: true, use_tunes: false)
28
+ UI.message("Successfully logged in")
29
+ end
25
30
 
26
31
  profiles = [] if Sigh.config[:skip_fetch_profiles]
27
32
  profiles ||= fetch_profiles # download the profile if it's there
@@ -54,6 +59,12 @@ module Sigh
54
59
  return download_profile(profile)
55
60
  end
56
61
 
62
+ def api_token
63
+ @api_token ||= Spaceship::ConnectAPI::Token.create(Sigh.config[:api_key]) if Sigh.config[:api_key]
64
+ @api_token ||= Spaceship::ConnectAPI::Token.from_json_file(Sigh.config[:api_key_path]) if Sigh.config[:api_key_path]
65
+ return @api_token
66
+ end
67
+
57
68
  # The kind of provisioning profile we're interested in
58
69
  def profile_type
59
70
  return @profile_type if @profile_type
@@ -128,7 +139,7 @@ module Sigh
128
139
  # Skip certificates that failed to download
129
140
  next unless current_cert[:downloaded]
130
141
  file = Tempfile.new('cert')
131
- file.write(current_cert[:downloaded])
142
+ file.write(current_cert[:downloaded].force_encoding('UTF-8'))
132
143
  file.close
133
144
  if FastlaneCore::CertChecker.installed?(file.path)
134
145
  installed = true
@@ -190,65 +201,95 @@ module Sigh
190
201
  profiles
191
202
  end
192
203
 
204
+ def fetch_certificates(certificate_types)
205
+ filter = {
206
+ certificateType: certificate_types.join(',')
207
+ }
208
+ return Spaceship::ConnectAPI::Certificate.all(filter: filter)
209
+ end
210
+
193
211
  def certificates_for_profile_and_platform
212
+ types = []
213
+
194
214
  case Sigh.config[:platform].to_s
195
215
  when 'ios', 'tvos'
196
216
  if profile_type == Spaceship::ConnectAPI::Profile::ProfileType::IOS_APP_DEVELOPMENT || profile_type == Spaceship::ConnectAPI::Profile::ProfileType::TVOS_APP_DEVELOPMENT
197
- certificates = Spaceship.certificate.development.all +
198
- Spaceship.certificate.apple_development.all
217
+ types = [
218
+ Spaceship::ConnectAPI::Certificate::CertificateType::DEVELOPMENT,
219
+ Spaceship::ConnectAPI::Certificate::CertificateType::IOS_DEVELOPMENT
220
+ ]
199
221
  elsif profile_type == Spaceship::ConnectAPI::Profile::ProfileType::IOS_APP_INHOUSE || profile_type == Spaceship::ConnectAPI::Profile::ProfileType::TVOS_APP_INHOUSE
200
222
  # Enterprise accounts don't have access to Apple Distribution certificates
201
- certificates = Spaceship.certificate.in_house.all
223
+ types = [
224
+ Spaceship::ConnectAPI::Certificate::CertificateType::IOS_DISTRIBUTION
225
+ ]
202
226
  # handles case where the desired certificate type is adhoc but the account is an enterprise account
203
227
  # the apple dev portal api has a weird quirk in it where if you query for distribution certificates
204
228
  # for enterprise accounts, you get nothing back even if they exist.
205
- elsif (profile_type == Spaceship::ConnectAPI::Profile::ProfileType::IOS_APP_ADHOC || profile_type == Spaceship::ConnectAPI::Profile::ProfileType::TVOS_APP_ADHOC) && Spaceship.client && Spaceship.client.in_house?
229
+ elsif (profile_type == Spaceship::ConnectAPI::Profile::ProfileType::IOS_APP_ADHOC || profile_type == Spaceship::ConnectAPI::Profile::ProfileType::TVOS_APP_ADHOC) && Spaceship::ConnectAPI.client && Spaceship::ConnectAPI.client.in_house?
206
230
  # Enterprise accounts don't have access to Apple Distribution certificates
207
- certificates = Spaceship.certificate.in_house.all
231
+ types = [
232
+ Spaceship::ConnectAPI::Certificate::CertificateType::IOS_DISTRIBUTION
233
+ ]
208
234
  else
209
- # Ad hoc or App Store
210
- certificates = Spaceship.certificate.production.all +
211
- Spaceship.certificate.apple_distribution.all
235
+ types = [
236
+ Spaceship::ConnectAPI::Certificate::CertificateType::DISTRIBUTION,
237
+ Spaceship::ConnectAPI::Certificate::CertificateType::IOS_DISTRIBUTION
238
+ ]
212
239
  end
213
240
 
214
241
  when 'macos', 'catalyst'
215
242
  if profile_type == Spaceship::ConnectAPI::Profile::ProfileType::MAC_APP_DEVELOPMENT || profile_type == Spaceship::ConnectAPI::Profile::ProfileType::MAC_CATALYST_APP_DEVELOPMENT
216
- certificates = Spaceship.certificate.mac_development.all +
217
- Spaceship.certificate.apple_development.all
243
+ types = [
244
+ Spaceship::ConnectAPI::Certificate::CertificateType::DEVELOPMENT,
245
+ Spaceship::ConnectAPI::Certificate::CertificateType::MAC_APP_DEVELOPMENT
246
+ ]
218
247
  elsif profile_type == Spaceship::ConnectAPI::Profile::ProfileType::MAC_APP_STORE || profile_type == Spaceship::ConnectAPI::Profile::ProfileType::MAC_CATALYST_APP_STORE
219
- certificates = Spaceship.certificate.mac_app_distribution.all +
220
- Spaceship.certificate.apple_distribution.all
248
+ types = [
249
+ Spaceship::ConnectAPI::Certificate::CertificateType::DISTRIBUTION,
250
+ Spaceship::ConnectAPI::Certificate::CertificateType::MAC_APP_DISTRIBUTION
251
+ ]
221
252
  elsif profile_type == Spaceship::ConnectAPI::Profile::ProfileType::MAC_APP_DIRECT || profile_type == Spaceship::ConnectAPI::Profile::ProfileType::MAC_CATALYST_APP_DIRECT
222
- certificates = Spaceship.certificate.developer_id_application.all
253
+ types = [
254
+ Spaceship::ConnectAPI::Certificate::CertificateType::DEVELOPER_ID_APPLICATION
255
+ ]
223
256
  else
224
- certificates = Spaceship.certificate.mac_app_distribution.all +
225
- Spaceship.certificate.apple_distribution.all
257
+ types = [
258
+ Spaceship::ConnectAPI::Certificate::CertificateType::DISTRIBUTION,
259
+ Spaceship::ConnectAPI::Certificate::CertificateType::MAC_APP_DISTRIBUTION
260
+ ]
226
261
  end
227
262
  end
228
263
 
229
- certificates
264
+ fetch_certificates(types)
230
265
  end
231
266
 
232
267
  def devices_to_use
233
268
  # Only use devices if development or adhoc
234
269
  return [] if !Sigh.config[:development] && !Sigh.config[:adhoc]
235
270
 
236
- device_class = case Sigh.config[:platform].to_s
237
- when 'ios'
238
- [
239
- Spaceship::ConnectAPI::Device::DeviceClass::APPLE_WATCH,
240
- Spaceship::ConnectAPI::Device::DeviceClass::IPAD,
241
- Spaceship::ConnectAPI::Device::DeviceClass::IPHONE,
242
- Spaceship::ConnectAPI::Device::DeviceClass::IPOD
243
- ].join(",")
244
- when 'tvos'
245
- Spaceship::ConnectAPI::Device::DeviceClass::APPLE_TV
246
- when 'macos', 'catalyst'
247
- Spaceship::ConnectAPI::Device::DeviceClass::MAC
248
- end
249
-
250
- filter = { deviceClass: device_class }
251
- return Spaceship::ConnectAPI::Device.all(filter: filter)
271
+ device_classes = case Sigh.config[:platform].to_s
272
+ when 'ios'
273
+ [
274
+ Spaceship::ConnectAPI::Device::DeviceClass::APPLE_WATCH,
275
+ Spaceship::ConnectAPI::Device::DeviceClass::IPAD,
276
+ Spaceship::ConnectAPI::Device::DeviceClass::IPHONE,
277
+ Spaceship::ConnectAPI::Device::DeviceClass::IPOD
278
+ ]
279
+ when 'tvos'
280
+ [Spaceship::ConnectAPI::Device::DeviceClass::APPLE_TV]
281
+ when 'macos', 'catalyst'
282
+ [Spaceship::ConnectAPI::Device::DeviceClass::MAC]
283
+ end
284
+
285
+ if api_token
286
+ return Spaceship::ConnectAPI::Device.all.select do |device|
287
+ device_classes.include?(device.device_class)
288
+ end
289
+ else
290
+ filter = { deviceClass: device_classes.join(",") }
291
+ return Spaceship::ConnectAPI::Device.all(filter: filter)
292
+ end
252
293
  end
253
294
 
254
295
  # Certificate to use based on the current distribution mode
@@ -273,7 +314,8 @@ module Sigh
273
314
  unless Sigh.config[:skip_certificate_verification]
274
315
  certificates = certificates.find_all do |c|
275
316
  file = Tempfile.new('cert')
276
- file.write(c.download_raw)
317
+ raw_data = Base64.decode64(c.certificate_content)
318
+ file.write(raw_data.force_encoding("UTF-8"))
277
319
  file.close
278
320
 
279
321
  FastlaneCore::CertChecker.installed?(file.path)