fastlane-plugin-try_scan 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c6c7d43c04eefe86a77bf821325cfe4a435487df5162edc121784d5a7b22eb97
4
- data.tar.gz: ec7438c57260293d37e743ec83bc9303c8893259a6d0d9f088e4675e0ea74a94
3
+ metadata.gz: f1cf8ffd4f2e1a0558797b6bdd7094d7b36f42306d28d10bea3172be11c42688
4
+ data.tar.gz: c286e3609e7900a837322e36dc86ed3ead3a17fe0a32a3239a87de8feb8a742a
5
5
  SHA512:
6
- metadata.gz: 57050baf27ba80ade9c67594d7d9d2f0280352fc14e758d6783043cdc1929b23abe7bf92b5d0f8f0d36a2fbe8d70b14e19de04ea7d99ce48c151b8d1072ec0f4
7
- data.tar.gz: cfc8abc27d18cce7067ce95316214d9f4f477bfb6d4375b7dc5ce41e0f1ac070295513086f21c64610eff0ecee28b21c507bddd9554c1a4bf2f85ed92062db6e
6
+ metadata.gz: 27fea4e492a529eee6953d601914075b0042549345bfb4fc91e28bf0562fc514c943bbebdb929777c5973d863ec8b09795b9445e46c76cd3da142a14c42d08fa
7
+ data.tar.gz: 12bab09a883ab80263e01a65b07ec9670df952a2800d1296a87688af7bf8736de240ebf35f05cf6f54df822d405cc3cf3c50f40b2c6ca3f908b0db69e1288d32
@@ -2,7 +2,6 @@ module Fastlane
2
2
  module Actions
3
3
 
4
4
  require 'json'
5
- require 'nokogiri'
6
5
  require 'fastlane/actions/scan'
7
6
  require_relative '../helper/scan_helper'
8
7
  require_relative '../helper/try_scan_runner'
@@ -11,61 +10,31 @@ module Fastlane
11
10
 
12
11
  class TryScanAction < Action
13
12
  def self.run(params)
14
- prepare_for_testing(params)
15
- success = TryScanManager::Runner.new(params.values).run
16
-
17
- raise FastlaneCore::UI.test_failure!('Tests have failed') if params[:fail_build] && !success
18
- end
19
-
20
- def self.prepare_for_testing(params)
21
- warn_of_xcode11_result_bundle_incompatability(params)
22
- use_scanfile_to_override_settings(params.values)
23
- turn_off_concurrent_workers(params.values)
24
- prepare_scan_config(params.values)
25
- coerce_destination_to_array(params)
13
+ if Helper.xcode_at_least?('11.0.0')
14
+ prepare_scan_config(params.values)
15
+ prepare_destination(params)
16
+ success = TryScanManager::Runner.new(params.values).run
17
+
18
+ raise FastlaneCore::UI.test_failure!('Tests have failed') if params[:fail_build] && !success
19
+ else
20
+ raise FastlaneCore::UI.user_error!("Minimum supported Xcode: `v11.0.0` (used: `v#{Helper.xcode_version}`)")
21
+ end
26
22
  end
27
23
 
28
- def self.warn_of_xcode11_result_bundle_incompatability(params)
29
- if FastlaneCore::Helper.xcode_at_least?('11.0.0')
30
- if params[:result_bundle]
31
- FastlaneCore::UI.important('As of Xcode 11, test_result bundles created in the output directory are actually symbolic links to an xcresult bundle')
32
- end
33
- elsif params[:output_types]&.include?('xcresult')
34
- FastlaneCore::UI.important("The 'xcresult' :output_type is only supported for Xcode 11 and greater. You are using #{FastlaneCore::Helper.xcode_version}.")
35
- end
24
+ def self.prepare_scan_config(scan_options)
25
+ Scan.config = FastlaneCore::Configuration.create(
26
+ Fastlane::Actions::ScanAction.available_options,
27
+ FastlaneScanHelper.scan_options_from_try_scan_options(scan_options)
28
+ )
36
29
  end
37
30
 
38
- def self.coerce_destination_to_array(params)
31
+ def self.prepare_destination(params)
39
32
  destination = params[:destination] || Scan.config[:destination] || []
40
33
  unless destination.kind_of?(Array)
41
34
  params[:destination] = Scan.config[:destination] = [destination]
42
35
  end
43
36
  end
44
37
 
45
- def self.turn_off_concurrent_workers(scan_options)
46
- if Gem::Version.new(Fastlane::VERSION) >= Gem::Version.new('2.142.0')
47
- scan_options.delete(:concurrent_workers) if scan_options[:concurrent_workers].to_i > 0
48
- end
49
- end
50
-
51
- def self.use_scanfile_to_override_settings(scan_options)
52
- overridden_options = FastlaneScanHelper.options_from_configuration_file(
53
- FastlaneScanHelper.scan_options_from_try_scan_options(scan_options)
54
- )
55
-
56
- unless overridden_options.empty?
57
- FastlaneCore::UI.important("Scanfile found: overriding try_scan options with it's values.")
58
- overridden_options.each { |key, val| scan_options[key] = val }
59
- end
60
- end
61
-
62
- def self.prepare_scan_config(scan_options)
63
- Scan.config ||= FastlaneCore::Configuration.create(
64
- Fastlane::Actions::ScanAction.available_options,
65
- FastlaneScanHelper.scan_options_from_try_scan_options(scan_options)
66
- )
67
- end
68
-
69
38
  #####################################################
70
39
  # Documentation #
71
40
  #####################################################
@@ -78,13 +47,8 @@ module Fastlane
78
47
  ["Alexey Alter-Pesotskiy"]
79
48
  end
80
49
 
81
- def self.scan_options
82
- ScanAction.available_options.reject { |config| %i[output_types].include?(config.key) }
83
- end
84
-
85
50
  def self.available_options
86
- scan_options = ScanAction.available_options.reject { |config| %i[output_types].include?(config.key) }
87
- scan_options + [
51
+ ScanAction.available_options + [
88
52
  FastlaneCore::ConfigItem.new(
89
53
  key: :try_count,
90
54
  env_name: "FL_TRY_SCAN_TRY_COUNT",
@@ -19,31 +19,9 @@ module TryScanManager
19
19
  end
20
20
 
21
21
  def self.scan_options_from_try_scan_options(params)
22
- valid_scan_keys = Fastlane::Actions::ScanAction.available_options.map(&:key)
23
22
  params.select { |key, _| valid_scan_keys.include?(key) }
24
23
  end
25
24
 
26
- def self.options_from_configuration_file(params)
27
- config = FastlaneCore::Configuration.create(
28
- Fastlane::Actions::ScanAction.available_options,
29
- params
30
- )
31
- config_file = config.load_configuration_file(Scan.scanfile_name, nil, true)
32
- overridden_options = config_file ? config_file.options : {}
33
-
34
- FastlaneCore::Project.detect_projects(config)
35
- project = FastlaneCore::Project.new(config)
36
-
37
- imported_path = File.expand_path(Scan.scanfile_name)
38
- Dir.chdir(File.expand_path("..", project.path)) do
39
- if File.expand_path(Scan.scanfile_name) != imported_path
40
- config_file = config.load_configuration_file(Scan.scanfile_name, nil, true)
41
- end
42
- overridden_options.merge!(config_file.options) if config_file
43
- end
44
- overridden_options
45
- end
46
-
47
25
  def self.remove_preexisting_simulator_logs(params)
48
26
  return unless params[:include_simulator_logs]
49
27
 
@@ -90,4 +68,4 @@ module TryScanManager
90
68
  end
91
69
  end
92
70
  end
93
- end
71
+ end
@@ -5,42 +5,37 @@ module TryScanManager
5
5
 
6
6
  def initialize(options = {})
7
7
  @options = options
8
+ @options[:try_count] = 1 if @options[:try_count] < 1
8
9
  end
9
10
 
10
11
  def run
11
- update_scan_config
12
12
  print_summary
13
13
  @attempt = 1
14
14
  begin
15
+ essential_scan_config_updates
15
16
  warn_of_performing_attempts
16
17
  clear_preexisting_data
17
18
  Scan::Runner.new.run
18
- print_parallel_scan_result
19
+ print_try_scan_result
19
20
  return true
20
21
  rescue FastlaneCore::Interface::FastlaneTestFailure => _
21
- failed_tests = extract_failed_tests
22
- print_parallel_scan_result(failed_tests_count: failed_tests.size)
23
- update_scan_junit_report
24
- return false if @attempt >= @options[:try_count]
22
+ failed_tests = failed_tests_from_xcresult_report
23
+ print_try_scan_result(failed_tests_count: failed_tests.size)
24
+ return false if finish?
25
25
 
26
26
  @attempt += 1
27
27
  update_scan_options(failed_tests)
28
28
  retry
29
29
  rescue FastlaneCore::Interface::FastlaneBuildFailure => _
30
- return false if @attempt >= @options[:try_count]
30
+ return false if finish?
31
31
 
32
32
  @attempt += 1
33
33
  retry
34
34
  end
35
35
  end
36
36
 
37
- def update_scan_config
38
- if !Scan.config[:output_types].include?('junit') && !parallel_running?
39
- output_types = Scan.config[:output_types].split(',')
40
- output_types << 'junit'
41
- Scan.config[:output_types] = output_types.join(',')
42
- end
43
- @options[:try_count] = 1 if @options[:try_count] < 1
37
+ def finish?
38
+ @attempt >= @options[:try_count]
44
39
  end
45
40
 
46
41
  def print_summary
@@ -70,9 +65,7 @@ module TryScanManager
70
65
  FastlaneScanHelper.remove_report_files
71
66
  end
72
67
 
73
- def print_parallel_scan_result(failed_tests_count: 0)
74
- return unless parallel_running?
75
-
68
+ def print_try_scan_result(failed_tests_count: 0)
76
69
  FastlaneCore::UI.important("TryScan: result after #{ordinalized_attempt} shot 👇")
77
70
  FastlaneCore::PrintTable.print_values(
78
71
  config: {"Number of tests" => tests_count_from_xcresult_report, "Number of failures" => failed_tests_count},
@@ -94,97 +87,24 @@ module TryScanManager
94
87
  end
95
88
 
96
89
  def update_scan_options(failed_tests)
97
- scan_options = @options.select { |key, _|
98
- FastlaneScanHelper.valid_scan_keys.include?(key)
99
- }.merge(plugin_scan_options)
90
+ scan_options = FastlaneScanHelper.scan_options_from_try_scan_options(@options)
100
91
  scan_options[:only_testing] = failed_tests
101
92
  scan_options[:skip_build] = true
102
93
  scan_options[:test_without_building] = true
103
- scan_options[:build_for_testing] = false
104
94
  scan_options.delete(:skip_testing)
105
95
  Scan.cache.clear
106
96
  scan_options.each do |key, val|
107
97
  next if val.nil?
108
98
 
109
- Scan.config.set(key, val) unless val.nil?
99
+ Scan.config.set(key, val)
110
100
  FastlaneCore::UI.verbose("\tSetting #{key.to_s} to #{val}")
111
101
  end
112
102
  end
113
103
 
114
- def plugin_scan_options
115
- xcargs = @options[:xcargs] || ''
116
- if xcargs&.include?('build-for-testing')
117
- FastlaneCore::UI.important(":xcargs, #{xcargs}, contained 'build-for-testing', removing it")
118
- xcargs.slice!('build-for-testing')
119
- end
120
- if xcargs.include?('-quiet')
121
- FastlaneCore::UI.important('Disabling -quiet as failing tests cannot be found with it enabled.')
122
- xcargs.gsub!('-quiet', '')
123
- end
124
- @options.select { |key, _| FastlaneScanHelper.valid_scan_keys.include?(key) }.merge({ xcargs: xcargs })
125
- end
126
-
127
- def extract_failed_tests
128
- if parallel_running?
129
- failed_tests_from_xcresult_report
130
- else
131
- failed_tests_from_junit_report
132
- end
133
- end
134
-
135
- def parallel_running?
136
- return @options[:concurrent_workers].to_i > 0 ||
137
- (@options[:devices] && @options[:devices].size > 1) ||
138
- (@options[:xcargs] && (@options[:xcargs] =~ /-parallel-testing-enabled(=|\s+)YES/ || @options[:xcargs].split('-destination').size > 2))
139
- end
140
-
141
- def failed_tests_from_junit_report
142
- report = junit_report
143
- suite_name = report.xpath('testsuites/@name').to_s.split('.')[0]
144
- test_cases = report.xpath('//testcase')
145
- only_testing = []
146
- test_cases.each do |test_case|
147
- next if test_case.xpath('failure').empty?
148
-
149
- test_class = test_case.xpath('@classname').to_s.split('.')[1]
150
- test_name = test_case.xpath('@name')
151
- only_testing << "#{suite_name}/#{test_class}/#{test_name}"
152
- end
153
- only_testing
154
- end
155
-
156
- def junit_report(cached: false)
157
- unless cached
158
- report_options = FastlaneScanHelper.report_options
159
- output_files = report_options.instance_variable_get(:@output_files)
160
- output_directory = report_options.instance_variable_get(:@output_directory)
161
- file_name = output_files.select { |name| name.include?('.xml') }.first
162
- @junit_report_path = "#{output_directory}/#{file_name}"
163
- @cached_junit_report = File.open(@junit_report_path) { |f| Nokogiri::XML(f) }
164
- end
165
- @cached_junit_report
166
- end
167
-
168
- def update_scan_junit_report
169
- return if @attempt == 1 || parallel_running?
170
-
171
- old_junit_report = junit_report(cached: true)
172
- new_junit_report = junit_report(cached: false)
173
-
174
- new_junit_report.css("testsuites").zip(old_junit_report.css("testsuites")).each do |new_suites, old_suites|
175
- old_suites.attributes["failures"].value = new_suites.attributes["failures"].value
176
- new_suites.css("testsuite").zip(old_suites.css("testsuite")).each do |new_suite, old_suite|
177
- old_suite.attributes["failures"].value = new_suite.attributes["failures"].value
178
- end
179
- end
180
-
181
- new_junit_report.css('testcase').each do |node1|
182
- old_junit_report.css('testcase').each do |node2|
183
- node2.children = node1.children if node1['name'] == node2['name']
184
- end
185
- end
186
-
187
- File.open(@junit_report_path, "w+") { |f| f.write(old_junit_report.to_xml) }
104
+ def essential_scan_config_updates
105
+ Scan.config[:result_bundle] = true
106
+ Scan.config[:build_for_testing] = nil if Scan.config[:build_for_testing]
107
+ Scan.config[:xcargs].slice!('build-for-testing') if Scan.config[:xcargs]&.include?('build-for-testing')
188
108
  end
189
109
 
190
110
  def parse_xcresult_report
@@ -1,5 +1,5 @@
1
1
  module Fastlane
2
2
  module TryScan
3
- VERSION = "0.3.0"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane-plugin-try_scan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexey Alter-Pesotskiy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-16 00:00:00.000000000 Z
11
+ date: 2020-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: nokogiri
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: json
29
15
  requirement: !ruby/object:Gem::Requirement