class Fastlane::Actions::MultiScanAction

Public Class Methods

authors() click to toggle source
# File lib/fastlane/plugin/retry_tests/actions/multi_scan.rb, line 137
def self.authors
  #Adapted from the "fastlane-plugin-test_center" plugin by:
  ["lyndsey-ferguson/@lyndseydf"]
end
available_options() click to toggle source
# File lib/fastlane/plugin/retry_tests/actions/multi_scan.rb, line 124
def self.available_options
  scan_options + [
    FastlaneCore::ConfigItem.new(
      key: :try_count,
      env_name: "FL_MULTI_SCAN_TRY_COUNT",
      description: "The number of times to retry running tests via scan",
      type: Integer,
      is_string: false,
      default_value: 1
    )
  ]
end
config_has_junit_report(config) click to toggle source
# File lib/fastlane/plugin/retry_tests/actions/multi_scan.rb, line 58
def self.config_has_junit_report(config)
  output_types = config.fetch(:output_types, '').to_s.split(',')
  output_filenames = config.fetch(:output_files, '').to_s.split(',')

  output_type_file_count_match = output_types.size == output_filenames.size
  output_types.include?('junit') && (output_type_file_count_match || config[:custom_report_file_name].to_s.strip.length > 0)
end
config_with_junit_report(config) click to toggle source
# File lib/fastlane/plugin/retry_tests/actions/multi_scan.rb, line 78
def self.config_with_junit_report(config)
  return config if config_has_junit_report(config)

  if config[:output_types].to_s.strip.empty? || config[:custom_report_file_name]
    config[:custom_report_file_name] ||= 'report.xml'
    config[:output_types] = 'junit'
  elsif config[:output_types].strip == 'junit' && config[:output_files].to_s.strip.empty?
    config[:custom_report_file_name] ||= 'report.xml'
  elsif !config[:output_types].split(',').include?('junit')
    config[:output_types] << ',junit'
    config[:output_files] << ',report.xml'
  elsif config[:output_files].nil?
    config[:output_files] = config[:output_types].split(',').map { |type| "report.#{type}" }.join(',')
  end
  config
end
config_with_retry(config, count) click to toggle source
# File lib/fastlane/plugin/retry_tests/actions/multi_scan.rb, line 66
def self.config_with_retry(config, count)
  folder = get_folder_root(config[:result_bundle])
  config[:result_bundle] = (folder + count.to_s)
  config[:output_directory] = (folder + count.to_s)
  config
end
description() click to toggle source

@!group Documentation

# File lib/fastlane/plugin/retry_tests/actions/multi_scan.rb, line 112
def self.description
  "Uses scan to run Xcode tests a given number of times: only re-testing failing tests."
end
details() click to toggle source
# File lib/fastlane/plugin/retry_tests/actions/multi_scan.rb, line 116
def self.details
  "Use this action to run your tests if you have fragile tests that fail sporadically."
end
get_folder_root(folder) click to toggle source
# File lib/fastlane/plugin/retry_tests/actions/multi_scan.rb, line 73
def self.get_folder_root(folder)
  folder = folder.gsub(/ *\d+$/, '')
  folder
end
is_supported?(platform) click to toggle source
# File lib/fastlane/plugin/retry_tests/actions/multi_scan.rb, line 142
def self.is_supported?(platform)
  platform == :ios
end
junit_report_filename(config) click to toggle source
# File lib/fastlane/plugin/retry_tests/actions/multi_scan.rb, line 95
def self.junit_report_filename(config)
  report_filename = config[:custom_report_file_name]
  if report_filename.nil?
    junit_index = config[:output_types].split(',').find_index('junit')
    report_filename = config[:output_files].to_s.split(',')[junit_index]
  end
  report_filename
end
junit_report_filepath(config) click to toggle source
# File lib/fastlane/plugin/retry_tests/actions/multi_scan.rb, line 104
def self.junit_report_filepath(config)
  File.absolute_path(File.join(config[:output_directory], junit_report_filename(config)))
end
merge_reports(scan_options, final_report_path) click to toggle source
# File lib/fastlane/plugin/retry_tests/actions/multi_scan.rb, line 41
def self.merge_reports(scan_options, final_report_path)
  folder = get_folder_root(scan_options[:output_directory])
  report_files = Dir.glob("#{folder}*/#{scan_options[:scheme]}.test_result/1_Test/action_TestSummaries.plist")
  asset_files = Dir.glob("#{folder}*/#{scan_options[:scheme]}.test_result/1_Test/Attachments")
  log_files = Dir.glob("#{folder}*/#{scan_options[:scheme]}.test_result/1_Test/action.xcactivitylog")
  #Merge all reports, screenshots, and logs if there were retried tests
  if report_files.size > 1
    other_action.collate_junit_reports(
      scheme: scan_options[:scheme],
      reports: report_files,
      collated_report: final_report_path,
      assets: asset_files,
      logs: log_files,
    )
  end
end
run(params) click to toggle source
# File lib/fastlane/plugin/retry_tests/actions/multi_scan.rb, line 9
def self.run(params)

  try_count = 0
  scan_options = params.values.reject { |k| k == :try_count }
  final_report_path = scan_options[:result_bundle]
  unless Helper.test?
    FastlaneCore::PrintTable.print_values(
      config: params._values.reject { |k, v| scan_options.key?(k) },
      title: "Summary for multi_scan (test_center v#{Fastlane::TestCenter::VERSION})"
    )
  end

  scan_options = config_with_junit_report(scan_options)

  begin
    try_count += 1
    scan_options = config_with_retry(scan_options, try_count)
    config = FastlaneCore::Configuration.create(Fastlane::Actions::ScanAction.available_options, scan_options)
    Fastlane::Actions::ScanAction.run(config)
  rescue FastlaneCore::Interface::FastlaneTestFailure => e
    FastlaneCore::UI.verbose("Scan failed with error #{e}")
    #Retry for the specified number of times if there were failed tests
    if try_count < params[:try_count]
      report_filepath = junit_report_filepath(scan_options)
      failed_tests = other_action.tests_from_junit(junit: report_filepath)[:failed]
      scan_options[:only_testing] = failed_tests.map(&:shellescape)
      retry
    end
  end
  merge_reports(scan_options, final_report_path)
end
scan_options() click to toggle source
# File lib/fastlane/plugin/retry_tests/actions/multi_scan.rb, line 120
def self.scan_options
  ScanAction.available_options
end