fastlane 2.241.2 → 2.242.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +38 -38
  3. data/cert/lib/cert/runner.rb +1 -1
  4. data/credentials_manager/README.md +3 -3
  5. data/credentials_manager/lib/credentials_manager/account_manager.rb +13 -3
  6. data/deliver/lib/deliver/runner.rb +5 -0
  7. data/fastlane/lib/assets/certificates/AppleIncRootCertificate.cer +0 -0
  8. data/fastlane/lib/assets/certificates/AppleRootCA-G3.cer +0 -0
  9. data/fastlane/lib/fastlane/action.rb +8 -6
  10. data/fastlane/lib/fastlane/actions/app_store_connect_api_key.rb +1 -1
  11. data/fastlane/lib/fastlane/actions/changelog_from_git_commits.rb +0 -3
  12. data/fastlane/lib/fastlane/actions/clipboard.rb +1 -1
  13. data/fastlane/lib/fastlane/actions/commit_version_bump.rb +0 -1
  14. data/fastlane/lib/fastlane/actions/create_keychain.rb +20 -29
  15. data/fastlane/lib/fastlane/actions/delete_keychain.rb +5 -3
  16. data/fastlane/lib/fastlane/actions/docs/build_app.md +1 -1
  17. data/fastlane/lib/fastlane/actions/docs/create_app_online.md +1 -1
  18. data/fastlane/lib/fastlane/actions/docs/frame_screenshots.md +4 -4
  19. data/fastlane/lib/fastlane/actions/docs/get_provisioning_profile.md +1 -1
  20. data/fastlane/lib/fastlane/actions/docs/upload_to_app_store.md.erb +1 -1
  21. data/fastlane/lib/fastlane/actions/docs/upload_to_play_store.md +12 -0
  22. data/fastlane/lib/fastlane/actions/download_app_privacy_details_from_app_store.rb +5 -4
  23. data/fastlane/lib/fastlane/actions/download_dsyms.rb +3 -1
  24. data/fastlane/lib/fastlane/actions/get_managed_play_store_publishing_rights.rb +1 -0
  25. data/fastlane/lib/fastlane/actions/git_pull.rb +1 -1
  26. data/fastlane/lib/fastlane/actions/hg_commit_version_bump.rb +0 -1
  27. data/fastlane/lib/fastlane/actions/import_certificate.rb +18 -6
  28. data/fastlane/lib/fastlane/actions/import_from_gem.rb +70 -0
  29. data/fastlane/lib/fastlane/actions/jazzy.rb +1 -1
  30. data/fastlane/lib/fastlane/actions/lcov.rb +1 -1
  31. data/fastlane/lib/fastlane/actions/mailgun.rb +2 -2
  32. data/fastlane/lib/fastlane/actions/make_changelog_from_jenkins.rb +1 -1
  33. data/fastlane/lib/fastlane/actions/notarize.rb +55 -7
  34. data/fastlane/lib/fastlane/actions/prompt.rb +1 -1
  35. data/fastlane/lib/fastlane/actions/push_to_git_remote.rb +2 -2
  36. data/fastlane/lib/fastlane/actions/sh.rb +20 -2
  37. data/fastlane/lib/fastlane/actions/sourcedocs.rb +2 -2
  38. data/fastlane/lib/fastlane/actions/swiftlint.rb +5 -2
  39. data/fastlane/lib/fastlane/actions/unlock_keychain.rb +17 -29
  40. data/fastlane/lib/fastlane/actions/update_fastlane.rb +10 -3
  41. data/fastlane/lib/fastlane/actions/update_project_code_signing.rb +2 -1
  42. data/fastlane/lib/fastlane/actions/update_project_provisioning.rb +21 -18
  43. data/fastlane/lib/fastlane/actions/upload_app_privacy_details_to_app_store.rb +1 -1
  44. data/fastlane/lib/fastlane/actions/upload_symbols_to_crashlytics.rb +8 -2
  45. data/fastlane/lib/fastlane/actions/verify_build.rb +2 -1
  46. data/fastlane/lib/fastlane/actions/verify_pod_keys.rb +2 -1
  47. data/fastlane/lib/fastlane/actions/xcodebuild.rb +1 -1
  48. data/fastlane/lib/fastlane/cli_tools_distributor.rb +7 -0
  49. data/fastlane/lib/fastlane/environment_printer.rb +14 -14
  50. data/fastlane/lib/fastlane/fast_file.rb +35 -4
  51. data/fastlane/lib/fastlane/helper/sh_helper.rb +27 -45
  52. data/fastlane/lib/fastlane/lane_list.rb +1 -1
  53. data/fastlane/lib/fastlane/plugins/plugin_manager.rb +2 -2
  54. data/fastlane/lib/fastlane/plugins/template/.rubocop.yml +0 -2
  55. data/fastlane/lib/fastlane/runner.rb +4 -6
  56. data/fastlane/lib/fastlane/server/socket_server_action_command_executor.rb +4 -4
  57. data/fastlane/lib/fastlane/swift_fastlane_api_generator.rb +3 -3
  58. data/fastlane/lib/fastlane/version.rb +2 -1
  59. data/fastlane/swift/Deliverfile.swift +1 -1
  60. data/fastlane/swift/DeliverfileProtocol.swift +1 -1
  61. data/fastlane/swift/Fastlane.swift +46 -152
  62. data/fastlane/swift/Gymfile.swift +1 -1
  63. data/fastlane/swift/GymfileProtocol.swift +1 -1
  64. data/fastlane/swift/Matchfile.swift +1 -1
  65. data/fastlane/swift/MatchfileProtocol.swift +1 -1
  66. data/fastlane/swift/Precheckfile.swift +1 -1
  67. data/fastlane/swift/PrecheckfileProtocol.swift +1 -1
  68. data/fastlane/swift/Runner.swift +1 -1
  69. data/fastlane/swift/Scanfile.swift +1 -1
  70. data/fastlane/swift/ScanfileProtocol.swift +1 -1
  71. data/fastlane/swift/Screengrabfile.swift +1 -1
  72. data/fastlane/swift/ScreengrabfileProtocol.swift +1 -1
  73. data/fastlane/swift/Snapshotfile.swift +1 -1
  74. data/fastlane/swift/SnapshotfileProtocol.swift +1 -1
  75. data/fastlane_core/lib/fastlane_core/cert_checker.rb +40 -76
  76. data/fastlane_core/lib/fastlane_core/command_executor.rb +128 -7
  77. data/fastlane_core/lib/fastlane_core/configuration/config_item.rb +1 -1
  78. data/fastlane_core/lib/fastlane_core/configuration/configuration_file.rb +1 -1
  79. data/fastlane_core/lib/fastlane_core/device_manager.rb +14 -5
  80. data/fastlane_core/lib/fastlane_core/fastlane_pty.rb +25 -10
  81. data/fastlane_core/lib/fastlane_core/helper.rb +26 -2
  82. data/fastlane_core/lib/fastlane_core/ios_app_identifier_guesser.rb +1 -1
  83. data/fastlane_core/lib/fastlane_core/itunes_transporter.rb +24 -19
  84. data/fastlane_core/lib/fastlane_core/keychain_importer.rb +48 -71
  85. data/fastlane_core/lib/fastlane_core/pkg_file_analyser.rb +5 -1
  86. data/fastlane_core/lib/fastlane_core/print_table.rb +1 -1
  87. data/fastlane_core/lib/fastlane_core/queue_worker.rb +0 -2
  88. data/fastlane_core/lib/fastlane_core/stored_passwords.rb +29 -0
  89. data/fastlane_core/lib/fastlane_core/string_filters.rb +1 -2
  90. data/fastlane_core/lib/fastlane_core/ui/fastlane_runner.rb +8 -4
  91. data/fastlane_core/lib/fastlane_core/ui/github_issue_inspector_reporter.rb +2 -2
  92. data/fastlane_core/lib/fastlane_core/ui/implementations/shell.rb +1 -1
  93. data/frameit/lib/frameit/device_types.rb +11 -4
  94. data/frameit/lib/frameit/editor.rb +31 -12
  95. data/frameit/lib/frameit/frame_downloader.rb +4 -1
  96. data/gym/lib/gym/detect_values.rb +10 -10
  97. data/gym/lib/gym/options.rb +1 -7
  98. data/gym/lib/gym/runner.rb +6 -1
  99. data/match/lib/match/encryption/encryption.rb +6 -1
  100. data/match/lib/match/encryption/openssl.rb +8 -3
  101. data/match/lib/match/portal_fetcher.rb +12 -6
  102. data/match/lib/match/runner.rb +2 -1
  103. data/pem/lib/pem/manager.rb +3 -3
  104. data/precheck/lib/precheck/runner.rb +4 -2
  105. data/scan/lib/scan/detect_values.rb +0 -1
  106. data/scan/lib/scan/runner.rb +1 -0
  107. data/sigh/lib/assets/resign.sh +10 -3
  108. data/sigh/lib/sigh/resign.rb +5 -21
  109. data/snapshot/lib/snapshot/reset_simulators.rb +5 -2
  110. data/snapshot/lib/snapshot/runner.rb +0 -1
  111. data/spaceship/lib/spaceship/base.rb +1 -1
  112. data/spaceship/lib/spaceship/client.rb +6 -3
  113. data/spaceship/lib/spaceship/connect_api/api_client.rb +12 -14
  114. data/spaceship/lib/spaceship/connect_api/models/bundle_id.rb +1 -1
  115. data/spaceship/lib/spaceship/connect_api/models/user.rb +7 -3
  116. data/spaceship/lib/spaceship/connect_api/testflight/testflight.rb +9 -11
  117. data/spaceship/lib/spaceship/connect_api/token.rb +21 -1
  118. data/spaceship/lib/spaceship/connect_api/tunes/tunes.rb +3 -1
  119. data/spaceship/lib/spaceship/helper/plist_middleware.rb +2 -2
  120. data/spaceship/lib/spaceship/portal/portal_client.rb +8 -8
  121. data/spaceship/lib/spaceship/test_flight/client.rb +1 -5
  122. data/supply/lib/supply/client.rb +1 -1
  123. data/supply/lib/supply/options.rb +6 -0
  124. data/supply/lib/supply/uploader.rb +28 -2
  125. metadata +29 -26
  126. data/fastlane/lib/fastlane/actions/hockey.rb +0 -400
  127. data/fastlane/lib/fastlane/actions/typetalk.rb +0 -93
@@ -1,5 +1,6 @@
1
1
  require 'tempfile'
2
2
  require 'openssl'
3
+ require 'security'
3
4
 
4
5
  require_relative 'features'
5
6
  require_relative 'helper'
@@ -74,80 +75,46 @@ module FastlaneCore
74
75
  def self.installed_identities(in_keychain: nil)
75
76
  install_missing_wwdr_certificates(in_keychain: in_keychain)
76
77
 
77
- available = list_available_identities(in_keychain: in_keychain)
78
- # Match for this text against word boundaries to avoid edge cases around multiples of 10 identities!
79
- if /\b0 valid identities found\b/ =~ available
78
+ identities = available_identities(in_keychain: in_keychain)
79
+ if identities.empty?
80
80
  UI.error([
81
81
  "There are no local code signing identities found.",
82
- "You can run" << " `security find-identity -v -p codesigning #{in_keychain}".rstrip << "` to get this output.",
82
+ "You can run" + " `security find-identity -v -p codesigning #{in_keychain}".rstrip + "` to get this output.",
83
83
  "This Stack Overflow thread has more information: https://stackoverflow.com/q/35390072/774.",
84
84
  "(Check in Keychain Access for an expired WWDR certificate: https://stackoverflow.com/a/35409835/774 has more info.)"
85
85
  ].join("\n"))
86
86
  end
87
87
 
88
- ids = []
89
- available.split("\n").each do |current|
90
- next if current.include?("REVOKED")
91
- begin
92
- (ids << current.match(/.*\) ([[:xdigit:]]*) \".*/)[1])
93
- rescue
94
- # the last line does not match
95
- end
96
- end
97
-
98
- return ids
88
+ identities.reject { |identity| identity.status.to_s.include?("REVOKED") }.map(&:sha1)
99
89
  end
100
90
 
101
91
  def self.installed_installers(in_keychain: nil)
102
- available = self.list_available_third_party_mac_installer(in_keychain: in_keychain)
103
- available += self.list_available_developer_id_installer(in_keychain: in_keychain)
104
-
105
- return available.scan(/^SHA-1 hash: ([[:xdigit:]]+)$/).flatten
106
- end
107
-
108
- def self.list_available_identities(in_keychain: nil)
109
- # -v Show valid identities only (default is to show all identities)
110
- # -p Specify policy to evaluate
111
- commands = ['security find-identity -v -p codesigning']
112
- commands << in_keychain if in_keychain
113
- `#{commands.join(' ')}`
92
+ ["3rd Party Mac Developer Installer", "Developer ID Installer"].flat_map do |name|
93
+ find_certificates(name, keychain: in_keychain).map(&:sha1)
94
+ end
114
95
  end
115
96
 
116
- def self.list_available_third_party_mac_installer(in_keychain: nil)
117
- # -Z Print SHA-256 (and SHA-1) hash of the certificate
118
- # -a Find all matching certificates, not just the first one
119
- # -c Match on "name" when searching (optional)
120
- commands = ['security find-certificate -Z -a -c "3rd Party Mac Developer Installer"']
121
- commands << in_keychain if in_keychain
122
- `#{commands.join(' ')}`
97
+ def self.available_identities(in_keychain: nil)
98
+ Security::Identity.find(keychain: in_keychain)
99
+ rescue Security::Error => e
100
+ UI.error("Could not list the code signing identities: #{e.message}")
101
+ []
123
102
  end
124
103
 
125
- def self.list_available_developer_id_installer(in_keychain: nil)
126
- # -Z Print SHA-256 (and SHA-1) hash of the certificate
127
- # -a Find all matching certificates, not just the first one
128
- # -c Match on "name" when searching (optional)
129
- commands = ['security find-certificate -Z -a -c "Developer ID Installer"']
130
- commands << in_keychain if in_keychain
131
- `#{commands.join(' ')}`
104
+ def self.find_certificates(name, keychain: nil)
105
+ Security::Certificate.find(name: name, keychain: keychain)
106
+ rescue Security::Error => e
107
+ UI.error("Could not search for '#{name}' certificates: #{e.message}")
108
+ []
132
109
  end
133
110
 
134
111
  def self.installed_wwdr_certificates(keychain: nil)
135
112
  keychain ||= wwdr_keychain # backwards compatibility
136
113
 
137
- # Find all installed WWDRCA certificates. A single `security
138
- # find-certificate` call can only match one common name, so query the
139
- # keychain once per common name used by the certificates
140
- installed_certs = []
141
- WWDRCA_CERTIFICATE_NAMES.each do |certificate_name|
142
- Helper.backticks("security find-certificate -a -c '#{certificate_name}' -p #{keychain.shellescape}", print: false)
143
- .lines
144
- .each do |line|
145
- if line.start_with?('-----BEGIN CERTIFICATE-----')
146
- installed_certs << line
147
- else
148
- installed_certs.last << line
149
- end
150
- end
114
+ # A single `security find-certificate` call can only match one common
115
+ # name, so query the keychain once per common name used by the certificates
116
+ installed_certs = WWDRCA_CERTIFICATE_NAMES.flat_map do |certificate_name|
117
+ find_certificates(certificate_name, keychain: keychain).map(&:pem)
151
118
  end
152
119
 
153
120
  # Get the alias (see `WWDRCA_CERTIFICATES`) of the installed WWDRCA certificates
@@ -175,7 +142,7 @@ module FastlaneCore
175
142
  file = Tempfile.new([File.basename(url, ".cer"), ".cer"])
176
143
  filename = file.path
177
144
  keychain ||= wwdr_keychain # backwards compatibility
178
- keychain = "-k #{keychain.shellescape}" unless keychain.empty?
145
+ UI.user_error!("Could not install WWDR certificate: no keychain found to install it into") if keychain.empty?
179
146
 
180
147
  # Attempts to fix an issue installing WWDR cert tends to fail on CIs
181
148
  # https://github.com/fastlane/fastlane/issues/20960
@@ -184,40 +151,37 @@ module FastlaneCore
184
151
  curl_extras = "--http1.1 --retry 3 --retry-all-errors "
185
152
  end
186
153
 
187
- import_command = "curl #{curl_extras}-f -o #{filename} #{url} && security import #{filename} #{keychain}"
188
- UI.verbose("Installing WWDR Cert: #{import_command}")
154
+ download_command = "curl #{curl_extras}-f -o #{filename} #{url}"
155
+ UI.verbose("Downloading WWDR Cert: #{download_command}")
189
156
 
190
157
  require 'open3'
191
- stdout, stderr, status = Open3.capture3(import_command)
158
+ stdout, stderr, status = Open3.capture3(download_command)
192
159
  if FastlaneCore::Globals.verbose?
193
160
  UI.command_output(stdout)
194
161
  UI.command_output(stderr)
195
162
  end
163
+ UI.user_error!("Could not download WWDR certificate") unless status.success?
196
164
 
197
- unless status.success?
198
- UI.verbose("Failed to install WWDR Certificate, checking output to see why")
199
- # Check the command output, WWDR might already exist
200
- unless /The specified item already exists in the keychain./ =~ stderr
201
- UI.user_error!("Could not install WWDR certificate")
202
- end
165
+ begin
166
+ Security::Certificate.import(filename, keychain: keychain, trusted_applications: [])
167
+ rescue Security::DuplicateItemError
203
168
  UI.verbose("WWDR Certificate was already installed")
169
+ rescue Security::Error => e
170
+ UI.user_error!("Could not install WWDR certificate: #{e.message}")
204
171
  end
205
172
  return true
206
173
  end
207
174
 
208
175
  def self.wwdr_keychain
209
- priority = [
210
- "security default-keychain -d user",
211
- "security list-keychains -d user"
212
- ]
213
- priority.each do |command|
214
- keychains = Helper.backticks(command, print: FastlaneCore::Globals.verbose?).split("\n")
215
- unless keychains.empty?
216
- # Select first keychain name from returned keychains list
217
- return keychains[0].strip.tr('"', '')
218
- end
176
+ keychain = begin
177
+ Security::Keychain.default_keychain
178
+ rescue Security::Error
179
+ nil
219
180
  end
220
- return ""
181
+ keychain ||= Security::Keychain.list(:user).first
182
+ keychain ? keychain.filename : ""
183
+ rescue Security::Error
184
+ ""
221
185
  end
222
186
 
223
187
  def self.sha1_fingerprint(path)
@@ -1,3 +1,5 @@
1
+ require 'open3'
2
+ require 'shellwords'
1
3
  require_relative 'ui/ui'
2
4
  require_relative 'globals'
3
5
  require_relative 'fastlane_pty'
@@ -31,9 +33,16 @@ module FastlaneCore
31
33
  # @param suppress_output [Boolean] Should we print the command's output?
32
34
  # @param suppress_error_output [Boolean] Suppress replaying output and printing the exit status
33
35
  # when the command fails, unless verbose output is enabled.
36
+ # @param env [Hash] environment variables for the command only, never printed: e.g. a value it should not get on its command line
37
+ # @param chdir [String] directory the command runs in; fastlane's own stays as it is
34
38
  # @return [String] All the output as string
35
39
  def execute(command: nil, print_all: false, print_command: true, error: nil, prefix: nil, loading: nil,
36
- suppress_output: false, suppress_error_output: false)
40
+ suppress_output: false, suppress_error_output: false, env: {}, chdir: nil)
41
+ # Read the output as UTF-8 whatever the user set, as sh does; restored below
42
+ previous_encoding = [Encoding.default_external, Encoding.default_internal]
43
+ Encoding.default_external = Encoding::UTF_8
44
+ Encoding.default_internal = Encoding::UTF_8
45
+
37
46
  verbose = FastlaneCore::Globals.verbose?
38
47
  print_all = true if verbose
39
48
  suppress_error_output = false if verbose
@@ -48,7 +57,9 @@ module FastlaneCore
48
57
  end
49
58
 
50
59
  begin
51
- status = FastlaneCore::FastlanePty.spawn(command) do |command_stdout, command_stdin, pid|
60
+ # Options only when given, so existing calls reach FastlanePty.spawn unchanged
61
+ spawn_options = { env: (env unless env.empty?), chdir: chdir }.compact
62
+ status = FastlaneCore::FastlanePty.spawn(command, **spawn_options) do |command_stdout, command_stdin, pid|
52
63
  command_stdout.each do |l|
53
64
  line = l.chomp
54
65
  line = line[1..-1] if line[0] == "\r"
@@ -73,11 +84,10 @@ module FastlaneCore
73
84
  output << ex.to_s
74
85
  o = output.join("\n")
75
86
  puts(o) unless suppress_error_output
76
- if error
77
- error.call(o, nil)
78
- else
79
- raise ex
80
- end
87
+ raise ex unless error
88
+ # Once, with the exit status FastlanePty read: -1 when the command was killed
89
+ error.call(o, ex.exit_status)
90
+ return o
81
91
  end
82
92
 
83
93
  # Exit status for build command, should be 0 if build succeeded
@@ -98,6 +108,117 @@ module FastlaneCore
98
108
  end
99
109
 
100
110
  return output.join("\n")
111
+ ensure
112
+ Encoding.default_external = previous_encoding.first
113
+ Encoding.default_internal = previous_encoding.last
114
+ end
115
+
116
+ # Runs a program with these arguments, without a shell: nothing needs escaping.
117
+ # An environment Hash may come first, as in Process.spawn.
118
+ # It runs in specs too, unlike Actions.sh, which returns the command string there.
119
+ #
120
+ # @param print_command [Boolean] print the command, shell-escaped
121
+ # @param print_output [Boolean] print stdout and stderr as they come; never forced on, so output that holds a secret stays hidden
122
+ # @param separate_stderr [Boolean] return stdout only; stderr goes to the error
123
+ # @param stdin [String] data written to the program's standard input, which is then closed; fastlane never prints it, the program's own output may
124
+ # @param chdir [String] directory the program runs in; fastlane's own stays as it is
125
+ # @param error [Proc] called with the output (stderr with separate_stderr) and the Process::Status, nil when the
126
+ # program could not start; its value is returned. Without it, a failure raises.
127
+ # @return [String] the output
128
+ def run(*command, print_command: true, print_output: false, separate_stderr: false, stdin: nil, chdir: nil, error: nil)
129
+ env = command.first.kind_of?(Hash) ? command.shift : {}
130
+ program, *arguments = command
131
+ shell_command = (env.map { |k, v| "#{k}=#{v.to_s.shellescape}" } + [command.shelljoin]).join(" ")
132
+ UI.command(shell_command) if print_command
133
+
134
+ # Checked first: starting in a missing directory raises the same Errno::ENOENT as a missing program
135
+ if chdir && !File.directory?(chdir)
136
+ message = "no directory '#{chdir}'"
137
+ return error.call(message, nil) if error
138
+ UI.user_error!("`#{shell_command}` failed: #{message}")
139
+ end
140
+
141
+ # [program, program] makes Ruby start the program itself, even with no arguments: a single string would go to a shell
142
+ result = collect(env, [program, program], *arguments, stdin: stdin, separate_stderr: separate_stderr, print_output: print_output, chdir: chdir)
143
+ return result.output if result.status.success?
144
+
145
+ failure_output = result.errors || result.output
146
+ return error.call(failure_output, result.status) if error
147
+ signal = FastlanePty.signal_name(result.status)
148
+ outcome = signal ? "failed: killed by #{signal}" : "failed with exit status #{result.status.exitstatus}:"
149
+ UI.user_error!("`#{shell_command}` #{outcome}\n#{failure_output[-500..] || failure_output}")
150
+ rescue SystemCallError => e
151
+ raise unless e.kind_of?(Errno::ENOENT) || e.kind_of?(Errno::EACCES)
152
+ return error.call(e.message, nil) if error
153
+ UI.user_error!("`#{shell_command}` failed: #{e.message}")
154
+ end
155
+
156
+ Result = Struct.new(:output, :errors, :status)
157
+
158
+ # Starts the command and collects its output and status; shared by run and Actions.sh.
159
+ # The command takes the forms of Process.spawn: one string goes through a shell, separate arguments do not,
160
+ # and an environment Hash may come first.
161
+ #
162
+ # collect("ls -la /Applications/Xcode\ 7.3.1.app")
163
+ # collect("ls", "-la", "/Applications/Xcode 7.3.1.app")
164
+ # collect({ "FOO" => "Hello" }, "echo $FOO")
165
+ #
166
+ # @param stdin [String] data written to the command's standard input, which is then closed; fastlane never prints it, the command's own output may
167
+ # @param separate_stderr [Boolean] keep stderr apart, in Result#errors
168
+ # @param print_output [Boolean] print stdout and stderr as they come
169
+ # @param chdir [String] directory the command runs in; fastlane's own stays as it is
170
+ # @return [Result] output: everything, or stdout only with separate_stderr; errors: stderr with separate_stderr, else nil
171
+ def collect(*command, stdin: nil, separate_stderr: false, print_output: false, chdir: nil)
172
+ previous_encoding = [Encoding.default_external, Encoding.default_internal]
173
+ Encoding.default_external = Encoding::UTF_8
174
+ Encoding.default_internal = Encoding::UTF_8
175
+
176
+ output = +''
177
+ errors = separate_stderr ? +'' : nil
178
+ status = nil
179
+ sanitized_output = false
180
+ print_line = lambda do |line|
181
+ next unless print_output
182
+ # Ensure the string being stripped is in valid UTF-8 format; Otherwise warn at the end
183
+ text = line.encode('UTF-8', invalid: :replace)
184
+ UI.command_output(text.strip)
185
+ sanitized_output = true if text != line
186
+ end
187
+
188
+ # chdir only when given, so existing calls reach Open3 unchanged
189
+ Open3.public_send(separate_stderr ? :popen3 : :popen2e, *command, **{ chdir: chdir }.compact) do |command_stdin, io, *error_io, thread|
190
+ # From a thread, so a command that writes a lot before reading its input cannot block on a full pipe
191
+ writer = stdin && Thread.new do
192
+ command_stdin.write(stdin)
193
+ rescue Errno::EPIPE
194
+ # The command exited without reading all of it; its exit status says what happened
195
+ ensure
196
+ command_stdin.close
197
+ end
198
+ # Nothing to give: the command reads end-of-file instead of waiting on an input nobody writes to
199
+ command_stdin.close unless stdin
200
+ # From a thread too, so a command that fills stderr while stdout is read cannot block
201
+ error_reader = errors && Thread.new do
202
+ error_io.first.each do |line|
203
+ print_line.call(line)
204
+ errors << line
205
+ end
206
+ end
207
+ io.sync = true
208
+ io.each do |line|
209
+ print_line.call(line)
210
+ output << line
211
+ end
212
+ error_reader&.join
213
+ status = thread.value
214
+ writer&.join
215
+ end
216
+
217
+ UI.important("Command output wasn't valid UTF-8 and was sanitized. Please report the issue.") if sanitized_output
218
+ Result.new(output, errors, status)
219
+ ensure
220
+ Encoding.default_external = previous_encoding.first
221
+ Encoding.default_internal = previous_encoding.last
101
222
  end
102
223
  end
103
224
  end
@@ -326,7 +326,7 @@ module FastlaneCore
326
326
  def deprecated_description(initial_description, deprecated)
327
327
  has_description = !initial_description.to_s.empty?
328
328
 
329
- description = "**DEPRECATED!**"
329
+ description = +"**DEPRECATED!**"
330
330
 
331
331
  if deprecated.kind_of?(String)
332
332
  description << " #{deprecated}"
@@ -113,7 +113,7 @@ module FastlaneCore
113
113
 
114
114
  # to support frozen strings (e.g. ENV variables) too
115
115
  # we have to dupe the value
116
- # in < Ruby 2.4.0 `.dup` is not support by boolean values
116
+ # some objects, such as singleton classes, cannot be duped,
117
117
  # and there is no good way to check if a class actually
118
118
  # responds to `dup`, so we have to rescue the exception
119
119
  begin
@@ -202,18 +202,17 @@ module FastlaneCore
202
202
 
203
203
  def boot
204
204
  return unless is_simulator
205
- return unless os_type == "iOS"
206
205
  return if self.state == 'Booted'
207
206
 
208
207
  # Boot the simulator and wait for it to finish booting
209
208
  UI.message("Booting #{self}")
210
- `xcrun simctl bootstatus #{self.udid} -b &> /dev/null`
209
+ output, status = Open3.capture2e("xcrun simctl bootstatus #{self.udid} -b")
210
+ UI.important("Unable to boot #{self}: #{output.strip}") unless status.success?
211
211
  self.state = 'Booted'
212
212
  end
213
213
 
214
214
  def shutdown
215
215
  return unless is_simulator
216
- return unless os_type == "iOS"
217
216
  return if self.state != 'Booted'
218
217
 
219
218
  UI.message("Shutting down #{self.udid}")
@@ -356,8 +355,18 @@ module FastlaneCore
356
355
  logs_collection_start = log_collection_start_time.strftime('%Y-%m-%d %H:%M:%S')
357
356
  command = "xcrun simctl spawn #{device.udid} log collect "
358
357
  command << "--start '#{logs_collection_start}' "
359
- command << "--output #{logarchive_dst.shellescape} 2>/dev/null"
360
- FastlaneCore::CommandExecutor.execute(command: command, print_all: false, print_command: true)
358
+ command << "--output #{logarchive_dst.shellescape}"
359
+ # A simulator that is no longer booted only warrants a warning: the logs are diagnostics.
360
+ # Any other failure still fails the action.
361
+ FastlaneCore::CommandExecutor.execute(command: command,
362
+ print_all: false,
363
+ print_command: true,
364
+ suppress_error_output: true,
365
+ error: proc do |output, status|
366
+ message = "Unable to collect system logs from #{device} (exit status #{status}): #{output}"
367
+ UI.user_error!(message) unless output.match?(/domain=com\.apple\.CoreSimulator\.SimError, code=405\b/)
368
+ UI.important(message)
369
+ end)
361
370
  end
362
371
  end
363
372
  end
@@ -20,13 +20,16 @@ module FastlaneCore
20
20
  end
21
21
 
22
22
  class FastlanePty
23
- def self.spawn(command, &block)
24
- spawn_with_pty(command, &block)
23
+ # @param env [Hash] environment variables for the command only, e.g. a value it should not get on its command line
24
+ # @param chdir [String] directory the command runs in; fastlane's own stays as it is
25
+ def self.spawn(command, env: {}, chdir: nil, &block)
26
+ spawn_with_pty(command, env: env, chdir: chdir, &block)
25
27
  rescue LoadError
26
- spawn_with_popen(command, &block)
28
+ spawn_with_popen(command, env: env, chdir: chdir, &block)
27
29
  end
28
30
 
29
- def self.spawn_with_pty(original_command, &block)
31
+ # On macOS the output of a command that exits very quickly can, rarely, be lost before it is read: see fastlane#21792
32
+ def self.spawn_with_pty(original_command, env: {}, chdir: nil, &block)
30
33
  require 'pty'
31
34
  # this forces the PTY flush - fixes #21792
32
35
  command = ENV['FASTLANE_EXEC_FLUSH_PTY_WORKAROUND'] ? "#{original_command};" : original_command
@@ -35,7 +38,7 @@ module FastlaneCore
35
38
  # that runs a subprocess in between overwrites it, and nothing writes it at
36
39
  # all when the wait does not happen. See fastlane#30188.
37
40
  status = nil
38
- PTY.spawn(command) do |command_stdout, command_stdin, pid|
41
+ PTY.spawn(*spawn_args(env, command, chdir)) do |command_stdout, command_stdin, pid|
39
42
  begin
40
43
  yield(command_stdout, command_stdin, pid)
41
44
  rescue Errno::EIO
@@ -62,7 +65,7 @@ module FastlaneCore
62
65
  # Better a plain error than a NoMethodError raised from inside the handler
63
66
  # that exists to report the failure, which is what nil used to produce.
64
67
  raise StandardError, "Could not determine the exit status of the command" if status.nil?
65
- raise StandardError, "Process crashed" if status.signaled?
68
+ raise StandardError, "Process crashed: killed by #{signal_name(status)}" if status.signaled?
66
69
  status.exitstatus
67
70
  rescue StandardError => e
68
71
  # Wrapping any error in FastlanePtyError to allow callers to see and use
@@ -71,21 +74,33 @@ module FastlaneCore
71
74
  raise FastlanePtyError.new(e, status&.exitstatus || e.exit_status, status)
72
75
  end
73
76
 
74
- def self.spawn_with_popen(command, &block)
77
+ def self.spawn_with_popen(command, env: {}, chdir: nil, &block)
75
78
  status = nil
76
79
  require 'open3'
77
- Open3.popen2e(command) do |command_stdin, command_stdout, p| # note the inversion
80
+ Open3.popen2e(*spawn_args(env, command, chdir)) do |command_stdin, command_stdout, p| # note the inversion
78
81
  status = p.value
79
82
  yield(command_stdout, command_stdin, status.pid)
80
83
  command_stdin.close
81
84
  command_stdout.close
82
- raise StandardError, "Process crashed" if status.signaled?
85
+ raise StandardError, "Process crashed: killed by #{signal_name(status)}" if status.signaled?
83
86
  status.exitstatus
84
87
  end
85
88
  rescue StandardError => e
86
89
  # Wrapping any error in FastlanePtyError to allow callers to see and use
87
90
  # $?.exitstatus that would usually get returned
88
- raise FastlanePtyError.new(e, status.exitstatus || e.exit_status, status)
91
+ raise FastlanePtyError.new(e, status&.exitstatus || e.exit_status, status)
92
+ end
93
+
94
+ # Existing callers keep calling spawn with the command alone: env and chdir are added only when given
95
+ def self.spawn_args(env, command, chdir = nil)
96
+ args = (env || {}).empty? ? [command] : [env, command]
97
+ chdir ? args + [{ chdir: chdir }] : args
98
+ end
99
+
100
+ # "SIGKILL" for a process killed by a signal, nil otherwise: Process::Status#exitstatus is nil only then
101
+ def self.signal_name(status)
102
+ return nil unless status.exitstatus.nil? && status.respond_to?(:termsig) && status.termsig
103
+ "SIG#{Signal.signame(status.termsig)}"
89
104
  end
90
105
 
91
106
  # to ease mocking
@@ -2,6 +2,7 @@ require 'logger'
2
2
  require 'colored'
3
3
  require 'tty-spinner'
4
4
  require 'pathname'
5
+ require 'fileutils'
5
6
 
6
7
  require_relative 'command_executor'
7
8
  require_relative 'fastlane_folder'
@@ -203,7 +204,7 @@ module FastlaneCore
203
204
  def self.swift_version
204
205
  if self.which('swift')
205
206
  output = `swift --version 2> /dev/null`
206
- return output.split("\n").first.match(/version ([0-9.]+)/).captures.first
207
+ return output.lines.first.to_s[/version ([0-9.]+)/, 1]
207
208
  end
208
209
  return nil
209
210
  end
@@ -263,6 +264,9 @@ module FastlaneCore
263
264
  result = File.expand_path(File.join(self.xcode_path, path))
264
265
  return result if File.exist?(result)
265
266
  end
267
+ if FastlaneCore::Env.truthy?("FASTLANE_ITUNES_TRANSPORTER_USE_SHELL_SCRIPT")
268
+ UI.user_error!("Could not find transporter at #{self.xcode_path}: Xcode 14 and newer no longer include it. Remove FASTLANE_ITUNES_TRANSPORTER_USE_SHELL_SCRIPT so fastlane uploads with altool, or install Transporter and set FASTLANE_ITUNES_TRANSPORTER_PATH.")
269
+ end
266
270
  UI.user_error!("Could not find transporter at #{self.xcode_path}. Please make sure you set the correct path to your Xcode installation.")
267
271
  elsif self.windows?
268
272
  [
@@ -344,6 +348,21 @@ module FastlaneCore
344
348
  str.gsub(/\e\[([;\d]+)?m/, '')
345
349
  end
346
350
 
351
+ # Opens path for writing, readable and writable only by its owner (0600), including when it
352
+ # already exists: the mode is set before anything is written. Windows has no such mode.
353
+ def self.open_owner_only(path, mode = "w", &block)
354
+ File.open(path, mode, 0o600) do |file|
355
+ file.chmod(0o600) unless windows?
356
+ yield(file)
357
+ end
358
+ end
359
+
360
+ # Creates dir and any missing parents accessible only by its owner (0700); an existing dir is restricted too
361
+ def self.mkdir_owner_only(dir)
362
+ FileUtils.mkdir_p(dir, mode: 0o700)
363
+ File.chmod(0o700, dir) unless windows?
364
+ end
365
+
347
366
  # Zips directory
348
367
  def self.zip_directory(path, output_path, contents_only: false, overwrite: false, print: true)
349
368
  if overwrite
@@ -362,7 +381,12 @@ module FastlaneCore
362
381
  end
363
382
 
364
383
  UI.command(command) unless print
365
- Helper.backticks(command, print: print)
384
+ FastlaneCore::CommandExecutor.execute(command: command,
385
+ print_all: print,
386
+ print_command: print,
387
+ error: proc do |output|
388
+ UI.user_error!("Could not zip '#{path}' to '#{output_path}':\n#{output}")
389
+ end)
366
390
  end
367
391
 
368
392
  # Executes the provided block after adjusting the ENV to have the
@@ -73,7 +73,7 @@ module FastlaneCore
73
73
  end
74
74
 
75
75
  def match_swift_application_id(text_line: nil)
76
- text_line.strip!
76
+ text_line = text_line.strip
77
77
  application_id_match = APP_ID_REGEX.match(text_line)
78
78
  return application_id_match[1].strip if application_id_match
79
79