Class: TryScanManager::Runner
- Inherits:
-
Object
- Object
- TryScanManager::Runner
- Defined in:
- lib/fastlane/plugin/try_scan/helper/try_scan_runner.rb
Constant Summary collapse
- FastlaneScanHelper =
TryScanManager::Helper::FastlaneScanHelper
Instance Method Summary collapse
- #clear_preexisting_data ⇒ Object
- #extract_failed_tests ⇒ Object
-
#initialize(options = {}) ⇒ Runner
constructor
A new instance of Runner.
- #junit_report(cached: false) ⇒ Object
- #merge_junit_reports ⇒ Object
- #plugin_scan_options ⇒ Object
- #print_summary ⇒ Object
- #run ⇒ Object
- #update_scan_config ⇒ Object
- #update_scan_options ⇒ Object
- #warn_of_performing_attempts(attempt) ⇒ Object
- #warn_of_try_scan_option ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Runner
Returns a new instance of Runner.
6 7 8 9 |
# File 'lib/fastlane/plugin/try_scan/helper/try_scan_runner.rb', line 6 def initialize( = {}) @options = warn_of_try_scan_option end |
Instance Method Details
#clear_preexisting_data ⇒ Object
61 62 63 64 65 66 |
# File 'lib/fastlane/plugin/try_scan/helper/try_scan_runner.rb', line 61 def clear_preexisting_data FastlaneScanHelper.remove_preexisting_simulator_logs(@options) FastlaneScanHelper.remove_preexisting_test_result_bundles(@options) FastlaneScanHelper.remove_preexisting_xcresult_bundles(@options) FastlaneScanHelper.remove_report_files end |
#extract_failed_tests ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/fastlane/plugin/try_scan/helper/try_scan_runner.rb', line 98 def extract_failed_tests report = junit_report suite_name = report.xpath('testsuites/@name').to_s.split('.')[0] test_cases = report.xpath('//testcase') only_testing = [] test_cases.each do |test_case| next if test_case.xpath('failure').empty? test_class = test_case.xpath('@classname').to_s.split('.')[1] test_name = test_case.xpath('@name') only_testing << "#{suite_name}/#{test_class}/#{test_name}" end only_testing end |
#junit_report(cached: false) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/fastlane/plugin/try_scan/helper/try_scan_runner.rb', line 113 def junit_report(cached: false) unless cached = FastlaneScanHelper. output_files = .instance_variable_get(:@output_files) output_directory = .instance_variable_get(:@output_directory) file_name = output_files.select { |name| name.include?('.xml') }.first @junit_report_path = "#{output_directory}/#{file_name}" @cached_junit_report = File.open(@junit_report_path) { |f| Nokogiri::XML(f) } end @cached_junit_report end |
#merge_junit_reports ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/fastlane/plugin/try_scan/helper/try_scan_runner.rb', line 125 def merge_junit_reports old_junit_report = junit_report(cached: true) new_junit_report = junit_report(cached: false) new_junit_report.css("testsuites").zip(old_junit_report.css("testsuites")).each do |new_suites, old_suites| old_suites.attributes["failures"].value = new_suites.attributes["failures"].value new_suites.css("testsuite").zip(old_suites.css("testsuite")).each do |new_suite, old_suite| old_suite.attributes["failures"].value = new_suite.attributes["failures"].value end end new_junit_report.css('testcase').each do |node1| old_junit_report.css('testcase').each do |node2| node2.children = node1.children if node1['name'] == node2['name'] end end File.open(@junit_report_path, "w+") { |f| f.write(old_junit_report.to_xml) } end |
#plugin_scan_options ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/fastlane/plugin/try_scan/helper/try_scan_runner.rb', line 84 def xcargs = @options[:xcargs] || '' if xcargs&.include?('build-for-testing') FastlaneCore::UI.important(":xcargs, #{xcargs}, contained 'build-for-testing', removing it") xcargs.slice!('build-for-testing') end if xcargs.include?('-quiet') FastlaneCore::UI.important('Disabling -quiet as failing tests cannot be found with it enabled.') xcargs.gsub!('-quiet', '') end xcargs.gsub!(/-parallel-testing-enabled(=|\s+)(YES|NO)/, '') @options.select { |k,v| FastlaneScanHelper.valid_scan_keys.include?(k) }.merge({ xcargs: "#{xcargs} -parallel-testing-enabled NO " }) end |
#print_summary ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/fastlane/plugin/try_scan/helper/try_scan_runner.rb', line 34 def print_summary return if FastlaneCore::Helper.test? scan_actual_params = Scan.config.values(ask: false) scan_available_keys = Scan.config..map(&:key) try_scan_params = @options.reject { |try_scan_key, _| scan_available_keys.include?(try_scan_key) } FastlaneCore::PrintTable.print_values( config: try_scan_params, title: "Summary for try_scan #{Fastlane::TryScan::VERSION}" ) FastlaneCore::PrintTable.print_values( config: scan_actual_params, title: "Summary for scan #{Fastlane::VERSION}" ) end |
#run ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/fastlane/plugin/try_scan/helper/try_scan_runner.rb', line 11 def run update_scan_config print_summary attempt = 1 begin warn_of_performing_attempts(attempt) clear_preexisting_data Scan::Runner.new.run return true rescue FastlaneCore::Interface::FastlaneBuildFailure, FastlaneCore::Interface::FastlaneTestFailure => _ merge_junit_reports if attempt != 1 return false if attempt > @options[:try_count] attempt += 1 retry end end |
#update_scan_config ⇒ Object
30 31 32 |
# File 'lib/fastlane/plugin/try_scan/helper/try_scan_runner.rb', line 30 def update_scan_config Scan.config[:output_types] << 'junit' unless Scan.config[:output_types].include?('junit') end |
#update_scan_options ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/fastlane/plugin/try_scan/helper/try_scan_runner.rb', line 68 def = @options.select { |key, _| FastlaneScanHelper.valid_scan_keys.include?(key) }.merge() [:only_testing] = extract_failed_tests [:skip_build] = true [:test_without_building] = true [:build_for_testing] = false .delete(:skip_testing) Scan.cache.clear .each do |key, val| next if val.nil? Scan.config.set(key, val) unless val.nil? FastlaneCore::UI.verbose("\tSetting #{key.to_s} to #{val}") end end |
#warn_of_performing_attempts(attempt) ⇒ Object
50 51 52 |
# File 'lib/fastlane/plugin/try_scan/helper/try_scan_runner.rb', line 50 def warn_of_performing_attempts(attempt) FastlaneCore::UI.important("TryScan shot №#{attempt}\n") end |
#warn_of_try_scan_option ⇒ Object
54 55 56 57 58 59 |
# File 'lib/fastlane/plugin/try_scan/helper/try_scan_runner.rb', line 54 def warn_of_try_scan_option if @options[:try_count] <= 0 FastlaneCore::UI.important(":try_count can't be less than or equal to zero. Setting a default value equal to `1`") @options[:try_count] = 1 end end |