fastlane-plugin-xcresult_to_junit 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f5757e2a9823c97cfa45d23ac665ed098c7cae0736484b9f6c3467b9c6d94aa2
4
+ data.tar.gz: 591790faba5cd45cbf2d4611ed8a7b7fe9218a98bbf277e21a7cad294b542871
5
+ SHA512:
6
+ metadata.gz: 50ff098a3dfa44f066d477985fedf2e138b1007648b618911c2b4c1681d7134d13d0f10524882ab17687662c370c01c282ffd356070232ea8c539c8161234859
7
+ data.tar.gz: c8a5783667857c1cc03e25e48df679b9e1721ff00f90d710250daea7debdb82e68b613397f0dd48e273e237a2bc1d168c62f35345f4084a0b653bd23da110bbf
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Shane Birdsall <shane.birdsall@fiserv.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,78 @@
1
+ # xcresult_to_junit plugin
2
+
3
+ [![fastlane Plugin Badge](https://rawcdn.githack.com/fastlane/fastlane/master/fastlane/assets/plugin-badge.svg)](https://rubygems.org/gems/fastlane-plugin-xcresult_to_junit)
4
+
5
+ ## Getting Started
6
+
7
+ This project is a [_fastlane_](https://github.com/fastlane/fastlane) plugin. To get started with `fastlane-plugin-xcresult_to_junit`, add it to your project by running:
8
+
9
+ ```bash
10
+ fastlane add_plugin xcresult_to_junit
11
+ ```
12
+
13
+ ## About xcresult_to_junit
14
+
15
+ This plugin produces junit xml files from Xcode 11+ xcresult files.
16
+
17
+ This tool is not designed to work with result files produced with xcode versions older than xcode 11.
18
+
19
+ My main motivation behind creating my own solution was to have a plugin that works in a variety of testing scenarios.
20
+ The below table captures the current requirements this plugin meets. If you have a requirement that is not met by this plugin and would like to contribute then please feel free :metal:
21
+
22
+ | Requirement | Status |
23
+ |---------------------------------------|--------------------|
24
+ | Works against one iOS device | :white_check_mark: |
25
+ | Works against multiple iOS device | :white_check_mark: |
26
+ | Generates one junit report per target | :white_check_mark: |
27
+ | Works with modern formats (Xcode 11+) | :white_check_mark: |
28
+
29
+ ## Example
30
+
31
+ Check out the [example `Fastfile`](fastlane/Fastfile) to see how to use this plugin. Try it by cloning the repo, running `fastlane install_plugins` and `bundle exec fastlane test`.
32
+
33
+ Ensure you specify the following when you call scan
34
+ ```ruby
35
+ fail_build: false, # Allows to continue after scan
36
+ result_bundle: true # Generate xcresult in output directory
37
+ ```
38
+
39
+ After scan you can call the plugin, which will look something like this
40
+ ```ruby
41
+ xcresult_to_junit(xcresult_path: './test_output/MyScheme.test_result.xcresult', output_path: './test_output/')
42
+ ```
43
+
44
+ We can get a list of the junit reports generated by doing something like so
45
+ ```ruby
46
+ junit_reports = Dir['./test_output/*.junit']
47
+ # Now we can iterate over the reports and send them where they need to go
48
+ # My test_output folder would ideally have been cleaned before this test run to avoid old results
49
+ ```
50
+
51
+ ## Run tests for this plugin
52
+
53
+ To run both the tests, and code style validation, run
54
+
55
+ ```
56
+ rake
57
+ ```
58
+
59
+ To automatically fix many of the styling issues, use
60
+ ```
61
+ rubocop -a
62
+ ```
63
+
64
+ ## Issues and Feedback
65
+
66
+ For any other issues and feedback about this plugin, please submit it to this repository.
67
+
68
+ ## Troubleshooting
69
+
70
+ If you have trouble using plugins, check out the [Plugins Troubleshooting](https://docs.fastlane.tools/plugins/plugins-troubleshooting/) guide.
71
+
72
+ ## Using _fastlane_ Plugins
73
+
74
+ For more information about how the `fastlane` plugin system works, check out the [Plugins documentation](https://docs.fastlane.tools/plugins/create-plugin/).
75
+
76
+ ## About _fastlane_
77
+
78
+ _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/xcresult_to_junit/version'
2
+
3
+ module Fastlane
4
+ module XcresultToJunit
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::XcresultToJunit.all_classes.each do |current|
15
+ require current
16
+ end
@@ -0,0 +1,93 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/xcresult_to_junit_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ class XcresultToJunitAction < Action
7
+ def self.run(params)
8
+ UI.message("The xcresult_to_junit plugin has started!")
9
+ all_results = Helper::XcresultToJunitHelper.load_results(params[:xcresult_path])['actions']['_values']
10
+ all_results.each do |test_run|
11
+ if test_run['actionResult']['testsRef'] # Skip if section has no testRef data as this means its not a test run
12
+ test_run_id = test_run['actionResult']['testsRef']['id']['_value']
13
+ all_tests = Helper::XcresultToJunitHelper.load_object(params[:xcresult_path], test_run_id)['summaries']['_values'][0]['testableSummaries']['_values']
14
+ test_suites = []
15
+ all_tests.each do |target|
16
+ target_name = target['targetName']['_value']
17
+ unless target['tests']
18
+ failure_summary = target['failureSummaries']['_values'][0]
19
+ test_suites << { name: target_name, error: failure_summary['message']['_value'] }
20
+ next
21
+ end
22
+ test_classes = target['tests']['_values'][0]['subtests']['_values'][0]['subtests']['_values']
23
+ test_classes.each do |test_class|
24
+ suite = { name: "#{target_name}.#{test_class['name']['_value']}", cases: [] }
25
+ if test_class['subtests']
26
+ test_class['subtests']['_values'].each do |test|
27
+ duration = 0
28
+ duration = test['duration']['_value'] if test['duration']
29
+ testcase = { name: test['name']['_value'], time: duration }
30
+ if test['testStatus']['_value'] == 'Failure'
31
+ failure = Helper::XcresultToJunitHelper.load_object(params[:xcresult_path], test['summaryRef']['id']['_value'])['failureSummaries']['_values'][0]
32
+ filename = failure['fileName']['_value']
33
+ message = failure['message']['_value']
34
+ if filename == '<unknown>'
35
+ testcase[:error] = message
36
+ else
37
+ testcase[:failure] = message
38
+ testcase[:failure_location] = "#{filename}:#{failure['lineNumber']['_value']}"
39
+ end
40
+ end
41
+ suite[:cases] << testcase
42
+ end
43
+ end
44
+ suite[:count] = suite[:cases].size
45
+ suite[:failures] = suite[:cases].count { |testcase| testcase[:failure] }
46
+ suite[:errors] = suite[:cases].count { |testcase| testcase[:error] }
47
+ test_suites << suite
48
+ end
49
+ end
50
+ junit_folder = Helper::XcresultToJunitHelper.save_device_details_to_file(params[:output_path], test_run['runDestination'])
51
+ Helper::XcresultToJunitHelper.generate_junit(junit_folder, test_suites)
52
+ end
53
+ end
54
+ UI.message("The xcresult_to_junit plugin has finished!")
55
+ end
56
+
57
+ def self.description
58
+ "Produces junit xml files from Xcode 11+ xcresult files"
59
+ end
60
+
61
+ def self.authors
62
+ ["Shane Birdsall"]
63
+ end
64
+
65
+ def self.return_value
66
+ # If your method provides a return value, you can describe here what it does
67
+ end
68
+
69
+ def self.details
70
+ "By using the xcresulttool this plugin parses xcresult files and generates junit reports to be used with other tools to display iOS test results"
71
+ end
72
+
73
+ def self.available_options
74
+ [
75
+ FastlaneCore::ConfigItem.new(key: :xcresult_path,
76
+ env_name: "XCRESULT_TO_JUNIT_XCRESULT_PATH",
77
+ description: "The path to the xcresult file",
78
+ optional: false,
79
+ type: String),
80
+ FastlaneCore::ConfigItem.new(key: :output_path,
81
+ env_name: "XCRESULT_TO_JUNIT_OUTPUT_PATH",
82
+ description: "The path where the output will be placed",
83
+ optional: false,
84
+ type: String)
85
+ ]
86
+ end
87
+
88
+ def self.is_supported?(platform)
89
+ [:ios, :mac].include?(platform)
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,106 @@
1
+ require 'fastlane_core/ui/ui'
2
+ require 'json'
3
+ require 'fileutils'
4
+
5
+ module Fastlane
6
+ UI = FastlaneCore::UI unless Fastlane.const_defined?("UI")
7
+
8
+ module Helper
9
+ class XcresultToJunitHelper
10
+ def self.load_object(xcresult_path, id)
11
+ JSON.load FastlaneCore::CommandExecutor.execute(command: "xcrun xcresulttool get --format json --path #{xcresult_path} --id #{id}")
12
+ end
13
+
14
+ def self.load_results(xcresult_path)
15
+ JSON.load FastlaneCore::CommandExecutor.execute(command: "xcrun xcresulttool get --format json --path #{xcresult_path}")
16
+ end
17
+
18
+ def self.save_device_details_to_file(output_path, device_destination)
19
+ device_udid = device_destination['targetDeviceRecord']['identifier']['_value']
20
+ device_details = {
21
+ 'udid' => device_udid,
22
+ 'name' => device_destination['targetDeviceRecord']['modelName']['_value'],
23
+ 'os' => device_destination['targetDeviceRecord']['operatingSystemVersion']['_value']
24
+ }.to_json
25
+
26
+ junit_folder = "#{output_path}/ios-#{device_udid}.junit"
27
+ FileUtils.rm_rf junit_folder
28
+ FileUtils.mkdir junit_folder
29
+ File.open("#{junit_folder}/device.json", 'w') do |f|
30
+ f << device_details
31
+ end
32
+ return junit_folder
33
+ end
34
+
35
+ def self.junit_file_start
36
+ puts '<?xml version="1.0" encoding="UTF-8"?>'
37
+ puts '<testsuites>'
38
+ end
39
+
40
+ def self.junit_file_end
41
+ puts '</testsuites>'
42
+ end
43
+
44
+ def self.junit_suite_error(suite)
45
+ puts "<testsuite name=#{suite[:name].encode xml: :attr} errors='1'>"
46
+ puts "<error>#{suite[:error].encode xml: :text}</error>"
47
+ end
48
+
49
+ def self.junit_suite_start(suite)
50
+ puts "<testsuite name=#{suite[:name].encode xml: :attr} tests='#{suite[:count]}' failures='#{suite[:failures]}' errors='#{suite[:errors]}'>"
51
+ end
52
+
53
+ def self.junit_suite_end
54
+ puts '</testsuite>'
55
+ end
56
+
57
+ def self.junit_testcase_start(suite, testcase)
58
+ print "<testcase classname=#{suite[:name].encode xml: :attr} name=#{testcase[:name].encode xml: :attr} time='#{testcase[:time]}'"
59
+ end
60
+
61
+ def self.junit_testcase_success
62
+ puts '/>'
63
+ end
64
+
65
+ def self.junit_testcase_failure(testcase)
66
+ puts '>'
67
+ puts "<failure message=#{testcase[:failure].encode xml: :attr}>#{testcase[:failure_location].encode xml: :text}</failure>"
68
+ puts '</testcase>'
69
+ end
70
+
71
+ def self.junit_testcase_error(testcase)
72
+ puts '>'
73
+ puts "<error>#{testcase[:error].encode xml: :text}</error>"
74
+ puts '</testcase>'
75
+ end
76
+
77
+ def self.generate_junit(junit_folder, test_suites)
78
+ File.open("#{junit_folder}/results.xml", 'w') do |fo|
79
+ old_stdout = $stdout
80
+ $stdout = fo
81
+ Helper::XcresultToJunitHelper.junit_file_start()
82
+ test_suites.each do |suite|
83
+ if suite[:error]
84
+ Helper::XcresultToJunitHelper.junit_suite_error(suite)
85
+ else
86
+ Helper::XcresultToJunitHelper.junit_suite_start(suite)
87
+ suite[:cases].each do |testcase|
88
+ Helper::XcresultToJunitHelper.junit_testcase_start(suite, testcase)
89
+ if testcase[:failure]
90
+ Helper::XcresultToJunitHelper.junit_testcase_failure(testcase)
91
+ elsif testcase[:error]
92
+ Helper::XcresultToJunitHelper.junit_testcase_error(testcase)
93
+ else
94
+ Helper::XcresultToJunitHelper.junit_testcase_success()
95
+ end
96
+ end
97
+ end
98
+ Helper::XcresultToJunitHelper.junit_suite_end()
99
+ end
100
+ Helper::XcresultToJunitHelper.junit_file_end()
101
+ $stdout = old_stdout
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,5 @@
1
+ module Fastlane
2
+ module XcresultToJunit
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,174 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fastlane-plugin-xcresult_to_junit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Shane Birdsall
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-11-13 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: rubocop-require_tools
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: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: fastlane
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: 2.134.0
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: 2.134.0
139
+ description:
140
+ email: shane.birdsall@fiserv.com
141
+ executables: []
142
+ extensions: []
143
+ extra_rdoc_files: []
144
+ files:
145
+ - LICENSE
146
+ - README.md
147
+ - lib/fastlane/plugin/xcresult_to_junit.rb
148
+ - lib/fastlane/plugin/xcresult_to_junit/actions/xcresult_to_junit_action.rb
149
+ - lib/fastlane/plugin/xcresult_to_junit/helper/xcresult_to_junit_helper.rb
150
+ - lib/fastlane/plugin/xcresult_to_junit/version.rb
151
+ homepage: https://github.com/zanizrules/fastlane-plugin-xcresult_to_junit
152
+ licenses:
153
+ - MIT
154
+ metadata: {}
155
+ post_install_message:
156
+ rdoc_options: []
157
+ require_paths:
158
+ - lib
159
+ required_ruby_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ requirements: []
170
+ rubygems_version: 3.0.2
171
+ signing_key:
172
+ specification_version: 4
173
+ summary: Produces junit xml files from Xcode 11+ xcresult files
174
+ test_files: []