Class: TestCenter::Helper::MultiScanManager::RetryingScan

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/test_center/helper/multi_scan_manager/retrying_scan.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ RetryingScan

Returns a new instance of RetryingScan.



5
6
7
8
# File 'lib/fastlane/plugin/test_center/helper/multi_scan_manager/retrying_scan.rb', line 5

def initialize(options = {})
  @options = options
  @retrying_scan_helper = RetryingScanHelper.new(@options)
end

Class Method Details

.run(options) ⇒ Object

:nocov:



58
59
60
# File 'lib/fastlane/plugin/test_center/helper/multi_scan_manager/retrying_scan.rb', line 58

def self.run(options)
  RetryingScan.new(options).run
end

Instance Method Details

#prepare_scan_configObject

:nocov:



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/fastlane/plugin/test_center/helper/multi_scan_manager/retrying_scan.rb', line 20

def prepare_scan_config
  # this allows multi_scan's `destination` option to be picked up by `scan`
  scan_config._values.delete(:device)
  ENV.delete('SCAN_DEVICE')
  scan_config._values.delete(:devices)
  ENV.delete('SCAN_DEVICES')
  # this prevents double -resultBundlePath args to xcodebuild
  if ReportNameHelper.includes_xcresult?(@options[:output_types])
    scan_config._values.delete(:result_bundle)
    ENV.delete('SCAN_RESULT_BUNDLE')
  end
  scan_config._values.delete(:skip_testing)
  scan_cache.clear
end

#runObject

:nocov:



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/fastlane/plugin/test_center/helper/multi_scan_manager/retrying_scan.rb', line 63

def run
  try_count = @options[:try_count] || 1
  begin
    @retrying_scan_helper.before_testrun
    update_scan_options

    values = scan_config.values(ask: false)
    values[:xcode_path] = File.expand_path("../..", FastlaneCore::Helper.xcode_path)
    ScanHelper.print_scan_parameters(values)

    Scan::Runner.new.run
    @retrying_scan_helper.after_testrun
    true
  rescue FastlaneCore::Interface::FastlaneTestFailure => e
    @retrying_scan_helper.after_testrun(e)
    retry if @retrying_scan_helper.testrun_count < try_count
    false
  rescue FastlaneCore::Interface::FastlaneBuildFailure => e
    @retrying_scan_helper.after_testrun(e)
    retry if @retrying_scan_helper.testrun_count < try_count
    false
  end
end

#scan_cacheObject



15
16
17
# File 'lib/fastlane/plugin/test_center/helper/multi_scan_manager/retrying_scan.rb', line 15

def scan_cache
  Scan.cache
end

#scan_configObject

:nocov:



11
12
13
# File 'lib/fastlane/plugin/test_center/helper/multi_scan_manager/retrying_scan.rb', line 11

def scan_config
  Scan.config
end

#update_scan_optionsObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/fastlane/plugin/test_center/helper/multi_scan_manager/retrying_scan.rb', line 35

def update_scan_options
  valid_scan_keys = Fastlane::Actions::ScanAction.available_options.map(&:key)
  scan_options = @options.select { |k,v| valid_scan_keys.include?(k) }
                          .merge(@retrying_scan_helper.scan_options)

  prepare_scan_config
  scan_options[:build_for_testing] = false
  scan_options.delete(:skip_testing)
  FastlaneCore::UI.verbose("retrying_scan #update_scan_options")
  scan_options.each do |k,v|
    next if v.nil?

    scan_config.set(k,v) unless v.nil?
    FastlaneCore::UI.verbose("\tSetting #{k.to_s} to #{v}")
  end
  if @options[:scan_devices_override]
    scan_device_names = @options[:scan_devices_override].map { |device| device.name }
    FastlaneCore::UI.verbose("\tSetting Scan.devices to #{scan_device_names}")
    Scan.devices.replace(@options[:scan_devices_override])
  end
end