fastlane-plugin-forsis 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3a499e26fa89aecf81bff1f092e457f5186536b5
4
+ data.tar.gz: ede699091b2c249e8e04525a3c0daae990b8f97d
5
+ SHA512:
6
+ metadata.gz: 37f3ff83e608a82270eaa581866f4a8ec431831663759b5e71549d3bc21ca7ac0dfd48615bdd21f54f8dcb14e291322a17265f4267240879c9845bcfc26d8a1d
7
+ data.tar.gz: 4e9671d65a7c7db11e3abd878063be472b80eb16354ac0f1aea26c7ded99992c984e8a0eb620642437f0058175809b33312f7779efbca63a9583dd2f8ef41af9
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Azohra/forsis
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.
data/README.md ADDED
@@ -0,0 +1,105 @@
1
+ # forsis plugin
2
+
3
+ [![fastlane Plugin Badge](https://rawcdn.githack.com/fastlane/fastlane/master/fastlane/assets/plugin-badge.svg)](https://rubygems.org/gems/fastlane-plugin-forsis)
4
+
5
+ **forsis** is a [_fastlane_](https://github.com/fastlane/fastlane) plugin that will be helpful to those swift developers who use SonarQube to analyze their code. forsis uses JUnit test reports generated by fastlane to produce generic test execution reports supported by SonarQube.
6
+
7
+ If you have used SonarQube for analyzing Swift projects, you've probably noticed that other than the code coverage, you don't get any information related to the unit tests appearing on the project dashboard. This plugin, however, will help you get more visibility on the unit tests by generating a test report that can be analyzed by SonarQube. By sending such a test report to SonarQube, the total number of unit tests will be displayed on the project dashboard as shown in the following image.
8
+
9
+ <img src="docs/SonarQube-dashboard.png" />
10
+
11
+ In addidtion, you can see a breakdown of test results under project Measures > Coverage > Tests. Alternatively, you can select the test count on the dashbord (by clicking it) to see the test results as shown in the image below.
12
+
13
+ <img src="docs/test-results.png" />
14
+
15
+ ## Getting Started
16
+
17
+ To get started with `fastlane-plugin-forsis`, add it to your project by running:
18
+
19
+ ```bash
20
+ fastlane add_plugin forsis
21
+ ```
22
+ Start using the plugin by adding this example 'lane' to your Fastfile:
23
+
24
+ ```ruby
25
+ lane :sonarqube_test_report do
26
+ forsis(
27
+ junit_report_file: './fastlane/report.junit',
28
+ sonar_report_directory: 'path_to_a_directory_to_store_sonarqube_report'
29
+ )
30
+ end
31
+ ```
32
+ * `junit_report_file` is the path to the JUnit test report generated by fastlane
33
+ * `sonar_report_directory` is the directory to store the generated SonarQube report. This parameter is optional and the defaut value is the fastlane directory in the main repo (*i.e.*, `./fastlane`).
34
+
35
+ **Note:** This plugin uses the fastlane JUnit test report named `report.junit`. This report is generated by running tests through fastlane using `run_tests` or `scan` actions. Therefore, in your Fastfile, the forsis lane must be run after the lane that runs the tests. Including the test lane, your Fastfile would look like the example below.
36
+
37
+ ```ruby
38
+ lane :run_unit_tests do
39
+ run_tests(
40
+ workspace: 'path_to_the_xcworkspace_directory',
41
+ scheme: 'path_to_the_project_test_scheme',
42
+ devices: ["iPhone 6s"],
43
+ # output_types: 'junit',
44
+ output_directory: './fastlane/test_output',
45
+ )
46
+ end
47
+
48
+ lane :sonarqube_test_report do
49
+ forsis(
50
+ junit_report_file: './fastlane/test_output/report.junit',
51
+ sonar_report_directory: './fastlane'
52
+ )
53
+ end
54
+ ```
55
+
56
+ The `run_tests` action generates a test report in two different formats by default (html and junit). (Note: the `scan` method is an alias for the `run_tests` method.) If you would not like to get the html report, you can override this default behavior by setting the parameter `output_types` to only 'junit'. In the example `:run_unit_tests` lane above, uncomment the line for output_types to only get a JUnit test report. Test reports are then found in the fastlane directory or in the `output_directory` if it has been set. To learn more about how to run tests through fastlane, check out the [fastlane documentation] (https://docs.fastlane.tools/getting-started/ios/running-tests/).
57
+
58
+ ## How to use the SonarQube test report generated by forsis?
59
+ This plugin creates an XML test report called `Test_sonarqube_report.xml`. To get benefit from this report, you need to feed it to SonarQube properly. To do so, you need to set the two following SonarQube analysis parameters:
60
+
61
+ * `sonar.tests` is the path to the directory that contains tests
62
+ * `sonar.testExecutionReportPaths` is the path to the SonarQube test report file generated by the plugin *i.e.*, the value of the `sonar_report_directory` in the forsis action followed by the name of the XML file that contains the report. This would be `fastlane/Test_sonarqube_report.xml`, if sonar_report_directory was not set.
63
+
64
+ If you need help setting up analysis parameters for SonarQube, refer to the [SonarQube Analysis Parameters](https://docs.sonarqube.org/latest/analysis/analysis-parameters/) documentation.
65
+ ## Run tests for this plugin
66
+
67
+ To run both the tests, and code style validation, run
68
+
69
+ ```
70
+ rake
71
+ ```
72
+
73
+ To automatically fix many of the styling issues, use
74
+ ```
75
+ rubocop -a
76
+ ```
77
+
78
+ ## Troubleshooting
79
+
80
+ If you have trouble using plugins, check out the [Plugins Troubleshooting](https://docs.fastlane.tools/plugins/plugins-troubleshooting/) guide.
81
+
82
+ ## Using _fastlane_ Plugins
83
+
84
+ For more information about how the `fastlane` plugin system works, check out the [Plugins documentation](https://docs.fastlane.tools/plugins/create-plugin/).
85
+
86
+ ## About _fastlane_
87
+
88
+ _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).
89
+ This software is available as open source under the terms of the MIT License.
90
+
91
+ ## Contribution
92
+
93
+ Bug reports and suggestions for improvements are always welcome. PRs are even better!!
94
+
95
+ If you run into any issues, before submitting a new GitHub issue, please make sure to
96
+
97
+ * Check out the entire README on this repo
98
+ * Search for [existing GitHub issues](https://github.com/azohra/forsis/issues)
99
+
100
+ If the above doesn't help, please submit an issue on [GitHub](https://github.com/azohra/forsis/issues). When reporting a bug, please make sure to include a spec that highlights the bug.
101
+
102
+ ## License
103
+
104
+ This software is available as open source under the terms of the MIT License.
105
+
@@ -0,0 +1,16 @@
1
+ require 'fastlane/plugin/forsis/version'
2
+
3
+ module Fastlane
4
+ module Forsis
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::Forsis.all_classes.each do |current|
15
+ require current
16
+ end
@@ -0,0 +1,65 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/forsis_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ class ForsisAction < Action
7
+
8
+ def self.run(params)
9
+ junit_report_path = params[:junit_report_file]
10
+ sonarqube_report_path = params[:sonar_report_directory]
11
+ UI.message("Generating the Sonarqube generic test execution report!")
12
+ Fastlane::Helper::ForsisHelper::Generator.generate(junit_report_path, sonarqube_report_path)
13
+ end
14
+
15
+ def self.description
16
+ "This plugin converts the fastlane-generated junit test report to a sonarqube generic test execution report"
17
+ end
18
+
19
+ def self.authors
20
+ ["Azadeh Bagheri"]
21
+ end
22
+
23
+ def self.details
24
+ "This plugin uses junit test reports generated by fastlane and converts them into the sonarqube generic test execution reports"
25
+ end
26
+
27
+ def self.available_options
28
+ [
29
+ FastlaneCore::ConfigItem.new(
30
+ key: :junit_report_file,
31
+ env_name: "forsis_JUNIT_REPORT",
32
+ description: "The path of the junit test report file used to generate the generic test execution file for sonarqube ",
33
+ optional: false,
34
+ type: String,
35
+ display_in_shell: false,
36
+ verify_block: proc do |path|
37
+ if path == ""
38
+ UI.user_error!("'forsis' action missing the key 'junit_report_path' or its value.")
39
+ else
40
+ UI.user_error!("ERROR: junit report not found at path: #{path}") unless File.exist?(path)
41
+ end
42
+ end
43
+ ),
44
+ FastlaneCore::ConfigItem.new(
45
+ key: :sonar_report_directory,
46
+ env_name: "forsis_SONAR_GENERATED_REPORT",
47
+ description: "The path of the sonarqube test execution report generated from the junit test report",
48
+ optional: true,
49
+ default_value: './fastlane',
50
+ type: String,
51
+ verify_block: proc do |path|
52
+ FileUtils.mkdir_p(path) unless File.directory?(path)
53
+ end
54
+ )
55
+ ]
56
+ end
57
+
58
+ def self.is_supported?(platform)
59
+ [:ios, :mac].include?(platform)
60
+ true
61
+ end
62
+
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,54 @@
1
+ require 'nokogiri'
2
+
3
+ module Fastlane
4
+ module Helper
5
+ module ForsisHelper
6
+ class Generator
7
+ def self.generate(junit_report_path, sonarqube_report_path)
8
+ junit_file = Nokogiri::XML(File.open(junit_report_path))
9
+ sonarqube_file = File.open(sonarqube_report_path + "/Test_sonarqube_report.xml", 'w')
10
+ test_suites = junit_file.xpath("//testsuite")
11
+ builder = Nokogiri::XML::Builder.new do |xml|
12
+ xml.testExecutions({ version: :"1" }) do
13
+ test_suites.each do |test_file|
14
+ file_name = `echo #{test_file["name"]}| cut -d'.' -f 2`.gsub(/\n/, '')
15
+ file_path = get_test_file_path(file_name)
16
+ test_cases = []
17
+ test_file.children.each do |child|
18
+ test_cases << child if child.class == Nokogiri::XML::Element
19
+ end
20
+ xml.file({ path: :"#{file_path}" }) do
21
+ test_cases.each do |test|
22
+ test_duration = (test["time"].to_f * 1000).round
23
+ test_failures = []
24
+ test.children.each do |test_child|
25
+ test_failures << test_child if test_child.class == Nokogiri::XML::Element
26
+ end
27
+ xml.testCase({ name: :"#{test["name"]}", duration: :"#{test_duration}" }) do
28
+ test_failures.each do |failure|
29
+ failure_type = failure.name
30
+ failure_message = failure["message"]
31
+ failure_description = failure.text
32
+ xml.send(failure_type, failure_description, message: failure_message)
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ sonarqube_file.puts(builder.to_xml)
41
+ sonarqube_file.close
42
+ end
43
+
44
+ def self.get_test_file_path(file_name)
45
+ `find . -iname "#{file_name}.swift"`.gsub(/\n/, '')
46
+ end
47
+ end
48
+
49
+ def self.show_message
50
+ UI.message("Hello from the forsis plugin helper!")
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,5 @@
1
+ module Fastlane
2
+ module Forsis
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,190 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fastlane-plugin-forsis
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Azadeh Bagheri
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-03-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
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: fastlane
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.111.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 2.111.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: nokogiri
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 1.9.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 1.9.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
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: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec_junit_formatter
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: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.65.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.65.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop-require_tools
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: simplecov
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description:
154
+ email: Azadeh.Bagheri@loblaw.ca
155
+ executables: []
156
+ extensions: []
157
+ extra_rdoc_files: []
158
+ files:
159
+ - LICENSE
160
+ - README.md
161
+ - lib/fastlane/plugin/forsis.rb
162
+ - lib/fastlane/plugin/forsis/actions/forsis_action.rb
163
+ - lib/fastlane/plugin/forsis/helper/forsis_helper.rb
164
+ - lib/fastlane/plugin/forsis/version.rb
165
+ homepage: https://github.com/azohra/forsis
166
+ licenses:
167
+ - MIT
168
+ metadata: {}
169
+ post_install_message:
170
+ rdoc_options: []
171
+ require_paths:
172
+ - lib
173
+ required_ruby_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ required_rubygems_version: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
183
+ requirements: []
184
+ rubyforge_project:
185
+ rubygems_version: 2.6.11
186
+ signing_key:
187
+ specification_version: 4
188
+ summary: This plugin converts junit test reports to gthe sonarqube generic test execution
189
+ report
190
+ test_files: []