fastlane-plugin-flutter_version_manager 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3a445dfae711ec9546ca087a5fe8915eec0527a50404e22abd2b6ce5ff121728
4
+ data.tar.gz: 9b41962257e201c4bb5ce1f5b8d224c25cde3ba865c2ef07b1520da30d5ef969
5
+ SHA512:
6
+ metadata.gz: cee00234ac5ae70bdd130f486c001b5343b44cf4be6bc2b946c231b6bbf1ff7071e68af3914b48eb50715fbabec6a75e03c1dbcd304ca84bc1a8b945839c843b
7
+ data.tar.gz: 16d4dec2fbb25437635b3ae8521db3a059a4577a760ecc72e5156c73d35b044670d8ccc3befd52c73e7c6f553ab273db7cdc68f470fb94121f51e9718dbfdc33
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Davor Maric <davormaric@outlookc.com> and Rubicon <info@rubicon-world.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,58 @@
1
+ # flutter_version_manager plugin
2
+
3
+ [![fastlane Plugin Badge](https://rawcdn.githack.com/fastlane/fastlane/master/fastlane/assets/plugin-badge.svg)](https://rubygems.org/gems/fastlane-plugin-flutter_version_manager)
4
+
5
+ ## Getting Started
6
+
7
+ This project is a [_fastlane_](https://github.com/fastlane/fastlane) plugin. To get started with `fastlane-plugin-flutter_version_manager`, add it to your project by running:
8
+
9
+ ```bash
10
+ fastlane add_plugin flutter_version_manager
11
+ ```
12
+
13
+ Inside project root, create new `version.yml` file and add the following:
14
+ ```
15
+ ---
16
+ major: 0
17
+ minor: 0
18
+ patch: 1
19
+
20
+ ```
21
+ ## About flutter_version_manager
22
+
23
+ Manages app versioning of a Flutter project. This plugin heavily resides on having a git repository and at least one commit as version code is applied through timestamp of HEAD commit. As for app version, `version.yml` should be used as a single source of truth. In order to apply changes to pubspec, use `-apply` as an argument of a plugin.
24
+
25
+ This plugin accepts 4 arguments:
26
+ `yml` - Path to version.yml file
27
+ `pubspec` - Path to pubspec.yaml file
28
+ `git_repo` - Path to git repository (optional)
29
+ `arguments` - Additional arguments (optional)
30
+ ```
31
+ -h: Access this menu
32
+ -version: Reads current version name
33
+ -code: Reads current version code
34
+ -major: Bumps major version
35
+ -minor: Bumps minor version
36
+ -patch: Bumps patch version
37
+ -apply: Applies version specified from version.yml to pubspec
38
+ ```
39
+
40
+ ## Example
41
+
42
+ 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`.
43
+
44
+ ## Issues and Feedback
45
+
46
+ For any other issues and feedback about this plugin, please submit it to this repository.
47
+
48
+ ## Troubleshooting
49
+
50
+ If you have trouble using plugins, check out the [Plugins Troubleshooting](https://docs.fastlane.tools/plugins/plugins-troubleshooting/) guide.
51
+
52
+ ## Using _fastlane_ Plugins
53
+
54
+ For more information about how the `fastlane` plugin system works, check out the [Plugins documentation](https://docs.fastlane.tools/plugins/create-plugin/).
55
+
56
+ ## About _fastlane_
57
+
58
+ _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/flutter_version_manager/version'
2
+
3
+ module Fastlane
4
+ module FlutterVersionManager
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::FlutterVersionManager.all_classes.each do |current|
15
+ require current
16
+ end
@@ -0,0 +1,248 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/flutter_version_manager_helper'
3
+ require 'git'
4
+ require 'yaml'
5
+
6
+ GIT_OFFSET = 1598622000 # IMPORTANT: Do not change!
7
+
8
+ module Fastlane
9
+ module Actions
10
+
11
+ class ArgumentManager
12
+ def evaluateArgument(argument)
13
+ case argument
14
+ when '-h'
15
+ true
16
+ when "-version"
17
+ true
18
+ when "-code"
19
+ true
20
+ when "-major"
21
+ true
22
+ when "-minor"
23
+ true
24
+ when "-patch"
25
+ true
26
+ when "-apply"
27
+ true
28
+ else
29
+ false
30
+ end
31
+ end
32
+
33
+ def invalid_argument
34
+ UI.message("You have to pass at least one argument: Use -h view all commands")
35
+ end
36
+
37
+ def missing_required_arguments
38
+ UI.message("You have to pass paths to version.yml and pubspec.yml: Use -h for more info")
39
+ end
40
+
41
+ def commands
42
+ "
43
+ -h: Access this menu
44
+ -version: Reads current version name
45
+ -code: Reads current version code
46
+ -major: Bumps major version
47
+ -minor: Bumps minor version
48
+ -patch: Bumps patch version
49
+ -apply: Applies version specified from version.yml to pubspec
50
+ "
51
+ end
52
+ end
53
+
54
+ class GitReader
55
+ def initialize(git_path)
56
+ @git = Git.open(git_path)
57
+ end
58
+
59
+ def get_timestamp
60
+ head = @git.object('HEAD')
61
+ commit = @git.gcommit(head.sha)
62
+ commit.date.to_i
63
+ end
64
+ end
65
+
66
+ class YamlReader
67
+ def initialize(yaml_path)
68
+ @yamlFile = YAML.load_file(yaml_path)
69
+ end
70
+
71
+ def field(fieldName)
72
+ @yamlFile[fieldName]
73
+ end
74
+
75
+ def all
76
+ @yamlFile
77
+ end
78
+ end
79
+
80
+ class YamlWritter
81
+ def initialize(yaml_path)
82
+ @yaml_path = yaml_path
83
+ end
84
+
85
+ def write(yaml)
86
+ File.open(@yaml_path, "w") { |file| file.write(yaml.to_yaml) }
87
+ end
88
+ end
89
+
90
+ class FileReader
91
+ def initialize(yaml_path)
92
+ @yaml_path = yaml_path
93
+ end
94
+
95
+ def read
96
+ IO.readlines(@yaml_path)
97
+ end
98
+ end
99
+
100
+ class FileWritter
101
+ def initialize(yaml_path)
102
+ @yaml_path = yaml_path
103
+ end
104
+
105
+ def write(content)
106
+ File.open(@yaml_path, "w") { |file|
107
+ file.puts(content)
108
+ file.close
109
+ }
110
+ end
111
+ end
112
+
113
+ class VersionManager
114
+ def initialize(yaml_path, pubspec_path, git_path)
115
+ @version_reader = YamlReader.new(yaml_path)
116
+ @version_writter = YamlWritter.new(yaml_path)
117
+ @pubspec_yaml_reader = YamlReader.new(pubspec_path)
118
+ @pubspec_file_reader = FileReader.new(pubspec_path)
119
+ @pubspec_file_writter = FileWritter.new(pubspec_path)
120
+ @git_reader = GitReader.new(git_path)
121
+ end
122
+
123
+ def get_current_version_name
124
+ "#{@version_reader.field('major')}.#{@version_reader.field('minor')}.#{@version_reader.field('patch')}"
125
+ end
126
+
127
+ def get_current_version_code
128
+ @git_reader.get_timestamp - GIT_OFFSET
129
+ end
130
+
131
+ def bump_major
132
+ context = @version_reader.all
133
+ context['major'] = context['major'] + 1
134
+ context['minor'] = 0
135
+ context['patch'] = 0
136
+ @version_writter.write(context)
137
+ update_pubspec
138
+ end
139
+
140
+ def bump_minor
141
+ context = @version_reader.all
142
+ context['minor'] = context['minor'] + 1
143
+ context['patch'] = 0
144
+ @version_writter.write(context)
145
+ update_pubspec
146
+ end
147
+
148
+ def bump_patch
149
+ context = @version_reader.all
150
+ context['patch'] = context['patch'] + 1
151
+ @version_writter.write(context)
152
+ update_pubspec
153
+ end
154
+
155
+ def update_pubspec
156
+ previousVersion = @pubspec_yaml_reader.field('version')
157
+ newVersion = "#{get_current_version_name}+#{get_current_version_code}"
158
+ newContent = @pubspec_file_reader.read.map { |s| s.gsub(previousVersion, newVersion) }
159
+ @pubspec_file_writter.write(newContent)
160
+ UI.message("Previous app version: #{previousVersion}")
161
+ UI.message("New app version: #{newVersion}")
162
+ end
163
+ end
164
+
165
+ ARGUMENT_MANAGER = ArgumentManager.new()
166
+
167
+ class FlutterVersionManagerAction < Action
168
+ def self.run(params)
169
+ version_path = params[:yml]
170
+ pubspec_path = params[:pubspec]
171
+ git_path = params[:git_repo] || './'
172
+ args = (params[:arguments] || "").split(" ")
173
+
174
+ # Paths valid, continue
175
+ versionManager = VersionManager.new(version_path, pubspec_path, git_path)
176
+
177
+ # Check if the user has passed additional arguments
178
+ if(args.include?("-h") || args.include?("-version") || args.include?("-code") || args.include?("-major") || args.include?("-minor") || args.include?("-patch") || args.include?("-apply"))
179
+ args.each { |a|
180
+ case a
181
+ when '-h'
182
+ UI.message(ARGUMENT_MANAGER.commands)
183
+ when "-version"
184
+ UI.message(versionManager.get_current_version_name)
185
+ when "-code"
186
+ UI.message(versionManager.get_current_version_code)
187
+ when "-major"
188
+ versionManager.bump_major
189
+ when "-minor"
190
+ versionManager.bump_minor
191
+ when "-patch"
192
+ versionManager.bump_patch
193
+ when "-apply"
194
+ versionManager.update_pubspec
195
+ end
196
+ }
197
+ else
198
+ ARGUMENT_MANAGER.invalid_argument
199
+ end
200
+ end
201
+
202
+ def self.description
203
+ "Manages app versioning of a Flutter project."
204
+ end
205
+
206
+ def self.authors
207
+ ["Davor Maric", "rubicon-world.com"]
208
+ end
209
+
210
+ def self.return_value
211
+ # If your method provides a return value, you can describe here what it does
212
+ end
213
+
214
+ def self.details
215
+ "App versioning tool for Flutter projects that can be plugged into pipeline via CI/CD"
216
+ end
217
+
218
+ def self.available_options
219
+ [
220
+ FastlaneCore::ConfigItem.new(
221
+ key: :arguments,
222
+ description: "Additional arguments",
223
+ optional: true,
224
+ type: String),
225
+ FastlaneCore::ConfigItem.new(
226
+ key: :yml,
227
+ description: "Path to version.yml",
228
+ optional: false,
229
+ type: String),
230
+ FastlaneCore::ConfigItem.new(
231
+ key: :pubspec,
232
+ description: "Path to pubspec.yaml",
233
+ optional: false,
234
+ type: String),
235
+ FastlaneCore::ConfigItem.new(
236
+ key: :git_repo,
237
+ description: "Path to root folder of git repository",
238
+ optional: true,
239
+ type: String)
240
+ ]
241
+ end
242
+
243
+ def self.is_supported?(platform)
244
+ true
245
+ end
246
+ end
247
+ end
248
+ end
@@ -0,0 +1,16 @@
1
+ require 'fastlane_core/ui/ui'
2
+
3
+ module Fastlane
4
+ UI = FastlaneCore::UI unless Fastlane.const_defined?("UI")
5
+
6
+ module Helper
7
+ class FlutterVersionManagerHelper
8
+ # class methods that you define here become available in your action
9
+ # as `Helper::FlutterVersionManagerHelper.your_method`
10
+ #
11
+ def self.show_message
12
+ # Hi! :)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,5 @@
1
+ module Fastlane
2
+ module FlutterVersionManager
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,174 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fastlane-plugin-flutter_version_manager
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Davor Maric
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-09-01 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.149.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.149.1
139
+ description:
140
+ email: davormaric@outlook.com
141
+ executables: []
142
+ extensions: []
143
+ extra_rdoc_files: []
144
+ files:
145
+ - LICENSE
146
+ - README.md
147
+ - lib/fastlane/plugin/flutter_version_manager.rb
148
+ - lib/fastlane/plugin/flutter_version_manager/actions/flutter_version_manager_action.rb
149
+ - lib/fastlane/plugin/flutter_version_manager/helper/flutter_version_manager_helper.rb
150
+ - lib/fastlane/plugin/flutter_version_manager/version.rb
151
+ homepage: https://github.com/rubiconba/fastlane-plugin-flutter-version-manager
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.1.2
171
+ signing_key:
172
+ specification_version: 4
173
+ summary: Manages app versioning of Flutter project
174
+ test_files: []