fastlane-plugin-rescan_flaky_tests 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d181fd6674c26468ed557a9247aa56edf05a138c
4
+ data.tar.gz: 6a009b3b84a005155582c5abeeaa62f5c310b309
5
+ SHA512:
6
+ metadata.gz: 6f74882b3a2e3fd3757573488b472c3ea4e441a499146ace4da436fd9f89ea72e1d0a2d2b3209b775db04cdcd51330590455aace309223cb971736e898ac022a
7
+ data.tar.gz: 1a115ffbb8929a12c4131d06329a36c77e564c40def52a23d80e3907a069f0cae664678dee37f3d172fd5c141610c793b9f7ec504012095339ab22caf5571c9a
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Ichiko Moro <ichiko.revjune@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,53 @@
1
+ # rescan_flaky_tests plugin
2
+
3
+ [![fastlane Plugin Badge](https://rawcdn.githack.com/fastlane/fastlane/master/fastlane/assets/plugin-badge.svg)](https://rubygems.org/gems/fastlane-plugin-rescan_flaky_tests)
4
+
5
+
6
+ ## Getting Started
7
+
8
+ This project is a [_fastlane_](https://github.com/fastlane/fastlane) plugin. To get started with `fastlane-plugin-rescan_flaky_tests`, add it to your project by running:
9
+
10
+ ```bash
11
+ fastlane add_plugin rescan_flaky_tests
12
+ ```
13
+
14
+ ## About rescan_flaky_tests
15
+
16
+ Re-run `scan` action for each failed test case.
17
+
18
+ When you running UI tests (XCUITest, EarlGrey or others), sometime that failed with un clear reason.
19
+
20
+ This plugin re-scan each failed test cases. And report result under `#{output_directory}/rescan/NN`.
21
+
22
+ ## Example
23
+
24
+ Check out the [example `Fastfile`](example/SampleDice/fastlane/Fastfile) to see how to use this plugin. Try it by cloning the repo, running `cd example/SampleDice; fastlane install_plugins` and `bundle exec fastlane test_ui`.
25
+
26
+ ## Run tests for this plugin
27
+
28
+ To run both the tests, and code style validation, run
29
+
30
+ ```
31
+ rake
32
+ ```
33
+
34
+ To automatically fix many of the styling issues, use
35
+ ```
36
+ rubocop -a
37
+ ```
38
+
39
+ ## Issues and Feedback
40
+
41
+ For any other issues and feedback about this plugin, please submit it to this repository.
42
+
43
+ ## Troubleshooting
44
+
45
+ If you have trouble using plugins, check out the [Plugins Troubleshooting](https://docs.fastlane.tools/plugins/plugins-troubleshooting/) guide.
46
+
47
+ ## Using _fastlane_ Plugins
48
+
49
+ For more information about how the `fastlane` plugin system works, check out the [Plugins documentation](https://docs.fastlane.tools/plugins/create-plugin/).
50
+
51
+ ## About _fastlane_
52
+
53
+ _fastlane_ is the easiest way to automate beta deployments and releases for your iOS and Android apps. To learn more, check out [fastlane.tools](https://fastlane.tools).
@@ -0,0 +1,16 @@
1
+ require 'fastlane/plugin/rescan_flaky_tests/version'
2
+
3
+ module Fastlane
4
+ module RescanFlakyTests
5
+ # Return all .rb files inside the "actions" and "helper" directory
6
+ def self.all_classes
7
+ Dir[File.expand_path('**/{actions,helper}/*.rb', File.dirname(__FILE__))]
8
+ end
9
+ end
10
+ end
11
+
12
+ # By default we want to import all available actions and helpers
13
+ # A plugin can contain any number of actions and plugins
14
+ Fastlane::RescanFlakyTests.all_classes.each do |current|
15
+ require current
16
+ end
@@ -0,0 +1,126 @@
1
+ module Fastlane
2
+ module Actions
3
+ class RescanFlakyTestsAction < Action
4
+ def self.run(params)
5
+ first_report_path = params[:report_file]
6
+ unless File.exist?(first_report_path)
7
+ UI.user_error!("The report file '#{first_report_path}' is not found.")
8
+ end
9
+
10
+ test_cases = Helper::RescanFlakyTestsHelper.extract_failed_test_cases(first_report_path)
11
+ if test_cases.nil?
12
+ UI.user_error!("The report should be junit xml file.")
13
+ end
14
+ if test_cases.empty?
15
+ UI.important("There is no test to retry.")
16
+ return true
17
+ end
18
+
19
+ failed_test_limit = params[:failed_test_limit]
20
+ if failed_test_limit > 0 && failed_test_limit < test_cases.count
21
+ UI.error("Stop rescan because there are too many faild cases, #{test_cases.count} > #{failed_test_limit} (threshold).")
22
+ exit 0
23
+ end
24
+
25
+ rescan_output_root = params[:output_directory]
26
+
27
+ last_exception = nil
28
+
29
+ test_cases.each_with_index do |test_case, i|
30
+ retry_output_directory = File.join(rescan_output_root, "rescan", (i + 1).to_s)
31
+ UI.important("Rescan '#{test_case}'.")
32
+ UI.important("Reports are saved '#{retry_output_directory}'.")
33
+
34
+ begin
35
+ scan_options = params[:scan]
36
+ scan_options[:only_testing] = [test_case]
37
+ scan_options[:output_directory] = retry_output_directory
38
+ scan_options[:buildlog_path] = retry_output_directory
39
+
40
+ scan_params = FastlaneCore::Configuration.create(ScanAction.available_options, scan_options)
41
+ ::Fastlane::Actions::ScanAction.run(scan_params)
42
+ rescue => e
43
+ last_exception = e
44
+ end
45
+ end
46
+
47
+ raise last_exception unless last_exception.nil?
48
+ end
49
+
50
+ def self.description
51
+ "Re-run `scan` action for each failed test case."
52
+ end
53
+
54
+ def self.authors
55
+ ["Ichiko Moro"]
56
+ end
57
+
58
+ def self.details
59
+ "When you running UI tests (XCUITest, EarlGrey or others), sometime that failed with un clear reason. \n\
60
+ This plugin re-scan each failed test cases. And report result under `\#{output_directory}/rescan/NN`."
61
+ end
62
+
63
+ def self.available_options
64
+ containing = FastlaneCore::Helper.fastlane_enabled_folder_path
65
+
66
+ [
67
+ FastlaneCore::ConfigItem.new(key: :report_file,
68
+ env_name: 'RESCAN_REPORT_FILE',
69
+ description: "JUnit report file path generated by scan, rescan target test cases extract from the file",
70
+ type: String,
71
+ default_value: File.join(containing, "test_output", "report.junit"),
72
+ default_value_dynamic: true),
73
+ FastlaneCore::ConfigItem.new(key: :output_directory,
74
+ env_name: 'RESCAN_OUTPUT_DIRECTORY',
75
+ description: "Each rescaned report and build log is saved in rescan_NN under the path",
76
+ type: String,
77
+ default_value: File.join(containing, "test_output"),
78
+ default_value_dynamic: true,
79
+ optional: true),
80
+ FastlaneCore::ConfigItem.new(key: :failed_test_limit,
81
+ env_name: 'RESCAN_FAILED_TEST_LIMIT',
82
+ description: "Stop rescan if faild test cases count is greater than this threshold. No limitation if this value is ZERO",
83
+ type: Integer,
84
+ default_value: 0,
85
+ optional: true),
86
+ FastlaneCore::ConfigItem.new(key: :scan,
87
+ description: "Parameters that are passed to the scan action",
88
+ type: Hash,
89
+ default_value: {},
90
+ optional: true)
91
+ ]
92
+ end
93
+
94
+ def self.is_supported?(platform)
95
+ [:ios, :mac].include?(platform)
96
+ end
97
+
98
+ def self.example_code
99
+ [
100
+ '# shoud run `scan` before to get first test result.',
101
+ 'begin
102
+ scan
103
+ rescue
104
+ rescan_flaky_tests
105
+ end',
106
+ '# use rescue block or `fail_build` option',
107
+ 'scan(fail_build: false)
108
+ rescan_flaky_tests',
109
+ '# recommend to pack scan options',
110
+ 'scan_options = {
111
+ ...
112
+ }
113
+ begin
114
+ scan(scan_options)
115
+ rescue
116
+ rescan_flaky_tests(
117
+ scan_options.merge {
118
+ report_file: "path/to/report.junit"
119
+ }
120
+ )
121
+ end'
122
+ ]
123
+ end
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,28 @@
1
+ require 'rexml/document'
2
+
3
+ module Fastlane
4
+ module Helper
5
+ class RescanFlakyTestsHelper
6
+ # class methods that you define here become available in your action
7
+ # as `Helper::RescanEachFragileTestsHelper.your_method`
8
+ #
9
+ def self.extract_failed_test_cases(report_file)
10
+ xml_doc = REXML::Document.new(File.open(report_file))
11
+
12
+ if xml_doc.elements.collect("testsuites") { |e| e }.count == 0
13
+ return nil
14
+ end
15
+
16
+ test_cases = []
17
+ xml_doc.elements.each("testsuites/testsuite/testcase[failure]") do |test_case|
18
+ (bundle, test_suite) = test_case.attributes["classname"].split(".")
19
+ method = test_case.attributes["name"]
20
+ # xcodebuild changes '-' to '_'
21
+ bundle.gsub!("_", "-")
22
+ test_cases << "#{bundle}/#{test_suite}/#{method}"
23
+ end
24
+ test_cases
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,5 @@
1
+ module Fastlane
2
+ module RescanFlakyTests
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fastlane-plugin-rescan_flaky_tests
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ichiko Moro
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-03-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: pry
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec_junit_formatter
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: 0.49.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 0.49.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: fastlane
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: 2.70.2
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: 2.70.2
125
+ description:
126
+ email: ichiko.revjune@gmail.com
127
+ executables: []
128
+ extensions: []
129
+ extra_rdoc_files: []
130
+ files:
131
+ - LICENSE
132
+ - README.md
133
+ - lib/fastlane/plugin/rescan_flaky_tests.rb
134
+ - lib/fastlane/plugin/rescan_flaky_tests/actions/rescan_flaky_tests_action.rb
135
+ - lib/fastlane/plugin/rescan_flaky_tests/helper/rescan_flaky_tests_helper.rb
136
+ - lib/fastlane/plugin/rescan_flaky_tests/version.rb
137
+ homepage: https://github.com/ichiko/fastlane-plugin-rescan_each_fragile_tests
138
+ licenses:
139
+ - MIT
140
+ metadata: {}
141
+ post_install_message:
142
+ rdoc_options: []
143
+ require_paths:
144
+ - lib
145
+ required_ruby_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ requirements: []
156
+ rubyforge_project:
157
+ rubygems_version: 2.5.2.1
158
+ signing_key:
159
+ specification_version: 4
160
+ summary: Re-run `scan` action for each failed test cases.
161
+ test_files: []