Module: Fastlane::Helper::Android::VersionHelper
- Defined in:
- lib/fastlane/plugin/wpmreleasetoolkit/helper/android/android_version_helper.rb
Overview
A module containing helper methods to manipulate/extract/bump Android version strings in gradle files
Constant Summary collapse
- VERSION_NAME =
The key used in internal version Hash objects to hold the versionName value
'name'- VERSION_CODE =
The key used in internal version Hash objects to hold the versionCode value
'code'- MAJOR_NUMBER =
The index for the major version number part
0- MINOR_NUMBER =
The index for the minor version number part
1- HOTFIX_NUMBER =
The index for the hotfix version number part
2- ALPHA_PREFIX =
The prefix used in front of the versionName for alpha versions
'alpha-'- RC_SUFFIX =
The suffix used in the versionName for RC (beta) versions
'-rc'
Class Method Summary collapse
-
.calc_next_release_base_version(version) ⇒ Hash
Compute the next release version name for the given version, without incrementing the version code.
-
.calc_next_release_short_version(version) ⇒ String
Compute the version name to use for the next release (‘“X.Y”`).
-
.get_library_version_from_gradle_config(build_gradle_path:, import_key:) ⇒ String
Extract the value of a import key from build.gradle.
-
.get_release_version(version_properties_path:, is_alpha: false) ⇒ Hash
Extract the version name and code from the release version of the app from ‘version.properties file`.
-
.get_version_parts(version) ⇒ Array<Int>
Split a version string into its individual integer parts.
-
.is_hotfix?(version) ⇒ Bool
Determines if a version name corresponds to a hotfix.
-
.remove_beta_suffix(version) ⇒ String
Remove the beta suffix (part after the ‘-`) from a version string.
Class Method Details
.calc_next_release_base_version(version) ⇒ Hash
Compute the next release version name for the given version, without incrementing the version code
- The version name sees its minor version part incremented by one (and carried to next major if it reaches 10)
- The version code is unchanged. This method is intended to be called internally by other methods taking care of the version code bump.
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/android/android_version_helper.rb', line 61 def self.calc_next_release_base_version(version) version_name = remove_beta_suffix(version[VERSION_NAME]) vp = get_version_parts(version_name) vp[MINOR_NUMBER] += 1 if vp[MINOR_NUMBER] == 10 vp[MAJOR_NUMBER] += 1 vp[MINOR_NUMBER] = 0 end { VERSION_NAME => "#{vp[MAJOR_NUMBER]}.#{vp[MINOR_NUMBER]}", VERSION_CODE => version[VERSION_CODE] } end |
.calc_next_release_short_version(version) ⇒ String
Compute the version name to use for the next release (‘“X.Y”`).
47 48 49 50 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/android/android_version_helper.rb', line 47 def self.calc_next_release_short_version(version) v = calc_next_release_base_version(VERSION_NAME => version, VERSION_CODE => nil) v[VERSION_NAME] end |
.get_library_version_from_gradle_config(build_gradle_path:, import_key:) ⇒ String
Extract the value of a import key from build.gradle
91 92 93 94 95 96 97 98 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/android/android_version_helper.rb', line 91 def self.get_library_version_from_gradle_config(build_gradle_path:, import_key:) return nil unless File.exist?(build_gradle_path) File.open(build_gradle_path, 'r') do |f| text = f.read text.match(/^\s*(?:\w*\.)?#{Regexp.escape(import_key)}\s*=\s*['"](.*?)["']/m)&.captures&.first end end |
.get_release_version(version_properties_path:, is_alpha: false) ⇒ Hash
Extract the version name and code from the release version of the app from ‘version.properties file`
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/android/android_version_helper.rb', line 28 def self.get_release_version(version_properties_path:, is_alpha: false) return nil unless File.exist?(version_properties_path) version_name_key = is_alpha ? 'alpha.versionName' : 'versionName' version_code_key = is_alpha ? 'alpha.versionCode' : 'versionCode' text = File.read(version_properties_path) name = text.match(/#{version_name_key}=(\S*)/m)&.captures&.first code = text.match(/#{version_code_key}=(\S*)/m)&.captures&.first name.nil? || code.nil? ? nil : { VERSION_NAME => name, VERSION_CODE => code.to_i } end |
.get_version_parts(version) ⇒ Array<Int>
Split a version string into its individual integer parts
121 122 123 124 125 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/android/android_version_helper.rb', line 121 def self.get_version_parts(version) parts = version.split('.').map(&:to_i) parts.fill(0, parts.length...3) # add 0 if needed to ensure array has at least 3 components parts end |
.is_hotfix?(version) ⇒ Bool
Determines if a version name corresponds to a hotfix
79 80 81 82 83 84 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/android/android_version_helper.rb', line 79 def self.is_hotfix?(version) return false if version[VERSION_NAME].start_with?(ALPHA_PREFIX) vp = get_version_parts(version[VERSION_NAME]) (vp.length > 2) && (vp[HOTFIX_NUMBER] != 0) end |
.remove_beta_suffix(version) ⇒ String
Remove the beta suffix (part after the ‘-`) from a version string
110 111 112 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/android/android_version_helper.rb', line 110 def self.remove_beta_suffix(version) version.split('-')[0] end |