fastlane-plugin-android_version_manager 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: f111afbf03b70d99f3f9bed4fffcf6004fcedaf805bdb08a6131d152e56a0677
4
+ data.tar.gz: 256c8aa6677d32b663e0a5684ac5fa03c459eb60cdc5420c5a60adff5c502be2
5
+ SHA512:
6
+ metadata.gz: d8dc4f9be2102f1c70f64d530c36bbc2227f4bad5d7e52c1ab0ce15acc1afa43961bf7aff8755faae30704bd71d41180c43aef10b347da9bc087bbf46529e4cc
7
+ data.tar.gz: 3ff8739ee5c8bd06329a5327b47fcef1d20effc175f1f63a7085ecd20d86005007bd35b73a35494d19eeb5eae8b53c267c8fa2592722bba88ea1c1e5792e8704
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Jonathan Cardoso Machado <me@jonathancardoso.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,74 @@
1
+ # android_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-android_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-android_version_manager`, add it to your project by running:
8
+
9
+ ```bash
10
+ fastlane add_plugin android_version_manager
11
+ ```
12
+
13
+ ## About android_version_manager
14
+
15
+ Android's App Version Managment
16
+
17
+ This plugin enables you to more easily manage Android app versioning with fastlane.
18
+
19
+ ### Available Actions
20
+
21
+ Read each action metadata on their respective source code:
22
+
23
+ #### [android_get_value_from_build_action](./lib/fastlane/plugin/android_version_manager/actions/android_get_value_from_build_action.rb)
24
+
25
+ #### [android_get_version_code_action](./lib/fastlane/plugin/android_version_manager/actions/android_get_version_code_action.rb)
26
+
27
+ #### [android_get_version_name_action](./lib/fastlane/plugin/android_version_manager/actions/android_get_version_name_action.rb)
28
+
29
+ #### [android_increment_version_code_action](./lib/fastlane/plugin/android_version_manager/actions/android_increment_version_code_action.rb)
30
+
31
+ #### [android_increment_version_name_action](./lib/fastlane/plugin/android_version_manager/actions/android_increment_version_name_action.rb)
32
+
33
+ ### Version Control
34
+
35
+ This plugin does not provide any functionality related to version control. This was intentional because that can be easily implemented on the lane directly, for example, just use the following actions:
36
+ 1. [ensure_git_status_clean](https://docs.fastlane.tools/actions/ensure_git_status_clean/)
37
+ 2. [git_tag_exists](https://docs.fastlane.tools/actions/git_tag_exists/)
38
+ 2. [git_add](https://docs.fastlane.tools/actions/git_add/)
39
+ 2. [git_commit](https://docs.fastlane.tools/actions/git_commit/)
40
+ 4. [add_git_tag](https://docs.fastlane.tools/actions/add_git_tag/)
41
+ 3. [push_to_git_remote](https://docs.fastlane.tools/actions/push_to_git_remote/)
42
+
43
+ ## Example
44
+
45
+ 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`.
46
+
47
+ ## Run tests for this plugin
48
+
49
+ To run both the tests, and code style validation, run
50
+
51
+ ```
52
+ bundle exec rake
53
+ ```
54
+
55
+ To automatically fix many of the styling issues, use
56
+ ```
57
+ bundle exec rubocop -a
58
+ ```
59
+
60
+ ## Issues and Feedback
61
+
62
+ For any other issues and feedback about this plugin, please submit it to this repository.
63
+
64
+ ## Troubleshooting
65
+
66
+ If you have trouble using plugins, check out the [Plugins Troubleshooting](https://docs.fastlane.tools/plugins/plugins-troubleshooting/) guide.
67
+
68
+ ## Using _fastlane_ Plugins
69
+
70
+ For more information about how the `fastlane` plugin system works, check out the [Plugins documentation](https://docs.fastlane.tools/plugins/create-plugin/).
71
+
72
+ ## About _fastlane_
73
+
74
+ _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/android_version_manager/version'
2
+
3
+ module Fastlane
4
+ module AndroidVersionManager
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::AndroidVersionManager.all_classes.each do |current|
15
+ require current
16
+ end
@@ -0,0 +1,40 @@
1
+ # This source code is based on this one:
2
+ # https://github.com/otkmnb2783/fastlane-plugin-android_versioning/blob/a9dc02d69a8c3a106d00b52ace78d4a763baf6af/lib/fastlane/plugin/android_versioning/actions/get_value_from_build.rb#L1
3
+ require "fileutils"
4
+
5
+ module Fastlane
6
+ module Actions
7
+ class AndroidGetValueFromBuildAction < Action
8
+ def self.run(params)
9
+ app_project_dir ||= params[:app_project_dir]
10
+ value, _line, _line_index = Helper::AndroidVersionManagerHelper.get_key_from_gradle_file("#{app_project_dir}/build.gradle", params[:key])
11
+ return value
12
+ end
13
+
14
+ def self.available_options
15
+ [
16
+ FastlaneCore::ConfigItem.new(key: :app_project_dir,
17
+ description: "The path to the application source folder in the Android project, the one that contains the build.gradle file (default: android/app)",
18
+ optional: true,
19
+ type: String,
20
+ default_value: "android/app",
21
+ verify_block: proc do |value|
22
+ # Not using File.exist?("#{value}/build.gradle") because it does not handle globs
23
+ UI.user_error!("Couldn't find build.gradle file at path '#{value}'") unless Dir["#{value}/build.gradle"].any?
24
+ end),
25
+ FastlaneCore::ConfigItem.new(key: :key,
26
+ description: "The property key to retrieve the value from",
27
+ type: String),
28
+ ]
29
+ end
30
+
31
+ def self.authors
32
+ ["Jonathan Cardoso", "@_jonathancardos", "JCMais"]
33
+ end
34
+
35
+ def self.is_supported?(platform)
36
+ platform == :android
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,97 @@
1
+ require "fastlane/action"
2
+ require_relative "../helper/android_version_manager_helper"
3
+
4
+ module Fastlane
5
+ module Actions
6
+ # To Share a Value
7
+ module SharedValues
8
+ ANDROID_VERSION_CODE ||= :ANDROID_VERSION_CODE
9
+ end
10
+
11
+ class AndroidGetVersionCodeAction < Action
12
+ def self.run(params)
13
+ # fastlane will take care of reading in the parameter and fetching the environment variable:
14
+ UI.message("Parameter app_project_dir: #{params[:app_project_dir]}")
15
+ UI.message("Parameter key: #{params[:key]}")
16
+
17
+ # We can expect version_code to be an existing and valid version code
18
+ version_code = Helper::AndroidVersionManagerHelper.get_version_code_from_gradle_file("#{params[:app_project_dir]}/build.gradle", params[:key])
19
+
20
+ Actions.lane_context[Fastlane::Actions::SharedValues::ANDROID_VERSION_CODE] = version_code
21
+
22
+ return version_code
23
+ end
24
+
25
+ #####################################################
26
+ # @!group Documentation
27
+ #####################################################
28
+
29
+ def self.description
30
+ "Returns the version code of the android project"
31
+ end
32
+
33
+ def self.details
34
+ "Based on the provided params, returns the value of the version code of the build.gradle file as a number"
35
+ end
36
+
37
+ def self.available_options
38
+ [
39
+ FastlaneCore::ConfigItem.new(key: :app_project_dir,
40
+ env_name: "FL_ANDROID_GET_VERSION_CODE_APP_PROJECT_DIR",
41
+ description: "The path to the application source folder in the Android project (default: android/app)",
42
+ optional: true,
43
+ type: String,
44
+ default_value: "android/app",
45
+ verify_block: proc do |value|
46
+ # Not using File.exist?("#{value}/build.gradle") because it does not handle globs
47
+ UI.user_error!("Couldn't find build.gradle file at path '#{value}'") unless Dir["#{value}/build.gradle"].any?
48
+ end),
49
+ FastlaneCore::ConfigItem.new(key: :key,
50
+ env_name: "FL_ANDROID_GET_VERSION_CODE_KEY",
51
+ description: "The property key",
52
+ optional: true,
53
+ type: String,
54
+ default_value: "versionCode"),
55
+ ]
56
+ end
57
+
58
+ def self.output
59
+ [
60
+ ["ANDROID_VERSION_CODE", "The version code specified on the build.gradle file of the project"],
61
+ ]
62
+ end
63
+
64
+ def self.category
65
+ # https://github.com/fastlane/fastlane/blob/051e5012984d97257571a76627c1261946afb8f8/fastlane/lib/fastlane/action.rb#L6-L21
66
+ :project
67
+ end
68
+
69
+ # def self.example_code
70
+ # [
71
+ # 'version = get_version_number(xcodeproj: "Project.xcodeproj")',
72
+ # 'version = get_version_number(
73
+ # xcodeproj: "Project.xcodeproj",
74
+ # target: "App"
75
+ # )'
76
+ # ]
77
+ # end
78
+
79
+ def self.return_value
80
+ "The Android app version code"
81
+ end
82
+
83
+ def self.return_type
84
+ # https://github.com/fastlane/fastlane/blob/051e5012984d97257571a76627c1261946afb8f8/fastlane/lib/fastlane/action.rb#L23-L30
85
+ :int
86
+ end
87
+
88
+ def self.authors
89
+ ["Jonathan Cardoso", "@_jonathancardos", "JCMais"]
90
+ end
91
+
92
+ def self.is_supported?(platform)
93
+ platform == :android
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,97 @@
1
+ require "fastlane/action"
2
+ require_relative "../helper/android_version_manager_helper"
3
+
4
+ module Fastlane
5
+ module Actions
6
+ # To Share a Value
7
+ module SharedValues
8
+ ANDROID_VERSION_NAME ||= :ANDROID_VERSION_NAME
9
+ end
10
+
11
+ class AndroidGetVersionNameAction < Action
12
+ def self.run(params)
13
+ # fastlane will take care of reading in the parameter and fetching the environment variable:
14
+ UI.message("Parameter app_project_dir: #{params[:app_project_dir]}")
15
+ UI.message("Parameter key: #{params[:key]}")
16
+
17
+ # We can expect version_name to be an existing and valid semver version name
18
+ version_name = Helper::AndroidVersionManagerHelper.get_version_name_from_gradle_file("#{params[:app_project_dir]}/build.gradle", params[:key])
19
+
20
+ Actions.lane_context[Fastlane::Actions::SharedValues::ANDROID_VERSION_NAME] = version_name
21
+
22
+ return version_name
23
+ end
24
+
25
+ #####################################################
26
+ # @!group Documentation
27
+ #####################################################
28
+
29
+ def self.description
30
+ "Returns the version name of the android project"
31
+ end
32
+
33
+ def self.details
34
+ "Based on the provided params, returns the value of the version name of the build.gradle file as a string"
35
+ end
36
+
37
+ def self.available_options
38
+ [
39
+ FastlaneCore::ConfigItem.new(key: :app_project_dir,
40
+ env_name: "FL_ANDROID_GET_VERSION_CODE_APP_PROJECT_DIR",
41
+ description: "The path to the application source folder in the Android project (default: android/app)",
42
+ optional: true,
43
+ type: String,
44
+ default_value: "android/app",
45
+ verify_block: proc do |value|
46
+ # Not using File.exist?("#{value}/build.gradle") because it does not handle globs
47
+ UI.user_error!("Couldn't find build.gradle file at path '#{value}'") unless Dir["#{value}/build.gradle"].any?
48
+ end),
49
+ FastlaneCore::ConfigItem.new(key: :key,
50
+ env_name: "FL_ANDROID_GET_VERSION_CODE_KEY",
51
+ description: "The property key",
52
+ optional: true,
53
+ type: String,
54
+ default_value: "versionName"),
55
+ ]
56
+ end
57
+
58
+ def self.output
59
+ [
60
+ ["ANDROID_VERSION_NAME", "The version code specified on the build.gradle file of the project"],
61
+ ]
62
+ end
63
+
64
+ def self.category
65
+ # https://github.com/fastlane/fastlane/blob/051e5012984d97257571a76627c1261946afb8f8/fastlane/lib/fastlane/action.rb#L6-L21
66
+ :project
67
+ end
68
+
69
+ # def self.example_code
70
+ # [
71
+ # 'version = get_version_name(xcodeproj: "Project.xcodeproj")',
72
+ # 'version = get_version_name(
73
+ # xcodeproj: "Project.xcodeproj",
74
+ # target: "App"
75
+ # )'
76
+ # ]
77
+ # end
78
+
79
+ def self.return_value
80
+ "The Android app version name"
81
+ end
82
+
83
+ def self.return_type
84
+ # https://github.com/fastlane/fastlane/blob/051e5012984d97257571a76627c1261946afb8f8/fastlane/lib/fastlane/action.rb#L23-L30
85
+ :int
86
+ end
87
+
88
+ def self.authors
89
+ ["Jonathan Cardoso", "@_jonathancardos", "JCMais"]
90
+ end
91
+
92
+ def self.is_supported?(platform)
93
+ platform == :android
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,111 @@
1
+ require "fastlane/action"
2
+ require_relative "../helper/android_version_manager_helper"
3
+
4
+ module Fastlane
5
+ module Actions
6
+ # To Share a Value
7
+ module SharedValues
8
+ ANDROID_VERSION_CODE ||= :ANDROID_VERSION_CODE
9
+ end
10
+
11
+ class AndroidIncrementVersionCodeAction < Action
12
+ def self.run(params)
13
+ UI.message("Param app_project_dir: #{params[:app_project_dir]}")
14
+ UI.message("Param version_code: #{params[:version_code]}")
15
+ UI.message("Param key: #{params[:key]}")
16
+
17
+ file_path = "#{params[:app_project_dir]}/build.gradle"
18
+
19
+ # We can expect version_code to be an existing and valid version code
20
+ version_code = Helper::AndroidVersionManagerHelper.get_version_code_from_gradle_file(file_path, params[:key])
21
+ new_version_code = params[:version_code] || version_code + 1
22
+
23
+ if new_version_code <= version_code
24
+ UI.user_error!("New version code must be greater than the current one")
25
+ end
26
+
27
+ Helper::AndroidVersionManagerHelper.set_key_value_on_gradle_file(file_path, params[:key], new_version_code)
28
+
29
+ Actions.lane_context[Fastlane::Actions::SharedValues::ANDROID_VERSION_CODE] = new_version_code
30
+
31
+ return new_version_code
32
+ end
33
+
34
+ #####################################################
35
+ # @!group Documentation
36
+ #####################################################
37
+
38
+ def self.description
39
+ "Increments the version code of the android project"
40
+ end
41
+
42
+ def self.details
43
+ "Based on the provided params, increments the version code and returns their new value"
44
+ end
45
+
46
+ def self.available_options
47
+ [
48
+ FastlaneCore::ConfigItem.new(key: :app_project_dir,
49
+ env_name: "FL_ANDROID_INCREMENT_VERSION_CODE_APP_PROJECT_DIR",
50
+ description: "The path to the application source folder in the Android project (default: android/app)",
51
+ optional: true,
52
+ type: String,
53
+ default_value: "android/app",
54
+ verify_block: proc do |value|
55
+ # Not using File.exist?("#{value}/build.gradle") because it does not handle globs
56
+ UI.user_error!("Couldn't find build.gradle file at path '#{value}'") unless Dir["#{value}/build.gradle"].any?
57
+ end),
58
+ FastlaneCore::ConfigItem.new(key: :key,
59
+ env_name: "FL_ANDROID_INCREMENT_VERSION_CODE_KEY",
60
+ description: "The property key",
61
+ optional: true,
62
+ type: String,
63
+ default_value: "versionCode"),
64
+ FastlaneCore::ConfigItem.new(key: :version_code,
65
+ env_name: "FL_ANDROID_GET_VERSION_CODE_VERSION_CODE",
66
+ description: "Change to a specific version instead of just incrementing",
67
+ optional: true,
68
+ is_string: false),
69
+ ]
70
+ end
71
+
72
+ def self.output
73
+ [
74
+ ["ANDROID_VERSION_CODE", "The new version code"],
75
+ ]
76
+ end
77
+
78
+ def self.category
79
+ # https://github.com/fastlane/fastlane/blob/051e5012984d97257571a76627c1261946afb8f8/fastlane/lib/fastlane/action.rb#L6-L21
80
+ :project
81
+ end
82
+
83
+ # def self.example_code
84
+ # [
85
+ # 'version = android_increment_version_code(xcodeproj: "Project.xcodeproj")',
86
+ # 'version = android_increment_version_code(
87
+ # xcodeproj: "Project.xcodeproj",
88
+ # target: "App"
89
+ # )'
90
+ # ]
91
+ # end
92
+
93
+ def self.return_value
94
+ "The Android app new version code"
95
+ end
96
+
97
+ def self.return_type
98
+ # https://github.com/fastlane/fastlane/blob/051e5012984d97257571a76627c1261946afb8f8/fastlane/lib/fastlane/action.rb#L23-L30
99
+ :int
100
+ end
101
+
102
+ def self.authors
103
+ ["Jonathan Cardoso", "@_jonathancardos", "JCMais"]
104
+ end
105
+
106
+ def self.is_supported?(platform)
107
+ platform == :android
108
+ end
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,133 @@
1
+ require "fastlane/action"
2
+ require "semantic"
3
+
4
+ require_relative "../helper/android_version_manager_helper"
5
+
6
+ module Fastlane
7
+ module Actions
8
+ # To Share a Value
9
+ module SharedValues
10
+ ANDROID_VERSION_NAME ||= :ANDROID_VERSION_NAME
11
+ end
12
+
13
+ class AndroidIncrementVersionNameAction < Action
14
+ def self.run(params)
15
+ UI.message("Param app_project_dir: #{params[:app_project_dir]}")
16
+ UI.message("Param version_name: #{params[:version_name]}")
17
+ UI.message("Param increment_type: #{params[:increment_type]}")
18
+ UI.message("Param key: #{params[:key]}")
19
+
20
+ file_path = "#{params[:app_project_dir]}/build.gradle"
21
+ increment_type = params[:increment_type].to_sym
22
+
23
+ # We can expect version_code to be an existing and valid version code
24
+ version_name = Helper::AndroidVersionManagerHelper.get_version_name_from_gradle_file(file_path, params[:key])
25
+
26
+ param_version_name = params[:version_name]
27
+ unless param_version_name.nil?
28
+ begin
29
+ param_version_name = Semantic::Version.new(param_version_name)
30
+ rescue Exception # rubocop:disable RescueException
31
+ raise $!, "Error parsing version name #{param_version_name}: #{$!}", $!.backtrace
32
+ end
33
+ end
34
+ new_version_name = param_version_name || version_name.increment!(increment_type)
35
+
36
+ if new_version_name <= version_name
37
+ UI.important("New version name is not greater than the current one")
38
+ end
39
+
40
+ Helper::AndroidVersionManagerHelper.set_key_value_on_gradle_file(file_path, params[:key], new_version_name.to_s)
41
+
42
+ Actions.lane_context[Fastlane::Actions::SharedValues::ANDROID_VERSION_NAME] = new_version_name
43
+
44
+ return new_version_name
45
+ end
46
+
47
+ #####################################################
48
+ # @!group Documentation
49
+ #####################################################
50
+
51
+ def self.description
52
+ "Increments the version name of the android project"
53
+ end
54
+
55
+ def self.details
56
+ "Based on the provided params, increments the version name and returns their new value"
57
+ end
58
+
59
+ def self.available_options
60
+ [
61
+ FastlaneCore::ConfigItem.new(key: :app_project_dir,
62
+ env_name: "FL_ANDROID_INCREMENT_VERSION_NAME_APP_PROJECT_DIR",
63
+ description: "The path to the application source folder in the Android project (default: android/app)",
64
+ optional: true,
65
+ type: String,
66
+ default_value: "android/app",
67
+ verify_block: proc do |value|
68
+ # Not using File.exist?("#{value}/build.gradle") because it does not handle globs
69
+ UI.user_error!("Couldn't find build.gradle file at path '#{value}'") unless Dir["#{value}/build.gradle"].any?
70
+ end),
71
+ FastlaneCore::ConfigItem.new(key: :key,
72
+ env_name: "FL_ANDROID_INCREMENT_VERSION_NAME_KEY",
73
+ description: "The property key",
74
+ optional: true,
75
+ type: String,
76
+ default_value: "versionName"),
77
+ FastlaneCore::ConfigItem.new(key: :increment_type,
78
+ env_name: "FL_ANDROID_INCREMENT_VERSION_NAME_INCREMENT_TYPE",
79
+ description: "The type of increment to make, can be one of: patch, minor, major",
80
+ optional: true,
81
+ type: String,
82
+ default_value: "patch",
83
+ verify_block: proc do |value|
84
+ UI.user_error!("Increment type of #{value} is not valid") unless ['patch', 'minor', 'major'].include?(value)
85
+ end),
86
+ FastlaneCore::ConfigItem.new(key: :version_name,
87
+ env_name: "FL_ANDROID_GET_VERSION_CODE_VERSION_NAME",
88
+ description: "Change to a specific version name instead of just incrementing",
89
+ optional: true,
90
+ is_string: false),
91
+ ]
92
+ end
93
+
94
+ def self.output
95
+ [
96
+ ["ANDROID_VERSION_NAME", "The new version name"],
97
+ ]
98
+ end
99
+
100
+ def self.category
101
+ # https://github.com/fastlane/fastlane/blob/051e5012984d97257571a76627c1261946afb8f8/fastlane/lib/fastlane/action.rb#L6-L21
102
+ :project
103
+ end
104
+
105
+ # def self.example_code
106
+ # [
107
+ # 'version = android_increment_version_code(xcodeproj: "Project.xcodeproj")',
108
+ # 'version = android_increment_version_code(
109
+ # xcodeproj: "Project.xcodeproj",
110
+ # target: "App"
111
+ # )'
112
+ # ]
113
+ # end
114
+
115
+ def self.return_value
116
+ "The Android app new version name"
117
+ end
118
+
119
+ def self.return_type
120
+ # https://github.com/fastlane/fastlane/blob/051e5012984d97257571a76627c1261946afb8f8/fastlane/lib/fastlane/action.rb#L23-L30
121
+ :int
122
+ end
123
+
124
+ def self.authors
125
+ ["Jonathan Cardoso", "@_jonathancardos", "JCMais"]
126
+ end
127
+
128
+ def self.is_supported?(platform)
129
+ platform == :android
130
+ end
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,48 @@
1
+ require 'fastlane/action'
2
+ require_relative '../helper/android_version_manager_helper'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ class AndroidVersionManagerAction < Action
7
+ def self.run(params)
8
+ UI.message("The android_version_manager plugin is working!")
9
+ end
10
+
11
+ def self.description
12
+ "Android's App Version Managment"
13
+ end
14
+
15
+ def self.authors
16
+ ["Jonathan Cardoso Machado"]
17
+ end
18
+
19
+ def self.return_value
20
+ # If your method provides a return value, you can describe here what it does
21
+ end
22
+
23
+ def self.details
24
+ # Optional:
25
+ ""
26
+ end
27
+
28
+ def self.available_options
29
+ [
30
+ FastlaneCore::ConfigItem.new(key: :app_project_dir,
31
+ env_name: "ANDROID_VERSIONING_APP_PROJECT_DIR",
32
+ description: "The path to the application source folder in the Android project (default: android/app)",
33
+ optional: true,
34
+ type: String,
35
+ default_value: "android/app"),
36
+ FastlaneCore::ConfigItem.new(key: :key,
37
+ description: "The property key",
38
+ type: String)
39
+
40
+ ]
41
+ end
42
+
43
+ def self.is_supported?(platform)
44
+ platform == :android
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,111 @@
1
+ require "fileutils"
2
+
3
+ require "fastlane_core/ui/ui"
4
+ require "semantic"
5
+ require "tempfile"
6
+
7
+ module Fastlane
8
+ UI = FastlaneCore::UI unless Fastlane.const_defined?("UI")
9
+
10
+ module Helper
11
+ class AndroidVersionManagerHelper
12
+ # class methods that you define here become available in your action
13
+ # as `Helper::AndroidVersionManagerHelper.your_method`
14
+ # Most actions code are here to follow this advice: https://docs.fastlane.tools/advanced/actions/#calling-other-actions
15
+ def self.get_key_from_gradle_file(file_path, key)
16
+ UI.message("Hello from the android_version_manager plugin helper - get_key_from_file!")
17
+
18
+ regex = Regexp.new(/(?<key>#{key}\s+)(?<equals>\=[\s]*?)?(?<left>[\'\"]?)(?<value>[a-zA-Z0-9\.\_]+)(?<right>[\'\"]?)(?<comment>.*)/)
19
+ value = ""
20
+ line_found = nil
21
+ line_found_index = nil
22
+ found = false
23
+ Dir.glob(file_path) do |path|
24
+ UI.verbose("get_key_from_gradle_file - path: #{path}")
25
+ UI.verbose("get_key_from_gradle_file - absolute_path: #{File.expand_path(path)}")
26
+ begin
27
+ File.open(path, "r") do |file|
28
+ file.each_line do |line, index|
29
+ unless line.match(regex) && !found
30
+ next
31
+ end
32
+ line_found = line
33
+ line_found_index = index
34
+ _key, _equals, _left, value, _right, _comment = line.match(regex).captures
35
+ break
36
+ end
37
+ file.close
38
+ end
39
+ end
40
+ end
41
+ return value, line_found, line_found_index
42
+ end
43
+
44
+ def self.set_key_value_on_gradle_file(file_path, key, new_value)
45
+ # this will do the search again, only because we need the values again
46
+ value, _line_found, line_found_index = get_key_from_gradle_file(file_path, key)
47
+
48
+ # https://stackoverflow.com/a/4174125/710693
49
+ Dir.glob(file_path) do |path|
50
+ Tempfile.open(".#{File.basename(path)}", File.dirname(path)) do |tempfile|
51
+ UI.verbose("set_key_value_on_gradle_file - path: #{path}")
52
+ UI.verbose("set_key_value_on_gradle_file - absolute_path: #{File.expand_path(path)}")
53
+ File.open(path).each do |line, index|
54
+ tempfile.puts(index == line_found_index ? line.sub(value, new_value.to_s) : line)
55
+ end
56
+ tempfile.close
57
+ FileUtils.mv(tempfile.path, path)
58
+ end
59
+ end
60
+ end
61
+
62
+ def self.get_version_code_from_gradle_file(file_path, key)
63
+ version_code, _line, _line_index = get_key_from_gradle_file(file_path, key)
64
+
65
+ UI.message("Read version code: #{version_code.inspect}")
66
+
67
+ # Error out if version_number is not set
68
+ if version_code.nil? || version_code == ""
69
+ UI.user_error!("Unable to find version code with key #{key} on file #{file_path}")
70
+ end
71
+
72
+ version_code = Helper::AndroidVersionManagerHelper.string_to_int(version_code)
73
+
74
+ # Error out if version_number is invalid
75
+ if version_code.nil?
76
+ UI.user_error!("Version code with key #{key} on file #{file_path} is invalid, it must be an integer")
77
+ end
78
+
79
+ return version_code
80
+ end
81
+
82
+ def self.get_version_name_from_gradle_file(file_path, key)
83
+ version_name, _line, _line_index = get_key_from_gradle_file(file_path, key)
84
+
85
+ UI.message("Read version name: #{version_name.inspect}")
86
+
87
+ # Error out if version_name is not set
88
+ if version_name.nil? || version_name == ""
89
+ UI.user_error!("Unable to find version name with key #{key} on file #{file_path}")
90
+ end
91
+
92
+ begin
93
+ version_name = Semantic::Version.new(version_name)
94
+ rescue Exception # rubocop:disable RescueException
95
+ raise $!, "Error parsing version name with key #{key} on file #{file_path}: #{$!}", $!.backtrace
96
+ end
97
+
98
+ return version_name
99
+ end
100
+
101
+ def self.string_to_int(string)
102
+ # without exceptions:
103
+ # num = string.to_i
104
+ # num if num.to_s == string
105
+ Integer(string || "", 10)
106
+ rescue ArgumentError
107
+ nil
108
+ end
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,5 @@
1
+ module Fastlane
2
+ module AndroidVersionManager
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,193 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fastlane-plugin-android_version_manager
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jonathan Cardoso Machado
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-12-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: semantic
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.6.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.6.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
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: bundler
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
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: rspec_junit_formatter
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: rake
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: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '='
102
+ - !ruby/object:Gem::Version
103
+ version: 0.49.1
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '='
109
+ - !ruby/object:Gem::Version
110
+ version: 0.49.1
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop-require_tools
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: simplecov
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: fastlane
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: 2.133.0
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: 2.133.0
153
+ description:
154
+ email: me@jonathancardoso.com
155
+ executables: []
156
+ extensions: []
157
+ extra_rdoc_files: []
158
+ files:
159
+ - LICENSE
160
+ - README.md
161
+ - lib/fastlane/plugin/android_version_manager.rb
162
+ - lib/fastlane/plugin/android_version_manager/actions/android_get_value_from_build_action.rb
163
+ - lib/fastlane/plugin/android_version_manager/actions/android_get_version_code_action.rb
164
+ - lib/fastlane/plugin/android_version_manager/actions/android_get_version_name_action.rb
165
+ - lib/fastlane/plugin/android_version_manager/actions/android_increment_version_code_action.rb
166
+ - lib/fastlane/plugin/android_version_manager/actions/android_increment_version_name_action.rb
167
+ - lib/fastlane/plugin/android_version_manager/actions/android_version_manager_action.rb
168
+ - lib/fastlane/plugin/android_version_manager/helper/android_version_manager_helper.rb
169
+ - lib/fastlane/plugin/android_version_manager/version.rb
170
+ homepage: https://github.com/JCMais/fastlane-plugin-android_version_manager
171
+ licenses:
172
+ - MIT
173
+ metadata: {}
174
+ post_install_message:
175
+ rdoc_options: []
176
+ require_paths:
177
+ - lib
178
+ required_ruby_version: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
183
+ required_rubygems_version: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ requirements: []
189
+ rubygems_version: 3.0.3
190
+ signing_key:
191
+ specification_version: 4
192
+ summary: Android's App Version Managment
193
+ test_files: []