fastlane-plugin-checks 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9e53f0bf24653288d90b48cd516107f9a1151bc4d11f22eda6eb21273907c730
4
+ data.tar.gz: 305a234ad41be4613d79ccdd7b3b56f04540f4889d8d7cae8930d44e13980b3c
5
+ SHA512:
6
+ metadata.gz: 8320e00ecdb4686bfe72775111895450947462d248ba3ad53e97477885866a69777add3033510827e155c0e54cd94162d82f2636c4ab1ebb1dade615de7ec520
7
+ data.tar.gz: 8faab11217afddca2b184a3c892a7719ccf2cbb3c3975ccd34719bbbeafc902a1e13b9eeb02724d888fee1456222340bfbdf8ba3f6754359b86a542aa919a1be
data/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,84 @@
1
+ # checks plugin
2
+
3
+ [![fastlane Plugin Badge](https://rawcdn.githack.com/fastlane/fastlane/master/fastlane/assets/plugin-badge.svg)](https://rubygems.org/gems/fastlane-plugin-checks)
4
+
5
+ ## Getting Started
6
+
7
+ This project is a [*fastlane*](https://github.com/fastlane/fastlane) plugin for
8
+ [Checks](https://checks.google.com). To get started with
9
+ `fastlane-plugin-checks`, add it to your project by running:
10
+
11
+ ```bash
12
+ fastlane add_plugin checks
13
+ ```
14
+
15
+ ## About upload_to_checks
16
+
17
+ Minimum way to use upload_to_checks with the required parameters:
18
+
19
+ ```
20
+ upload_to_checks(
21
+ account_id: "<your Checks account ID>",
22
+ app_id: "<your Checks app ID>",
23
+ binary_path: "<path to your .apk/.aab/.ipa>",
24
+ service_account_file_path: "<path to your service account JSON>",
25
+ )
26
+ ```
27
+
28
+ List of all parameters:
29
+
30
+ ## Variables
31
+
32
+ Name | Type | Default | Description
33
+ :-----------------------: | :-----: | :-----: | :---------:
34
+ service_account_file_path | string | – | Path to your serviceaccount.json file. Please refer to [Authenticate Google Checks](https://developers.google.com/checks/guide/integrate/cli/install-checks-cli#authenticate-service) with a service account to generate a service account.
35
+ account_id | string | – | Google Checks account ID from [Checks settings page](https://checks.area120.google.com/console/settings)
36
+ app_id | string | – | Google Checks application ID
37
+ binary_path | string | – | path to the application binary file: .apk, .aab or .ipa
38
+ generate_report | boolean | true | If `false` the action won't upload and run the report for binary_path. It is useful to test your authentication and other paramaters.
39
+ wait_for_report | boolean | true | If `false` the action won't wait for the report completion and the build will keep going.
40
+ severity_threshold | string | – | Valid values are: `PRIORITY` `POTENTIAL` `OPPORTUNITY`
41
+ fail_on | string | – | if `all` then action will fail if there are any failed checks following `severity_threshold` condition. It won't fail by default.
42
+ operation_id | string | – | For development and testing purposes. If an upload is already in progress, or you want to analyse an existing upload.
43
+
44
+ ## Example
45
+
46
+ Check out the [example `Fastfile`](fastlane/Fastfile) to see how to use this
47
+ plugin. Try it by cloning the repo, running `fastlane install_plugins` and
48
+ `bundle exec fastlane test`.
49
+
50
+ ## Run tests for this plugin
51
+
52
+ To run both the tests, and code style validation, run
53
+
54
+ ```
55
+ rake
56
+ ```
57
+
58
+ To automatically fix many of the styling issues, use
59
+
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
67
+ repository.
68
+
69
+ ## Troubleshooting
70
+
71
+ If you have trouble using plugins, check out the
72
+ [Plugins Troubleshooting](https://docs.fastlane.tools/plugins/plugins-troubleshooting/)
73
+ guide.
74
+
75
+ ## Using *fastlane* Plugins
76
+
77
+ For more information about how the `fastlane` plugin system works, check out the
78
+ [Plugins documentation](https://docs.fastlane.tools/plugins/create-plugin/).
79
+
80
+ ## About *fastlane*
81
+
82
+ *fastlane* is the easiest way to automate beta deployments and releases for your
83
+ iOS and Android apps. To learn more, check out
84
+ [fastlane.tools](https://fastlane.tools).
@@ -0,0 +1,133 @@
1
+ # Copyright 2024 Google LLC
2
+
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'fastlane_core/ui/ui'
16
+ require 'fastlane/action'
17
+ require 'tty-spinner'
18
+ require 'json'
19
+ require 'pry'
20
+
21
+ require_relative '../helper/credentials'
22
+ require_relative '../helper/checks_service'
23
+ require_relative '../helper/report_parser'
24
+ require_relative '../options'
25
+
26
+ module Fastlane
27
+ UI = FastlaneCore::UI unless Fastlane.const_defined?(:UI)
28
+ module Actions
29
+ class UploadToChecksAction < Action
30
+ def self.run(params) # rubocop:disable Metrics/PerceivedComplexity
31
+ # required parameters
32
+ service_account_file_path = params[:service_account_file_path]
33
+ project_id = params[:project_id]
34
+ account_id = params[:account_id]
35
+ app_id = params[:app_id]
36
+ binary_path = params[:binary_path]
37
+
38
+ # optional parameters
39
+ fail_on = params[:fail_on]
40
+ operation_id = params[:operation_id]
41
+ generate_report = params[:generate_report]
42
+ wait_for_report = params[:wait_for_report]
43
+ severity_threshold = params[:severity_threshold]
44
+
45
+ credentials = Fastlane::Checks::Credentials.new(key_file_path: service_account_file_path)
46
+ service = Fastlane::Checks::GoogleChecksService.new(credentials, project_id, account_id, app_id)
47
+
48
+ if generate_report
49
+ if operation_id.nil?
50
+ upload_spinner = TTY::Spinner.new("[:spinner] Uploading #{binary_path} to Google Checks...", format: :dots)
51
+ upload_spinner.auto_spin
52
+ begin
53
+ upload_response = service.upload_binary(binary_path)
54
+ rescue StandardError => e
55
+ UI.error(e)
56
+ UI.abort_with_message!("Error while uploading binary")
57
+ end
58
+ upload_spinner.success("Done")
59
+ end
60
+
61
+ if wait_for_report == false
62
+ UI.success("Skipping waiting for the report. Please visit https://checks.google.com to see the report.")
63
+ else
64
+ if operation_id.nil?
65
+ operation_id = Fastlane::Checks::GoogleChecksService.operation_id_from_name(upload_response["name"])
66
+ end
67
+
68
+ waiting_spinner = TTY::Spinner.new("[:spinner] Waiting for the report for operation id=#{operation_id}", format: :dots)
69
+ waiting_spinner.auto_spin
70
+
71
+ report_id, operation_response = service.wait_for_report(operation_id)
72
+
73
+ if report_id.nil?
74
+ waiting_spinner.error("Done")
75
+ UI.abort_with_message!("Failed to fetch the report")
76
+ else
77
+ waiting_spinner.success("Done")
78
+ report_response = service.report(report_id)
79
+ report_parser = Fastlane::Checks::ReportParser.new(severity_threshold)
80
+ failing_checks = report_parser.parse(report_response)
81
+ if failing_checks.empty? # rubocop:disable Metrics/BlockNesting
82
+ UI.success("No issues # rubocop:disable Metrics/BlockNestingdetected")
83
+ UI.success("Report console URL: #{operation_response['response']['resultsUri']}")
84
+ else
85
+ UI.error("#{failing_checks.length} issues detected:")
86
+ failing_checks.each do |check|
87
+ UI.error("Type: #{check['type']}. Details: #{check}")
88
+ end
89
+ if fail_on == 'all' # rubocop:disable Metrics/BlockNesting
90
+ UI.test_failure!("Report console URL: #{operation_response['response']['resultsUri']}")
91
+ else
92
+ UI.important("Report console URL: #{operation_response['response']['resultsUri']}")
93
+ end
94
+ end
95
+ end
96
+ end
97
+ else
98
+ response = service.apps_list
99
+ UI.message(response)
100
+ end
101
+ end
102
+
103
+ def self.description
104
+ "upload to checks"
105
+ end
106
+
107
+ def self.authors
108
+ ["boertel"]
109
+ end
110
+
111
+ def self.return_value
112
+ # If your method provides a return value, you can describe here what it does
113
+ end
114
+
115
+ def self.details
116
+ # Optional:
117
+ "upload to checks your mobile app"
118
+ end
119
+
120
+ def self.available_options
121
+ Fastlane::Checks::Options.available_options
122
+ end
123
+
124
+ def self.is_supported?(platform)
125
+ # Adjust this if your plugin only works for a particular platform (iOS vs. Android, for example)
126
+ # See: https://docs.fastlane.tools/advanced/#control-configuration-by-lane-and-by-platform
127
+ #
128
+ # [:ios, :mac, :android].include?(platform)
129
+ true
130
+ end
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,109 @@
1
+ # Copyright 2024 Google LLC
2
+
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'faraday'
16
+ require 'googleauth'
17
+
18
+ module Fastlane
19
+ module Checks
20
+ class GoogleChecksService
21
+ BASE_URL = "https://checks.googleapis.com"
22
+ OAUTH_SCOPES = ["https://www.googleapis.com/auth/checks"]
23
+ DEFAULT_TIMEOUT = 45 * 60 # 30 minutes
24
+ CHECK_OPERATION_INTERVAL = 60 # 1 minute
25
+
26
+ private_constant :BASE_URL
27
+ private_constant :DEFAULT_TIMEOUT
28
+ private_constant :CHECK_OPERATION_INTERVAL
29
+
30
+ def initialize(credentials, project_id, account_id, app_id)
31
+ @account_id = account_id
32
+ @app_id = app_id
33
+ @auth = credentials.get_google_credential(OAUTH_SCOPES)
34
+ @project_id ||= @auth.project_id
35
+
36
+ default_headers = @auth.apply({})
37
+ default_headers["X-Goog-User-Project"] = @project_id
38
+ @connection = Faraday.new(url: BASE_URL, headers: default_headers)
39
+ end
40
+
41
+ def apps_list
42
+ get("/v1alpha/accounts/#{@account_id}/apps/")
43
+ end
44
+
45
+ def upload_binary(binary_path)
46
+ binary_data = File.binread(binary_path)
47
+ path = "/upload/v1alpha/accounts/#{@account_id}/apps/#{@app_id}/reports:analyzeUpload"
48
+ response = @connection.post(path) do |req|
49
+ req.headers['X-Goog-Upload-Protocol'] = 'raw'
50
+ req.headers['Content-Type'] = 'application/octet-stream'
51
+ req.body = binary_data
52
+ end
53
+ handle_response(response)
54
+ end
55
+
56
+ def check_operation(operation_id)
57
+ get("/v1alpha/accounts/#{@account_id}/apps/#{@app_id}/operations/#{operation_id}")
58
+ end
59
+
60
+ def report(report_id)
61
+ params = {
62
+ "fields" => "name,checks(type,state,severity)"
63
+ }
64
+ get("/v1alpha/accounts/#{@account_id}/apps/#{@app_id}/reports/#{report_id}", params)
65
+ end
66
+
67
+ def get(path, params = {})
68
+ response = @connection.get(path, params)
69
+ handle_response(response)
70
+ end
71
+
72
+ def wait_for_report(operation_id)
73
+ started_at = Time.now
74
+ operation_response = nil
75
+ loop do
76
+ operation_response = check_operation(operation_id)
77
+ has_timeout = Time.now - started_at > DEFAULT_TIMEOUT
78
+ break if operation_response["done"] || has_timeout
79
+
80
+ sleep(CHECK_OPERATION_INTERVAL)
81
+ end
82
+ if operation_response["response"]
83
+ [
84
+ GoogleChecksService.report_id_from_name(operation_response["response"]["name"]),
85
+ operation_response
86
+ ]
87
+ end
88
+ end
89
+
90
+ def self.operation_id_from_name(name)
91
+ name.split("/").last
92
+ end
93
+
94
+ def self.report_id_from_name(name)
95
+ name.split("/").last
96
+ end
97
+
98
+ private
99
+
100
+ def handle_response(response)
101
+ if response.success?
102
+ JSON.parse(response.body)
103
+ else
104
+ raise "HTTP request to checks.google.com failed with\nstatus: #{response.status}\nbody:\n#{response.body}"
105
+ end
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,41 @@
1
+ # Copyright 2024 Google LLC
2
+
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'googleauth'
16
+ require 'fastlane_core/ui/ui'
17
+
18
+ module Fastlane
19
+ UI = FastlaneCore::UI unless Fastlane.const_defined?(:UI)
20
+ module Checks
21
+ class Credentials
22
+ def initialize(key_file_path: nil)
23
+ @key_file_path = key_file_path
24
+ end
25
+
26
+ def get_google_credential(scopes)
27
+ File.open(File.expand_path(@key_file_path), "r") do |file|
28
+ options = {
29
+ json_key_io: file,
30
+ scope: scopes
31
+ }
32
+ begin
33
+ return Google::Auth::ServiceAccountCredentials.make_creds(options)
34
+ rescue StandardError => e
35
+ UI.abort_with_message!("Failed to read service account file: #{e.message}")
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,50 @@
1
+ # Copyright 2024 Google LLC
2
+
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ module Fastlane
16
+ module Checks
17
+ class ReportParser
18
+ OPPORTUNITY = "OPPORTUNITY"
19
+ POTENTIAL = "POTENTIAL"
20
+ PRIORITY = "PRIORITY"
21
+
22
+ public_constant :OPPORTUNITY, :POTENTIAL, :PRIORITY
23
+
24
+ def initialize(severity_threshold)
25
+ @severity_threshold = severity_threshold
26
+ end
27
+
28
+ def is_severity_included_in_threshold(severity)
29
+ case @severity_threshold
30
+ when OPPORTUNITY
31
+ return severity == PRIORITY || severity == POTENTIAL || severity == OPPORTUNITY
32
+ when POTENTIAL
33
+ return severity == PRIORITY || severity == POTENTIAL
34
+ when PRIORITY
35
+ return severity == PRIORITY
36
+ end
37
+ end
38
+
39
+ def parse(report)
40
+ failing_checks = []
41
+ report["checks"].each do |check|
42
+ if check['state'] == "FAILED" && is_severity_included_in_threshold(check['severity'])
43
+ failing_checks << check
44
+ end
45
+ end
46
+ return failing_checks
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,80 @@
1
+ # Copyright 2024 Google LLC
2
+
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'fastlane_core/ui/ui'
16
+ require 'fastlane_core/configuration/config_item'
17
+
18
+ module Fastlane
19
+ UI = FastlaneCore::UI unless Fastlane.const_defined?(:UI)
20
+ module Checks
21
+ class Options
22
+ def self.available_options
23
+ [
24
+ FastlaneCore::ConfigItem.new(key: :service_account_file_path,
25
+ description: "Path to your service account json file. Please refer to https://developers.google.com/checks/guide/integrate/cli/install-checks-cli#authenticate-service to get your private key JSON file",
26
+ optional: false,
27
+ verify_block: proc do |value|
28
+ UI.user_error!("Could not find file at path '#{value}'") unless File.exist?(value)
29
+ end),
30
+ FastlaneCore::ConfigItem.new(key: :project_id,
31
+ description: "Google Cloud Platform project name",
32
+ optional: true),
33
+ FastlaneCore::ConfigItem.new(key: :account_id,
34
+ description: "Google Checks Account Id",
35
+ optional: false),
36
+ FastlaneCore::ConfigItem.new(key: :app_id,
37
+ description: "Google Checks App Id",
38
+ optional: false),
39
+ FastlaneCore::ConfigItem.new(key: :operation_id,
40
+ description: "Operation ID",
41
+ optional: true),
42
+ FastlaneCore::ConfigItem.new(key: :severity_threshold,
43
+ description: "severity threshold. Possible values: PRIORITY, POTENTIAL, OPPORTUNITY",
44
+ default_value: "PRIORITY",
45
+ optional: true,
46
+ verify_block: proc do |value|
47
+ UI.user_error!("Invalid value '#{value}'") unless ['PRIORITY', 'POTENTIAL', 'OPPORTUNITY'].include?(value)
48
+ end),
49
+ FastlaneCore::ConfigItem.new(key: :binary_path,
50
+ description: "Path to the app",
51
+ optional: false,
52
+ verify_block: proc do |value|
53
+ UI.user_error!("App file not found at path '#{value}'") unless File.exist?(value)
54
+ end),
55
+ FastlaneCore::ConfigItem.new(key: :generate_report,
56
+ description: "skip generating report",
57
+ default_value: true,
58
+ type: Fastlane::Boolean),
59
+ FastlaneCore::ConfigItem.new(key: :wait_for_report,
60
+ description: "Wait for report to complete",
61
+ default_value: true,
62
+ type: Fastlane::Boolean),
63
+ FastlaneCore::ConfigItem.new(key: :fail_on,
64
+ description: "action will fail if the report contains issues with severity equal or higher than the specified value. Possible values: all, never",
65
+ default_value: "never",
66
+ type: String,
67
+ verify_block: proc do |value|
68
+ UI.user_error!("Invalid value '#{value}'") unless ['all', 'never'].include?(value)
69
+ end)
70
+ ]
71
+ end
72
+
73
+ def self.set_default_property(hash_obj, property, default)
74
+ unless hash_obj.key?(property)
75
+ hash_obj[property] = default
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,19 @@
1
+ # Copyright 2024 Google LLC
2
+
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ module Fastlane
16
+ module Checks
17
+ VERSION = "0.1.0"
18
+ end
19
+ end
@@ -0,0 +1,30 @@
1
+ # Copyright 2024 Google LLC
2
+
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'fastlane/plugin/checks/version'
16
+
17
+ module Fastlane
18
+ module Checks
19
+ # Return all .rb files inside the "actions" and "helper" directory
20
+ def self.all_classes
21
+ Dir[File.expand_path('**/{actions,helper}/*.rb', File.dirname(__FILE__))]
22
+ end
23
+ end
24
+ end
25
+
26
+ # By default we want to import all available actions and helpers
27
+ # A plugin can contain any number of actions and plugins
28
+ Fastlane::Checks.all_classes.each do |current|
29
+ require current
30
+ end
metadata ADDED
@@ -0,0 +1,248 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fastlane-plugin-checks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sherzat Aitbayev
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-03-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
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
+ - !ruby/object:Gem::Dependency
28
+ name: googleauth
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: tty-spinner
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
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: bundler
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: fastlane
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 2.217.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 2.217.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
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: rake
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: rspec
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: rspec_junit_formatter
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: rubocop
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '='
144
+ - !ruby/object:Gem::Version
145
+ version: 1.50.2
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '='
151
+ - !ruby/object:Gem::Version
152
+ version: 1.50.2
153
+ - !ruby/object:Gem::Dependency
154
+ name: rubocop-performance
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: rubocop-require_tools
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: simplecov
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: webmock
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
209
+ description:
210
+ email:
211
+ executables: []
212
+ extensions: []
213
+ extra_rdoc_files: []
214
+ files:
215
+ - LICENSE
216
+ - README.md
217
+ - lib/fastlane/plugin/checks.rb
218
+ - lib/fastlane/plugin/checks/actions/upload_to_checks.rb
219
+ - lib/fastlane/plugin/checks/helper/checks_service.rb
220
+ - lib/fastlane/plugin/checks/helper/credentials.rb
221
+ - lib/fastlane/plugin/checks/helper/report_parser.rb
222
+ - lib/fastlane/plugin/checks/options.rb
223
+ - lib/fastlane/plugin/checks/version.rb
224
+ homepage: https://github.com/google-checks/checks-fastlane-plugin
225
+ licenses:
226
+ - Apache-2.0
227
+ metadata:
228
+ rubygems_mfa_required: 'true'
229
+ post_install_message:
230
+ rdoc_options: []
231
+ require_paths:
232
+ - lib
233
+ required_ruby_version: !ruby/object:Gem::Requirement
234
+ requirements:
235
+ - - ">="
236
+ - !ruby/object:Gem::Version
237
+ version: '2.6'
238
+ required_rubygems_version: !ruby/object:Gem::Requirement
239
+ requirements:
240
+ - - ">="
241
+ - !ruby/object:Gem::Version
242
+ version: '0'
243
+ requirements: []
244
+ rubygems_version: 3.5.6
245
+ signing_key:
246
+ specification_version: 4
247
+ summary: Fastlane plugin for Checks (checks.google.com)
248
+ test_files: []