fastlane-plugin-periphery 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
+ SHA256:
3
+ metadata.gz: 193810e605fc8f7f7f7285417cab60d865e5654b33c0e773ef616680a7303dfa
4
+ data.tar.gz: 4a0bdb31f320deee68c070247b9387f8ca80f9ef77ca98e42a019eb1815d150d
5
+ SHA512:
6
+ metadata.gz: 7b986b0b8bb0269d3ce1c090447ce07cd06273099ae9e54b4bd4aa804421457580ae5a186ceec22b319d252667844886c2167b7185257cbe2abfdf148f66ed31
7
+ data.tar.gz: 80ebe6ecb9e9bf1bfbced75300d54f8368996eb73925992b77cb5c8bbe9baf4bd2d124c7725236284caafff9acb462e9579f5b93623672bd00f9795cd4101df8
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Liam Nichols <liam.nichols.ln@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.
data/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # periphery plugin
2
+
3
+ [![fastlane Plugin Badge](https://rawcdn.githack.com/fastlane/fastlane/master/fastlane/assets/plugin-badge.svg)](https://rubygems.org/gems/fastlane-plugin-periphery)
4
+
5
+ ## Getting Started
6
+
7
+ This project is a [_fastlane_](https://github.com/fastlane/fastlane) plugin. To get started with `fastlane-plugin-periphery`, add it to your project by running:
8
+
9
+ ```bash
10
+ fastlane add_plugin periphery
11
+ ```
12
+
13
+ ## About periphery
14
+
15
+ Identifies unused code in Swift projects using Periphery
16
+
17
+ **Note to author:** Add a more detailed description about this plugin here. If your plugin contains multiple actions, make sure to mention them here.
18
+
19
+ ## Example
20
+
21
+ 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`.
22
+
23
+ **Note to author:** Please set up a sample project to make it easy for users to explore what your plugin does. Provide everything that is necessary to try out the plugin in this project (including a sample Xcode/Android project if necessary)
24
+
25
+ ## Run tests for this plugin
26
+
27
+ To run both the tests, and code style validation, run
28
+
29
+ ```
30
+ rake
31
+ ```
32
+
33
+ To automatically fix many of the styling issues, use
34
+ ```
35
+ rubocop -a
36
+ ```
37
+
38
+ ## Issues and Feedback
39
+
40
+ For any other issues and feedback about this plugin, please submit it to this repository.
41
+
42
+ ## Troubleshooting
43
+
44
+ If you have trouble using plugins, check out the [Plugins Troubleshooting](https://docs.fastlane.tools/plugins/plugins-troubleshooting/) guide.
45
+
46
+ ## Using _fastlane_ Plugins
47
+
48
+ For more information about how the `fastlane` plugin system works, check out the [Plugins documentation](https://docs.fastlane.tools/plugins/create-plugin/).
49
+
50
+ ## About _fastlane_
51
+
52
+ _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,13 @@
1
+ require 'fastlane/plugin/periphery/version'
2
+
3
+ module Fastlane
4
+ module Periphery
5
+ def self.all_classes
6
+ Dir[File.expand_path('**/actions/*.rb', File.dirname(__FILE__))]
7
+ end
8
+ end
9
+ end
10
+
11
+ Fastlane::Periphery.all_classes.each do |current|
12
+ require current
13
+ end
@@ -0,0 +1,188 @@
1
+ require 'fastlane/action'
2
+
3
+ module Fastlane
4
+ module Actions
5
+ module SharedValues
6
+ PERIPHERY_RESULTS = :PERIPHERY_RESULTS
7
+ end
8
+
9
+ class PeripheryAction < Action
10
+ # https://github.com/peripheryapp/periphery/blob/master/Sources/Frontend/Formatters/JsonFormatter.swift
11
+ class Result
12
+ attr_reader :kind, :name, :modifiers, :attributes, :accessibility, :ids, :hints, :location
13
+
14
+ def initialize(raw)
15
+ @kind = raw['kind']
16
+ @name = raw['name']
17
+ @modifiers = raw['modifiers']
18
+ @attributes = raw['attributes']
19
+ @accessibility = raw['accessibility']
20
+ @ids = raw['ids']
21
+ @hints = raw['hints']
22
+ @location = raw['location']
23
+ end
24
+ end
25
+
26
+ class Runner
27
+ attr_reader :executable, :config, :skip_build, :index_store_path, :results
28
+
29
+ def expand_and_verify_path(path)
30
+ return nil if path.nil?
31
+
32
+ path = File.expand_path(path)
33
+ UI.user_error!("File or directory does not exist at path '#{path}'") unless File.exist?(path)
34
+
35
+ path
36
+ end
37
+
38
+ def initialize(params)
39
+ @executable = params[:executable] || 'periphery'
40
+ @config = expand_and_verify_path(params[:config])
41
+ @skip_build = params[:skip_build]
42
+ @index_store_path = expand_and_verify_path(params[:index_store_path])
43
+ @results = nil
44
+ end
45
+
46
+ def run
47
+ verify_executable
48
+ perform_scan
49
+ print_summary
50
+ results
51
+ end
52
+
53
+ def verify_executable
54
+ version = Actions.sh_control_output([executable, 'version'], print_command_output: false).strip!
55
+ UI.message("Using periphery version #{version}")
56
+ rescue
57
+ UI.user_error!("Unable to invoke periphery executable '#{executable}'. Is it installed?")
58
+ end
59
+
60
+ def perform_scan
61
+ # Run the periphery scan command and collect the output
62
+ UI.message("Performing scan. This might take a few moments...")
63
+ output = Actions.sh_control_output(scan_command, print_command_output: false, error_callback: lambda { |result|
64
+ UI.error(result)
65
+ UI.user_error!("The scan could not be completed successfully")
66
+ })
67
+
68
+ # Decode the JSON output and assign to the property/lane_context
69
+ @results = JSON.parse(output).map { |raw| Result.new(raw) }
70
+ Actions.lane_context[SharedValues::PERIPHERY_RESULTS] = results
71
+ end
72
+
73
+ def scan_command
74
+ # Build up the initial part of the command
75
+ command = [
76
+ executable,
77
+ 'scan',
78
+ '--disable-update-check',
79
+ '--format',
80
+ 'json'
81
+ ]
82
+
83
+ # Specify the path to the config if it was provided
84
+ if config
85
+ command << '--config'
86
+ command << config
87
+ end
88
+
89
+ # Support --skip-build mode
90
+ if skip_build || !index_store_path.nil?
91
+ command << '--skip-build'
92
+ command << '--index-store-path'
93
+ command << resolve_index_store_path
94
+ end
95
+
96
+ # Return the complete array of arguments
97
+ command
98
+ end
99
+
100
+ def resolve_index_store_path
101
+ # If it was explicitly specified, return the path to the index store
102
+ return index_store_path unless index_store_path.nil?
103
+
104
+ # Alternatively, use the derived data path defined by a prior action
105
+ derived_data_path = find_derived_data_path
106
+ return File.join(derived_data_path, 'Index', 'DataStore') unless derived_data_path.nil?
107
+
108
+ # Fail if we couldn't automatically resolve the path
109
+ UI.user_error!("The index store path could not be resolved. Either specify it using the index_store_path argument or provide a path to derived data when using build_app or xcodebuild actions.")
110
+ end
111
+
112
+ def find_derived_data_path
113
+ # These values are set by other actions that may have been used to build an app previously
114
+ candidates = [
115
+ Actions.lane_context[SharedValues::SCAN_DERIVED_DATA_PATH],
116
+ Actions.lane_context[SharedValues::XCODEBUILD_DERIVED_DATA_PATH]
117
+ ]
118
+
119
+ # Return the first candidate where the value was set and the directory still exists
120
+ candidates.find { |x| !x.nil? && File.exist?(x) }
121
+ end
122
+
123
+ def print_summary
124
+ # Group the results by their first hint (assume there is only one).
125
+ grouped_results = results
126
+ .group_by { |result| result.hints.first }
127
+ .transform_values(&:count)
128
+
129
+ # Print the counts in a table
130
+ FastlaneCore::PrintTable.print_values(config: grouped_results, title: 'Summary of Results') unless Helper.test?
131
+ end
132
+ end
133
+
134
+ def self.run(params)
135
+ require 'json'
136
+
137
+ Runner.new(params).run
138
+ end
139
+
140
+ def self.description
141
+ "Identifies unused code in Swift projects using Periphery"
142
+ end
143
+
144
+ def self.authors
145
+ ["Liam Nichols"]
146
+ end
147
+
148
+ def self.return_value
149
+ "Output of the command parsed from JSON into an array of Result objects"
150
+ end
151
+
152
+ def self.available_options
153
+ [
154
+ FastlaneCore::ConfigItem.new(key: :executable,
155
+ env_name: "PERIPHERY_EXECUTABLE",
156
+ description: "Path to the `periphery` executable on your machine",
157
+ optional: true),
158
+ FastlaneCore::ConfigItem.new(key: :config,
159
+ env_name: "PERIPHERY_CONFIG",
160
+ description: "Path to configuration file",
161
+ optional: true,
162
+ type: String),
163
+ FastlaneCore::ConfigItem.new(key: :skip_build,
164
+ env_name: "PERIPHERY_SKIP_BUILD",
165
+ description: "Skip the project build step",
166
+ optional: true,
167
+ default_value: false,
168
+ type: Boolean),
169
+ FastlaneCore::ConfigItem.new(key: :index_store_path,
170
+ env_name: "PERIPHERY_INDEX_STORE_PATH",
171
+ description: "Path to index store to use",
172
+ optional: true,
173
+ type: String)
174
+ ]
175
+ end
176
+
177
+ def self.output
178
+ [
179
+ ["PERIPHERY_RESULTS", "The output of periphery decoded into an array of Result objects."]
180
+ ]
181
+ end
182
+
183
+ def self.is_supported?(platform)
184
+ [:ios, :mac].include?(platform)
185
+ end
186
+ end
187
+ end
188
+ end
@@ -0,0 +1,5 @@
1
+ module Fastlane
2
+ module Periphery
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,173 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fastlane-plugin-periphery
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Liam Nichols
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-08-03 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.156.1
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: 2.156.1
139
+ description:
140
+ email: liam.nichols.ln@gmail.com
141
+ executables: []
142
+ extensions: []
143
+ extra_rdoc_files: []
144
+ files:
145
+ - LICENSE
146
+ - README.md
147
+ - lib/fastlane/plugin/periphery.rb
148
+ - lib/fastlane/plugin/periphery/actions/periphery_action.rb
149
+ - lib/fastlane/plugin/periphery/version.rb
150
+ homepage: https://github.com/liamnichols/fastlane-plugin-periphery
151
+ licenses:
152
+ - MIT
153
+ metadata: {}
154
+ post_install_message:
155
+ rdoc_options: []
156
+ require_paths:
157
+ - lib
158
+ required_ruby_version: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ required_rubygems_version: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ requirements: []
169
+ rubygems_version: 3.0.3
170
+ signing_key:
171
+ specification_version: 4
172
+ summary: Identifies unused code in Swift projects using Periphery
173
+ test_files: []