Method: Fastlane::Runner#execute_action

Defined in:
fastlane/lib/fastlane/runner.rb

#execute_action(method_sym, class_ref, arguments, custom_dir: nil, from_action: false) ⇒ Object



218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# File 'fastlane/lib/fastlane/runner.rb', line 218

def execute_action(method_sym, class_ref, arguments, custom_dir: nil, from_action: false)
  if from_action == true
    custom_dir = "." # We preserve the directory from where the previous action was called from
  elsif custom_dir.nil?
    custom_dir ||= "." if Helper.test?
    custom_dir ||= ".."
  end

  verify_supported_os(method_sym, class_ref)

  begin
    Dir.chdir(custom_dir) do # go up from the fastlane folder, to the project folder
      # Removing step_name before its parsed into configurations
      args = arguments.kind_of?(Array) && arguments.first.kind_of?(Hash) ? arguments.first : {}
      step_name = args.delete(:step_name)

      # arguments is an array by default, containing an hash with the actual parameters
      # Since we usually just need the passed hash, we'll just use the first object if there is only one
      if arguments.count == 0
        configurations = ConfigurationHelper.parse(class_ref, {}) # no parameters => empty hash
      elsif arguments.count == 1 && arguments.first.kind_of?(Hash)
        configurations = ConfigurationHelper.parse(class_ref, arguments.first) # Correct configuration passed
      elsif !class_ref.available_options
        # This action does not use the new action format
        # Just passing the arguments to this method
        configurations = arguments
      else
        UI.user_error!("You have to call the integration like `#{method_sym}(key: \"value\")`. Run `fastlane action #{method_sym}` for all available keys. Please check out the current documentation on GitHub.")
      end

      # If another action is calling this action, we shouldn't show it in the summary
      # A nil value for action_name will hide it from the summary
      unless from_action
        action_name = step_name
        action_name ||= class_ref.method(:step_text).arity == 1 ? class_ref.step_text(configurations) : class_ref.step_text
      end

      Actions.execute_action(action_name) do
        if Fastlane::Actions.is_deprecated?(class_ref)
          puts("==========================================".deprecated)
          puts("This action (#{method_sym}) is deprecated".deprecated)
          puts(class_ref.deprecated_notes.to_s.remove_markdown.deprecated) if class_ref.deprecated_notes
          puts("==========================================\n".deprecated)
        end
        class_ref.runner = self # needed to call another action from an action
        return class_ref.run(configurations)
      end
    end
  rescue Interrupt => e
    raise e # reraise the interruption to avoid logging this as a crash
  rescue FastlaneCore::Interface::FastlaneCommonException => e # these are exceptions that we don't count as crashes
    raise e
  rescue FastlaneCore::Interface::FastlaneError => e # user_error!
    action_completed(method_sym.to_s, status: FastlaneCore::ActionCompletionStatus::USER_ERROR, exception: e)
    raise e
  rescue Exception => e # rubocop:disable Lint/RescueException
    # high chance this is actually FastlaneCore::Interface::FastlaneCrash, but can be anything else
    # Catches all exceptions, since some plugins might use system exits to get out
    action_completed(method_sym.to_s, status: FastlaneCore::ActionCompletionStatus::FAILED, exception: e)
    raise e
  end
end