fastlane 2.241.1 → 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 (140) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +39 -39
  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/commands_generator.rb +7 -1
  50. data/fastlane/lib/fastlane/environment_printer.rb +14 -14
  51. data/fastlane/lib/fastlane/fast_file.rb +35 -4
  52. data/fastlane/lib/fastlane/helper/sh_helper.rb +27 -45
  53. data/fastlane/lib/fastlane/lane_list.rb +1 -1
  54. data/fastlane/lib/fastlane/plugins/plugin_manager.rb +2 -2
  55. data/fastlane/lib/fastlane/plugins/template/.rubocop.yml +0 -2
  56. data/fastlane/lib/fastlane/runner.rb +4 -6
  57. data/fastlane/lib/fastlane/server/socket_server.rb +57 -7
  58. data/fastlane/lib/fastlane/server/socket_server_action_command_executor.rb +4 -4
  59. data/fastlane/lib/fastlane/swift_fastlane_api_generator.rb +3 -3
  60. data/fastlane/lib/fastlane/swift_lane_manager.rb +32 -11
  61. data/fastlane/lib/fastlane/version.rb +2 -1
  62. data/fastlane/swift/ArgumentProcessor.swift +10 -2
  63. data/fastlane/swift/Deliverfile.swift +1 -1
  64. data/fastlane/swift/DeliverfileProtocol.swift +1 -1
  65. data/fastlane/swift/Fastlane.swift +46 -152
  66. data/fastlane/swift/Gymfile.swift +1 -1
  67. data/fastlane/swift/GymfileProtocol.swift +1 -1
  68. data/fastlane/swift/MainProcess.swift +27 -0
  69. data/fastlane/swift/Matchfile.swift +1 -1
  70. data/fastlane/swift/MatchfileProtocol.swift +1 -1
  71. data/fastlane/swift/Precheckfile.swift +1 -1
  72. data/fastlane/swift/PrecheckfileProtocol.swift +1 -1
  73. data/fastlane/swift/RubyCommand.swift +1 -9
  74. data/fastlane/swift/RubyCommandable.swift +3 -2
  75. data/fastlane/swift/Runner.swift +1 -1
  76. data/fastlane/swift/Scanfile.swift +1 -1
  77. data/fastlane/swift/ScanfileProtocol.swift +1 -1
  78. data/fastlane/swift/Screengrabfile.swift +1 -1
  79. data/fastlane/swift/ScreengrabfileProtocol.swift +1 -1
  80. data/fastlane/swift/Snapshotfile.swift +1 -1
  81. data/fastlane/swift/SnapshotfileProtocol.swift +1 -1
  82. data/fastlane/swift/main.swift +1 -1
  83. data/fastlane_core/lib/fastlane_core/cert_checker.rb +40 -76
  84. data/fastlane_core/lib/fastlane_core/command_executor.rb +128 -7
  85. data/fastlane_core/lib/fastlane_core/configuration/config_item.rb +1 -1
  86. data/fastlane_core/lib/fastlane_core/configuration/configuration_file.rb +1 -1
  87. data/fastlane_core/lib/fastlane_core/device_manager.rb +14 -5
  88. data/fastlane_core/lib/fastlane_core/fastlane_pty.rb +25 -10
  89. data/fastlane_core/lib/fastlane_core/helper.rb +26 -2
  90. data/fastlane_core/lib/fastlane_core/ios_app_identifier_guesser.rb +1 -1
  91. data/fastlane_core/lib/fastlane_core/itunes_transporter.rb +41 -22
  92. data/fastlane_core/lib/fastlane_core/keychain_importer.rb +48 -71
  93. data/fastlane_core/lib/fastlane_core/pkg_file_analyser.rb +5 -1
  94. data/fastlane_core/lib/fastlane_core/print_table.rb +1 -1
  95. data/fastlane_core/lib/fastlane_core/queue_worker.rb +0 -2
  96. data/fastlane_core/lib/fastlane_core/stored_passwords.rb +29 -0
  97. data/fastlane_core/lib/fastlane_core/string_filters.rb +1 -2
  98. data/fastlane_core/lib/fastlane_core/ui/fastlane_runner.rb +8 -4
  99. data/fastlane_core/lib/fastlane_core/ui/github_issue_inspector_reporter.rb +2 -2
  100. data/fastlane_core/lib/fastlane_core/ui/implementations/shell.rb +1 -1
  101. data/frameit/lib/frameit/device_types.rb +11 -4
  102. data/frameit/lib/frameit/editor.rb +31 -12
  103. data/frameit/lib/frameit/frame_downloader.rb +4 -1
  104. data/gym/lib/gym/detect_values.rb +10 -10
  105. data/gym/lib/gym/options.rb +1 -7
  106. data/gym/lib/gym/runner.rb +6 -1
  107. data/match/lib/match/encryption/encryption.rb +6 -1
  108. data/match/lib/match/encryption/openssl.rb +8 -3
  109. data/match/lib/match/portal_fetcher.rb +12 -6
  110. data/match/lib/match/runner.rb +4 -1
  111. data/match/lib/match/storage/gitlab/secure_file.rb +2 -1
  112. data/match/lib/match/storage/google_cloud_storage.rb +1 -1
  113. data/match/lib/match/storage/interface.rb +10 -0
  114. data/match/lib/match/storage/s3_storage.rb +1 -1
  115. data/pem/lib/pem/manager.rb +3 -3
  116. data/precheck/lib/precheck/runner.rb +4 -2
  117. data/scan/lib/scan/detect_values.rb +0 -1
  118. data/scan/lib/scan/runner.rb +1 -0
  119. data/sigh/lib/assets/resign.sh +10 -3
  120. data/sigh/lib/sigh/manager.rb +5 -1
  121. data/sigh/lib/sigh/resign.rb +5 -21
  122. data/snapshot/lib/snapshot/reset_simulators.rb +5 -2
  123. data/snapshot/lib/snapshot/runner.rb +0 -1
  124. data/spaceship/lib/spaceship/base.rb +1 -1
  125. data/spaceship/lib/spaceship/client.rb +13 -4
  126. data/spaceship/lib/spaceship/connect_api/api_client.rb +12 -14
  127. data/spaceship/lib/spaceship/connect_api/models/bundle_id.rb +1 -1
  128. data/spaceship/lib/spaceship/connect_api/models/user.rb +7 -3
  129. data/spaceship/lib/spaceship/connect_api/testflight/testflight.rb +9 -11
  130. data/spaceship/lib/spaceship/connect_api/token.rb +21 -1
  131. data/spaceship/lib/spaceship/connect_api/tunes/tunes.rb +3 -1
  132. data/spaceship/lib/spaceship/helper/plist_middleware.rb +2 -2
  133. data/spaceship/lib/spaceship/portal/portal_client.rb +8 -8
  134. data/spaceship/lib/spaceship/test_flight/client.rb +1 -5
  135. data/supply/lib/supply/client.rb +1 -1
  136. data/supply/lib/supply/options.rb +6 -0
  137. data/supply/lib/supply/uploader.rb +28 -2
  138. metadata +28 -25
  139. data/fastlane/lib/fastlane/actions/hockey.rb +0 -400
  140. data/fastlane/lib/fastlane/actions/typetalk.rb +0 -93
@@ -5,6 +5,7 @@ module Fastlane
5
5
  require 'tmpdir'
6
6
 
7
7
  find_binary_path(params)
8
+ find_dsym_path(params)
8
9
  unless params[:app_id]
9
10
  find_gsp_path(params)
10
11
  find_api_token(params)
@@ -127,6 +128,11 @@ module Fastlane
127
128
  params[:binary_path] = File.expand_path(params[:binary_path])
128
129
  end
129
130
 
131
+ # Searched when the action runs rather than as the option's default, which is computed whenever the options are built
132
+ def self.find_dsym_path(params)
133
+ params[:dsym_path] ||= (Dir["./**/*.dSYM"] + Dir["./**/*.dSYM.zip"]).sort_by { |f| File.mtime(f) }.last
134
+ end
135
+
130
136
  #####################################################
131
137
  # @!group Documentation
132
138
  #####################################################
@@ -146,8 +152,8 @@ module Fastlane
146
152
  [
147
153
  FastlaneCore::ConfigItem.new(key: :dsym_path,
148
154
  env_name: "FL_UPLOAD_SYMBOLS_TO_CRASHLYTICS_DSYM_PATH",
149
- description: "Path to the DSYM file or zip to upload",
150
- default_value: ENV[SharedValues::DSYM_OUTPUT_PATH.to_s] || (Dir["./**/*.dSYM"] + Dir["./**/*.dSYM.zip"]).sort_by { |f| File.mtime(f) }.last,
155
+ description: "Path to the DSYM file or zip to upload. Defaults to the dSYM of the last build_app, or else the most recent .dSYM or .dSYM.zip under the current directory",
156
+ default_value: ENV[SharedValues::DSYM_OUTPUT_PATH.to_s],
151
157
  default_value_dynamic: true,
152
158
  optional: true,
153
159
  verify_block: proc do |value|
@@ -18,7 +18,8 @@ module Fastlane
18
18
  end
19
19
 
20
20
  def self.app_path(params, dir)
21
- build_path = params[:ipa_path] || params[:build_path] || Actions.lane_context[SharedValues::IPA_OUTPUT_PATH] || ''
21
+ build_path = params[:ipa_path] || params[:build_path] || Actions.lane_context[SharedValues::IPA_OUTPUT_PATH]
22
+ UI.user_error!("Pass :ipa_path or :build_path, or run build_app before verify_build") unless build_path
22
23
  UI.user_error!("Unable to find file '#{build_path}'") unless File.exist?(build_path)
23
24
  build_path = File.expand_path(build_path)
24
25
 
@@ -31,7 +31,8 @@ module Fastlane
31
31
  def self.value(key, target)
32
32
  command = ["pod", "keys", "get", key]
33
33
  command << target unless target.to_s.empty?
34
- value = `#{command.shelljoin}`
34
+ # The value is a secret: run never prints the output unless asked, and keeps stderr out of it
35
+ value = FastlaneCore::CommandExecutor.run(*command, separate_stderr: true, print_command: false)
35
36
  value.split("]").last.strip
36
37
  end
37
38
 
@@ -195,7 +195,7 @@ module Fastlane
195
195
  if testing
196
196
  if params[:reports]
197
197
  # New report options format
198
- reports = params[:reports].reduce("") do |arguments, report|
198
+ reports = params[:reports].reduce(+"") do |arguments, report|
199
199
  report_string = "--report #{report[:report]}"
200
200
 
201
201
  if report[:output]
@@ -16,6 +16,10 @@ module Fastlane
16
16
  ARGV.include?("init")
17
17
  end
18
18
 
19
+ def running_json_command?
20
+ ARGV.first == "lanes" && (ARGV.include?("-j") || ARGV.include?("--json"))
21
+ end
22
+
19
23
  def utf8_locale?
20
24
  (ENV['LANG'] || "").end_with?("UTF-8", "utf8") || (ENV['LC_ALL'] || "").end_with?("UTF-8", "utf8") || (FastlaneCore::CommandExecutor.which('locale') && `locale charmap`.strip == "UTF-8")
21
25
  end
@@ -23,6 +27,9 @@ module Fastlane
23
27
  def take_off
24
28
  before_import_time = Time.now
25
29
 
30
+ # JSON commands print the JSON on STDOUT; logs and prompts go to stderr.
31
+ $stdout = $stderr if running_json_command?
32
+
26
33
  if ENV["FASTLANE_DISABLE_ANIMATION"].nil?
27
34
  # Usually in the fastlane code base we use
28
35
  #
@@ -144,11 +144,16 @@ module Fastlane
144
144
  c.option('-s', '--stay_alive', 'Keeps socket server up even after error or disconnects, requires CTRL-C to kill.')
145
145
  c.option('-c seconds', '--connection_timeout', 'Sets connection established timeout')
146
146
  c.option('-p port', '--port', "Sets the port on localhost for the socket connection")
147
+ c.option('--token_file path', "File holding the token every command must carry (default: FASTLANE_SOCKET_SERVER_TOKEN_FILE)")
147
148
  c.action do |args, options|
148
149
  default_connection_timeout = 5
149
150
  stay_alive = options.stay_alive || false
150
151
  connection_timeout = options.connection_timeout || default_connection_timeout
151
152
  port = options.port || 2000
153
+ token_file = options.token_file || ENV["FASTLANE_SOCKET_SERVER_TOKEN_FILE"]
154
+ token = File.read(token_file).strip if token_file
155
+ UI.user_error!("The token file #{token_file} is empty") if token_file && token.empty?
156
+ UI.important("No --token_file given: any local process that connects first can run actions") unless token
152
157
 
153
158
  if stay_alive && options.connection_timeout.nil?
154
159
  UI.important("stay_alive is set, but the connection timeout is not, this will give you #{default_connection_timeout} seconds to (re)connect")
@@ -162,7 +167,8 @@ module Fastlane
162
167
  command_executor: command_executor,
163
168
  connection_timeout: connection_timeout,
164
169
  stay_alive: stay_alive,
165
- port: port
170
+ port: port,
171
+ token: token
166
172
  )
167
173
  result = server.start
168
174
  UI.success("Result: #{result}") if result
@@ -20,7 +20,7 @@ module Fastlane
20
20
  def self.get
21
21
  UI.important("Generating fastlane environment output, this might take a few seconds...")
22
22
  require "fastlane/markdown_table_formatter"
23
- env_output = ""
23
+ env_output = +""
24
24
  env_output << print_system_environment
25
25
  env_output << print_system_locale
26
26
  env_output << print_fastlane_files
@@ -33,7 +33,7 @@ module Fastlane
33
33
  status = (env_output.include?("🚫") ? "🚫" : "✅")
34
34
  env_header = "<details><summary>#{status} fastlane environment #{status}</summary>\n\n"
35
35
  env_tail = "</details>"
36
- final_output = ""
36
+ final_output = +""
37
37
 
38
38
  if FastlaneCore::Globals.captured_output?
39
39
  final_output << "### Captured Output\n\n"
@@ -50,7 +50,7 @@ module Fastlane
50
50
  end
51
51
 
52
52
  def self.print_loaded_plugins
53
- env_output = "### Loaded fastlane plugins:\n"
53
+ env_output = +"### Loaded fastlane plugins:\n"
54
54
  env_output << "\n"
55
55
  plugin_manager = Fastlane::PluginManager.new
56
56
  plugin_manager.load_plugins(print_table: false)
@@ -58,7 +58,7 @@ module Fastlane
58
58
  if plugin_manager.available_plugins.length <= 0
59
59
  env_output << "**No plugins Loaded**\n"
60
60
  else
61
- table = ""
61
+ table = +""
62
62
  table << "| Plugin | Version | Update-Status |\n"
63
63
  table << "|--------|---------|\n"
64
64
  plugin_manager.available_plugins.each do |plugin|
@@ -96,8 +96,8 @@ module Fastlane
96
96
 
97
97
  def self.print_loaded_fastlane_gems
98
98
  # fastlanes internal gems
99
- env_output = "### fastlane gems\n\n"
100
- table = ""
99
+ env_output = +"### fastlane gems\n\n"
100
+ table = +""
101
101
  table << "| Gem | Version | Update-Status |\n"
102
102
  table << "|-----|---------|------------|\n"
103
103
  fastlane_tools = Fastlane::TOOLS + [:fastlane_core, :credentials_manager]
@@ -128,10 +128,10 @@ module Fastlane
128
128
  end
129
129
 
130
130
  def self.print_loaded_gems
131
- env_output = "<details>"
131
+ env_output = +"<details>"
132
132
  env_output << "<summary><b>Loaded gems</b></summary>\n\n"
133
133
 
134
- table = "| Gem | Version |\n"
134
+ table = +"| Gem | Version |\n"
135
135
  table << "|-----|---------|\n"
136
136
  gems_to_check.each do |current_gem|
137
137
  unless Fastlane::TOOLS.include?(current_gem.name.to_sym)
@@ -146,9 +146,9 @@ module Fastlane
146
146
  end
147
147
 
148
148
  def self.print_system_locale
149
- env_output = "### System Locale\n\n"
149
+ env_output = +"### System Locale\n\n"
150
150
  found_one = false
151
- env_table = ""
151
+ env_table = +""
152
152
  ["LANG", "LC_ALL", "LANGUAGE"].each do |e|
153
153
  env_icon = "🚫"
154
154
  if ENV[e] && ENV[e].end_with?("UTF-8")
@@ -161,11 +161,11 @@ module Fastlane
161
161
  env_table << "| #{e} | #{ENV[e]} | #{env_icon} |\n"
162
162
  end
163
163
  if !found_one
164
- table = "| Error |\n"
164
+ table = +"| Error |\n"
165
165
  table << "|-----|\n"
166
166
  table << "| No Locale with UTF8 found 🚫|\n"
167
167
  else
168
- table = "| Variable | Value | |\n"
168
+ table = +"| Variable | Value | |\n"
169
169
  table << "|-----|---------|----|\n"
170
170
  table << env_table
171
171
  end
@@ -177,7 +177,7 @@ module Fastlane
177
177
  def self.print_system_environment
178
178
  require "openssl"
179
179
 
180
- env_output = "### Stack\n\n"
180
+ env_output = +"### Stack\n\n"
181
181
  product, version, build = "Unknown"
182
182
  os_version = "UNKNOWN"
183
183
 
@@ -250,7 +250,7 @@ module Fastlane
250
250
  end
251
251
 
252
252
  def self.print_fastlane_files
253
- env_output = "### fastlane files:\n\n"
253
+ env_output = +"### fastlane files:\n\n"
254
254
 
255
255
  {
256
256
  "Fastfile" => FastlaneCore::FastlaneFolder.fastfile_path,
@@ -206,23 +206,23 @@ module Fastlane
206
206
 
207
207
  raise ArgumentError, "sh requires :command keyword in argument" if command.nil?
208
208
  log = options[:log].nil? ? true : options[:log]
209
- FastFile.sh(*command, step_name: options[:step_name], log: log, error_callback: options[:error_callback], &b)
209
+ FastFile.sh(*command, step_name: options[:step_name], log: log, error_callback: options[:error_callback], stdin: options[:stdin], separate_stderr: options.fetch(:separate_stderr, false), chdir: options[:chdir], &b)
210
210
  elsif args.count != 1 && args.last.kind_of?(Hash)
211
211
  new_args = args.dup
212
212
  options = new_args.pop
213
213
  log = options[:log].nil? ? true : options[:log]
214
- FastFile.sh(*new_args, step_name: options[:step_name], log: log, error_callback: options[:error_callback], &b)
214
+ FastFile.sh(*new_args, step_name: options[:step_name], log: log, error_callback: options[:error_callback], stdin: options[:stdin], separate_stderr: options.fetch(:separate_stderr, false), chdir: options[:chdir], &b)
215
215
  else
216
216
  FastFile.sh(*args, &b)
217
217
  end
218
218
  end
219
219
 
220
- def self.sh(*command, step_name: nil, log: true, error_callback: nil, &b)
220
+ def self.sh(*command, step_name: nil, log: true, error_callback: nil, stdin: nil, separate_stderr: false, chdir: nil, &b)
221
221
  command_header = step_name
222
222
  command_header ||= log ? Actions.shell_command_from_args(*command) : "shell command"
223
223
 
224
224
  Actions.execute_action(command_header) do
225
- Actions.sh_no_action(*command, log: log, error_callback: error_callback, &b)
225
+ Actions.sh_no_action(*command, log: log, error_callback: error_callback, stdin: stdin, separate_stderr: separate_stderr, chdir: chdir, &b)
226
226
  end
227
227
  end
228
228
 
@@ -407,6 +407,37 @@ module Fastlane
407
407
  end
408
408
  end
409
409
 
410
+ # @param gem_name [String] The name of the gem to import
411
+ # @param paths [Array] the list of pattern to expand matching fastfiles to import
412
+ def import_from_gem(gem_name: nil, paths: ["fastlane/Fastfile*"])
413
+ UI.user_error!("Please pass a gem name to the `import_from_gem` action") if gem_name.to_s.length == 0
414
+
415
+ Actions.execute_action('import_from_gem') do
416
+ action_launched('import_from_gem')
417
+
418
+ UI.message("Importing from gem: #{gem_name}")
419
+ rubygem = Bundler.rubygems.find_name(gem_name).first
420
+ UI.user_error!("Couldn't find gem '#{gem_name}', make sure it is in your Gemfile") unless rubygem
421
+
422
+ # Before its Fastfiles, whose lanes may call the actions of the plugins the gem depends on
423
+ Fastlane.plugin_manager.load_plugins_required_by(gem_name)
424
+
425
+ gem_path = rubygem.full_gem_path
426
+
427
+ fastfiles = paths.map { |r| Dir.glob("#{gem_path}/#{r}") }.flatten
428
+ UI.user_error!("No Fastfile found in gem '#{gem_name}' matching #{paths.join(', ')}") if fastfiles.empty?
429
+
430
+ return_value = fastfiles.map do |file_path|
431
+ UI.message("Importing fastfile from #{file_path}")
432
+ import(file_path)
433
+ end
434
+
435
+ action_completed('import_from_gem', status: FastlaneCore::ActionCompletionStatus::SUCCESS)
436
+
437
+ return_value
438
+ end
439
+ end
440
+
410
441
  #####################################################
411
442
  # @!group Versioning helpers
412
443
  #####################################################
@@ -8,27 +8,31 @@ module Fastlane
8
8
  # When running this in tests, it will return the actual command instead of executing it
9
9
  # @param log [Boolean] should fastlane print out the executed command
10
10
  # @param error_callback [Block] a callback invoked with the command output if there is a non-zero exit status
11
- # @param stdin [String] data written to the command's standard input, which is then closed; it is never printed
12
- def self.sh(*command, log: true, error_callback: nil, stdin: nil, &b)
13
- sh_control_output(*command, print_command: log, print_command_output: log, error_callback: error_callback, stdin: stdin, &b)
11
+ # @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
12
+ # @param separate_stderr [Boolean] return stdout only; stderr goes to the error message and the error_callback
13
+ # @param chdir [String] directory the command runs in; fastlane's own stays as it is
14
+ def self.sh(*command, log: true, error_callback: nil, stdin: nil, separate_stderr: false, chdir: nil, &b)
15
+ sh_control_output(*command, print_command: log, print_command_output: log, error_callback: error_callback, stdin: stdin, separate_stderr: separate_stderr, chdir: chdir, &b)
14
16
  end
15
17
 
16
- def self.sh_no_action(*command, log: true, error_callback: nil, stdin: nil, &b)
17
- sh_control_output(*command, print_command: log, print_command_output: log, error_callback: error_callback, stdin: stdin, &b)
18
+ def self.sh_no_action(*command, log: true, error_callback: nil, stdin: nil, separate_stderr: false, chdir: nil, &b)
19
+ sh_control_output(*command, print_command: log, print_command_output: log, error_callback: error_callback, stdin: stdin, separate_stderr: separate_stderr, chdir: chdir, &b)
18
20
  end
19
21
 
20
22
  # @param command The command to be executed (variadic)
21
23
  # @param print_command [Boolean] Should we print the command that's being executed
22
24
  # @param print_command_output [Boolean] Should we print the command output during execution
23
25
  # @param error_callback [Block] A block that's called if the command exits with a non-zero status
26
+ # @param separate_stderr [Boolean] Return stdout only, and give stderr to the error message and the error_callback
24
27
  # @yield [status, result, cmd] The return status of the command, all output from the command and an equivalent shell command
25
28
  # @yieldparam [Process::Status] status A Process::Status indicating the status of the completed command
26
- # @yieldparam [String] result The complete output to stdout and stderr of the completed command
29
+ # @yieldparam [String] result The complete output to stdout and stderr of the completed command (stdout only with separate_stderr)
27
30
  # @yieldparam [String] cmd A shell command equivalent to the arguments passed
28
31
  # rubocop: disable Metrics/PerceivedComplexity
29
- def self.sh_control_output(*command, print_command: true, print_command_output: true, error_callback: nil, stdin: nil)
32
+ def self.sh_control_output(*command, print_command: true, print_command_output: true, error_callback: nil, stdin: nil, separate_stderr: false, chdir: nil)
30
33
  print_command = print_command_output = true if $troubleshoot
31
34
  # Set the encoding first, the user might have set it wrong
35
+ # Not a duplicate of CommandExecutor.collect's: this one also covers the block and the error_callback
32
36
  previous_encoding = [Encoding.default_external, Encoding.default_internal]
33
37
  Encoding.default_external = Encoding::UTF_8
34
38
  Encoding.default_internal = Encoding::UTF_8
@@ -41,42 +45,14 @@ module Fastlane
41
45
  shell_command = shell_command_from_args(*command)
42
46
  UI.command(shell_command) if print_command
43
47
 
44
- result = ''
48
+ result = +''
45
49
  exit_status = nil
46
50
  if FastlaneCore::Helper.sh_enabled?
47
- # The argument list is passed directly to Open3.popen2e, which
48
- # handles the variadic argument list in the same way as Kernel#spawn.
49
- # (http://ruby-doc.org/core-2.4.2/Kernel.html#method-i-spawn) or
50
- # Process.spawn (http://ruby-doc.org/core-2.4.2/Process.html#method-c-spawn).
51
- #
52
- # sh "ls -la /Applications/Xcode\ 7.3.1.app"
53
- # sh "ls", "-la", "/Applications/Xcode 7.3.1.app"
54
- # sh({ "FOO" => "Hello" }, "echo $FOO")
55
- sanitized_output = false
56
- Open3.popen2e(*command) do |command_stdin, io, thread|
57
- # From a thread, so a command that writes a lot before reading its input cannot block on a full pipe
58
- writer = stdin && Thread.new do
59
- command_stdin.write(stdin)
60
- rescue Errno::EPIPE
61
- # The command exited without reading all of it; its exit status says what happened
62
- ensure
63
- command_stdin.close
64
- end
65
- io.sync = true
66
- io.each do |line|
67
- if print_command_output
68
- # Ensure the string being stripped is in valid UTF-8 format; Otherwise warn at the end
69
- text = line.encode('UTF-8', invalid: :replace)
70
- UI.command_output(text.strip)
71
- sanitized_output = true if text != line
72
- end
73
- result << line
74
- end
75
- exit_status = thread.value
76
- writer&.join
77
- end
78
-
79
- UI.important("Command output wasn't valid UTF-8 and was sanitized. Please report the issue.") if sanitized_output
51
+ # The command forms are documented on CommandExecutor.collect
52
+ collected = FastlaneCore::CommandExecutor.collect(*command, stdin: stdin, separate_stderr: separate_stderr, print_output: print_command_output, chdir: chdir)
53
+ result = collected.output
54
+ errors = collected.errors
55
+ exit_status = collected.status
80
56
 
81
57
  # Checking Process::Status#exitstatus instead of #success? makes for more
82
58
  # testable code. (Tests mock exitstatus only.) This is also consistent
@@ -85,9 +61,15 @@ module Fastlane
85
61
  if exit_status.exitstatus != 0
86
62
  # Due to some output and build systems having 30-80k lines of output.
87
63
  # We will truncate what we will show to recap the failure.
88
- truncated_msg = result.length > 500 ? result[-500..-1] : result
89
-
90
- message = if print_command
64
+ failure_output = errors || result
65
+ truncated_msg = failure_output.length > 500 ? failure_output[-500..-1] : failure_output
66
+
67
+ signal = FastlaneCore::FastlanePty.signal_name(exit_status)
68
+ message = if signal && print_command
69
+ "Command '#{shell_command}' was killed by #{signal}.\n"
70
+ elsif signal
71
+ "Shell command was killed by #{signal}.\n"
72
+ elsif print_command
91
73
  "Exit status of command '#{shell_command}' was #{exit_status.exitstatus} instead of 0.\n"
92
74
  else
93
75
  "Shell command exited with exit status #{exit_status.exitstatus} instead of 0.\n"
@@ -97,7 +79,7 @@ module Fastlane
97
79
  if error_callback || block_given?
98
80
  UI.error(message)
99
81
  # block notified below, on success or failure
100
- error_callback && error_callback.call(result)
82
+ error_callback && error_callback.call(failure_output)
101
83
  else
102
84
  UI.shell_error!(message)
103
85
  end
@@ -103,7 +103,7 @@ module Fastlane
103
103
  end
104
104
 
105
105
  def self.output_json(path)
106
- puts(JSON.pretty_generate(self.generate_json(path)))
106
+ STDOUT.puts(JSON.pretty_generate(self.generate_json(path)))
107
107
  end
108
108
 
109
109
  # Returns a hash
@@ -185,7 +185,7 @@ module Fastlane
185
185
  puts("Installing plugin dependencies...")
186
186
  ensure_plugins_attached!
187
187
  with_clean_bundler_env do
188
- cmd = "bundle install"
188
+ cmd = +"bundle install"
189
189
  cmd << " --quiet" unless FastlaneCore::Globals.verbose?
190
190
  cmd << " && bundle exec fastlane generate_swift" if FastlaneCore::FastlaneFolder.swift?
191
191
  cmd << " && echo 'Successfully installed plugins'"
@@ -204,7 +204,7 @@ module Fastlane
204
204
  UI.user_error!("No plugins are installed")
205
205
  end
206
206
  with_clean_bundler_env do
207
- cmd = "bundle update"
207
+ cmd = +"bundle update"
208
208
  cmd << " #{plugins.join(' ')}"
209
209
  cmd << " --quiet" unless FastlaneCore::Globals.verbose?
210
210
  cmd << " && bundle exec fastlane generate_swift" if FastlaneCore::FastlaneFolder.swift?
@@ -17,8 +17,6 @@ AllCops:
17
17
  - "**/lib/assets/DefaultFastfileTemplate"
18
18
  - "**/lib/assets/MatchfileTemplate"
19
19
  - "**/*.provisionprofile"
20
- Lint/ErbNewArguments:
21
- Enabled: false
22
20
  Style/HashSyntax:
23
21
  EnforcedShorthandSyntax: either
24
22
  Naming/BlockForwarding:
@@ -135,6 +135,7 @@ module Fastlane
135
135
  if class_ref.respond_to?(:alias_used)
136
136
  orig_action = method_sym.to_s
137
137
  arguments = [{}] if arguments.empty?
138
+ arguments[0] = arguments.first.dup if arguments.first.kind_of?(String) # alias_used may change it, and it can be a literal from the Fastfile
138
139
  class_ref.alias_used(orig_action, arguments.first)
139
140
  end
140
141
  end
@@ -151,13 +152,10 @@ module Fastlane
151
152
  # built-in actions
152
153
  end
153
154
 
155
+ # Both lookups above only return classes that respond to `run`
154
156
  if class_ref
155
- if class_ref.respond_to?(:run)
156
- # Action is available, now execute it
157
- return self.execute_action(method_sym, class_ref, arguments, custom_dir: custom_dir, from_action: from_action)
158
- else
159
- UI.user_error!("Action '#{method_sym}' of class '#{class_name}' was found, but has no `run` method.")
160
- end
157
+ # Action is available, now execute it
158
+ return self.execute_action(method_sym, class_ref, arguments, custom_dir: custom_dir, from_action: from_action)
161
159
  end
162
160
 
163
161
  # No lane, no action, let's at least show the correct error message
@@ -3,6 +3,7 @@ require 'fastlane/server/command_parser.rb'
3
3
  require 'fastlane/server/json_return_value_processor.rb'
4
4
  require 'socket'
5
5
  require 'json'
6
+ require 'openssl'
6
7
 
7
8
  module Fastlane
8
9
  class SocketServer
@@ -20,7 +21,8 @@ module Fastlane
20
21
  return_value_processor: nil,
21
22
  connection_timeout: 5,
22
23
  stay_alive: false,
23
- port: 2000
24
+ port: 2000,
25
+ token: nil
24
26
  )
25
27
  if return_value_processor.nil?
26
28
  return_value_processor = JSONReturnValueProcessor.new
@@ -31,6 +33,8 @@ module Fastlane
31
33
  @connection_timeout = connection_timeout.to_i
32
34
  @stay_alive = stay_alive
33
35
  @port = port.to_i
36
+ # When set, every command must carry it: the runner reads it from a file only this user can read
37
+ @token = token
34
38
  end
35
39
 
36
40
  # this is the public API, don't call anything else
@@ -78,6 +82,11 @@ module Fastlane
78
82
  end
79
83
 
80
84
  def parse_and_execute_command(command_string: nil)
85
+ unless token_matches?(command_string)
86
+ UI.error("Refusing a command without this run's token: it does not come from the FastlaneRunner fastlane started")
87
+ return COMMAND_EXECUTION_STATE[:error]
88
+ end
89
+
81
90
  command = CommandParser.parse(json: command_string)
82
91
  case command
83
92
  when ControlCommand
@@ -137,15 +146,17 @@ module Fastlane
137
146
  end
138
147
 
139
148
  def listen
140
- @server = TCPServer.open('localhost', @port) # Socket to listen on port 2000
141
- UI.verbose("Waiting for #{@connection_timeout} seconds for a connection from FastlaneRunner")
149
+ @servers = listening_sockets
150
+ @port = @servers.first.local_address.ip_port
151
+ UI.verbose("Waiting for #{@connection_timeout} seconds for a connection from FastlaneRunner on port #{@port}")
142
152
 
143
- # set thread local to ready so we can check it
153
+ # set thread locals so the caller can tell the runner where to connect
154
+ Thread.current[:port] = @port
144
155
  Thread.current[:ready] = true
145
156
  @client = nil
146
157
  begin
147
158
  Timeout.timeout(@connection_timeout) do
148
- @client = @server.accept # Wait for a client to connect
159
+ @client = accept_first_connection
149
160
  end
150
161
  rescue Timeout::Error
151
162
  UI.user_error!("fastlane failed to receive a connection from the FastlaneRunner binary after #{@connection_timeout} seconds, shutting down")
@@ -166,8 +177,47 @@ module Fastlane
166
177
  @client.close
167
178
  @client = nil
168
179
 
169
- @server.close
170
- @server = nil
180
+ close_servers
181
+ end
182
+
183
+ # A socket on every address localhost resolves to. The runner connects to
184
+ # `localhost` and tries those addresses in turn, so another process listening
185
+ # on one this server did not take would receive its commands.
186
+ def listening_sockets
187
+ # Port 0: a free port, the same on every address
188
+ return Socket.tcp_server_sockets('localhost', 0) if @port.zero?
189
+
190
+ sockets = []
191
+ Addrinfo.getaddrinfo('localhost', @port, nil, :STREAM).uniq(&:ip_address).each do |address|
192
+ sockets << address.listen
193
+ rescue SystemCallError => e
194
+ sockets.each(&:close)
195
+ UI.user_error!("fastlane could not listen on #{address.inspect_sockaddr} for the FastlaneRunner binary: #{e.message}")
196
+ end
197
+ sockets
198
+ end
199
+
200
+ # The first connection on any of the sockets. They are closed once it is
201
+ # accepted, so nothing else can connect while the runner is talking to us.
202
+ def accept_first_connection
203
+ ready, = IO.select(@servers)
204
+ ready.first.accept.first
205
+ ensure
206
+ close_servers
207
+ end
208
+
209
+ def token_matches?(command_string)
210
+ return true if @token.nil?
211
+
212
+ token = JSON.parse(command_string)['token']
213
+ token.kind_of?(String) && OpenSSL.secure_compare(token, @token)
214
+ rescue JSON::ParserError, TypeError
215
+ false
216
+ end
217
+
218
+ def close_servers
219
+ (@servers || []).each { |server| server.close unless server.closed? }
220
+ @servers = nil
171
221
  end
172
222
 
173
223
  # record fastlane action command and then execute it
@@ -56,13 +56,13 @@ module Fastlane
56
56
  def class_ref_for_action(named: nil)
57
57
  class_ref = Actions.action_class_ref(named)
58
58
  unless class_ref
59
- if Fastlane::Actions.formerly_bundled_actions.include?(action)
59
+ if Fastlane::Actions.formerly_bundled_actions.include?(named)
60
60
  # This was a formerly bundled action which is now a plugin.
61
61
  UI.verbose(caller.join("\n"))
62
- UI.user_error!("The action '#{action}' is no longer bundled with fastlane. You can install it using `fastlane add_plugin #{action}`")
62
+ UI.user_error!("The action '#{named}' is no longer bundled with fastlane. You can install it using `fastlane add_plugin #{named}`")
63
63
  else
64
- Fastlane::ActionsList.print_suggestions(action)
65
- UI.user_error!("Action '#{action}' not available, run `fastlane actions` to get a full list")
64
+ Fastlane::ActionsList.print_suggestions(named)
65
+ UI.user_error!("Action '#{named}' not available, run `fastlane actions` to get a full list")
66
66
  end
67
67
  end
68
68
 
@@ -24,7 +24,7 @@ module Fastlane
24
24
 
25
25
  super()
26
26
 
27
- self.actions_not_supported = ["import", "import_from_git"].to_set
27
+ self.actions_not_supported = ["import", "import_from_git", "import_from_gem"].to_set
28
28
  self.action_options_to_ignore = {
29
29
 
30
30
  "precheck" => [
@@ -83,7 +83,7 @@ module Fastlane
83
83
  available_actions << action.action_name unless available_external_actions.include?(action)
84
84
  end
85
85
 
86
- self.actions_not_supported = (["import", "import_from_git"] + available_actions).to_set
86
+ self.actions_not_supported = (["import", "import_from_git", "import_from_gem"] + available_actions).to_set
87
87
  self.action_options_to_ignore = {}
88
88
  end
89
89
  end
@@ -113,7 +113,7 @@ module Fastlane
113
113
  available_actions << action.action_name unless available_plugins.include?(action)
114
114
  end
115
115
 
116
- self.actions_not_supported = (["import", "import_from_git"] + available_actions).to_set
116
+ self.actions_not_supported = (["import", "import_from_git", "import_from_gem"] + available_actions).to_set
117
117
  self.action_options_to_ignore = {}
118
118
  end
119
119
  end