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'.freeze
- VERSION_CODE =
The key used in internal version Hash objects to hold the versionCode value
'code'.freeze
- 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-'.freeze
- RC_SUFFIX =
The suffix used in the versionName for RC (beta) versions
'-rc'.freeze
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.
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/android/android_version_helper.rb', line 59 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”`).
45 46 47 48 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/android/android_version_helper.rb', line 45 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
89 90 91 92 93 94 95 96 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/android/android_version_helper.rb', line 89 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`
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/android/android_version_helper.rb', line 26 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
119 120 121 122 123 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/android/android_version_helper.rb', line 119 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
77 78 79 80 81 82 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/android/android_version_helper.rb', line 77 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
108 109 110 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/android/android_version_helper.rb', line 108 def self.remove_beta_suffix(version) version.split('-')[0] end |