Module: Fastlane::Helper::Ios::VersionHelper
- Defined in:
- lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_version_helper.rb
Overview
A module containing helper methods to manipulate/extract/bump iOS version strings in xcconfig files
Constant Summary collapse
- 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
- BUILD_NUMBER =
The index for the build version number part
3
Class Method Summary collapse
-
.bump_build_number(build_number) ⇒ Int
Return the build number value incremented by one.
-
.bump_version_release ⇒ String
Prints the current and next release version numbers to stdout, then return the next release version.
-
.calc_next_build_version(version) ⇒ String
Compute the name of the next build version.
-
.calc_next_hotfix_version(version) ⇒ String
Compute the name of the next hotfix version.
-
.calc_next_release_version(version) ⇒ String
Compute the name of the next release version.
-
.calc_prev_build_version(version) ⇒ String
Compute the name of the previous build version.
-
.calc_prev_hotfix_version(version) ⇒ String
Compute the name of the previous hotfix version.
-
.calc_prev_release_version(version) ⇒ String
Compute the name of the previous release version.
-
.create_internal_version(version) ⇒ String
Create an internal version number, for which the build number is based on today’s date.
-
.get_build_version ⇒ String
Returns the current value of the ‘VERSION_LONG` key from the public xcconfig file.
-
.get_internal_version ⇒ String
Returns the current value of the ‘VERSION_LONG` key from the internal xcconfig file.
-
.get_public_version ⇒ String
deprecated
Deprecated.
This method is going to be removed soon due to it’s dependency on ‘ENV` via `get_build_version`.
-
.get_short_version_string(version) ⇒ String
Return the short version string “X.Y” from the full version.
-
.get_version_parts(version) ⇒ Array<String>
Split a version string into its 4 parts, ensuring its parts count is valid.
-
.get_xcconfig_public_version(xcconfig_file:) ⇒ String
Returns the public-facing version string.
-
.is_hotfix?(version) ⇒ Bool
Determines if a version number corresponds to a hotfix.
-
.is_int?(string) ⇒ Bool
Check if a string is an integer.
-
.read_build_number_from_config_file(file_path) ⇒ String
Extract the BUILD_NUMBER entry from an ‘xcconfig` file.
-
.read_from_config_file(key, file_path) ⇒ String
Read the value of a given key from an ‘.xcconfig` file.
-
.read_long_version_from_config_file(file_path) ⇒ String
Extract the VERSION_LONG entry from an ‘xcconfig` file.
-
.update_xc_config(file_path, new_version, new_version_short) ⇒ Object
Updates an xcconfig file with new values for VERSION_SHORT and VERSION_LONG entries.
-
.update_xc_configs(new_version, new_version_short, internal_version) ⇒ Object
Update the ‘.xcconfig` files (the public one, and the internal one if it exists) with the new version strings.
-
.verify_version(version) ⇒ String
Ensure that the version provided is only composed of number parts and return the validated string.
Class Method Details
.bump_build_number(build_number) ⇒ Int
Return the build number value incremented by one.
175 176 177 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_version_helper.rb', line 175 def self.bump_build_number(build_number) build_number.nil? ? 0 : build_number.to_i + 1 end |
.bump_version_release ⇒ String
Prints the current and next release version numbers to stdout, then return the next release version
212 213 214 215 216 217 218 219 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_version_helper.rb', line 212 def self.bump_version_release # Bump release current_version = get_public_version UI.("Current version: #{current_version}") new_version = calc_next_release_version(current_version) UI.("New version: #{new_version}") verify_version(new_version) end |
.calc_next_build_version(version) ⇒ String
Compute the name of the next build version.
109 110 111 112 113 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_version_helper.rb', line 109 def self.calc_next_build_version(version) vp = get_version_parts(version) vp[BUILD_NUMBER] += 1 "#{vp[MAJOR_NUMBER]}.#{vp[MINOR_NUMBER]}.#{vp[HOTFIX_NUMBER]}.#{vp[BUILD_NUMBER]}" end |
.calc_next_hotfix_version(version) ⇒ String
Compute the name of the next hotfix version.
122 123 124 125 126 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_version_helper.rb', line 122 def self.calc_next_hotfix_version(version) vp = get_version_parts(version) vp[HOTFIX_NUMBER] += 1 "#{vp[MAJOR_NUMBER]}.#{vp[MINOR_NUMBER]}.#{vp[HOTFIX_NUMBER]}" end |
.calc_next_release_version(version) ⇒ String
Compute the name of the next release version.
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_version_helper.rb', line 61 def self.calc_next_release_version(version) vp = get_version_parts(version) vp[MINOR_NUMBER] += 1 if vp[MINOR_NUMBER] == 10 vp[MAJOR_NUMBER] += 1 vp[MINOR_NUMBER] = 0 end "#{vp[MAJOR_NUMBER]}.#{vp[MINOR_NUMBER]}" end |
.calc_prev_build_version(version) ⇒ String
Compute the name of the previous build version.
135 136 137 138 139 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_version_helper.rb', line 135 def self.calc_prev_build_version(version) vp = get_version_parts(version) vp[BUILD_NUMBER] -= 1 unless (vp[BUILD_NUMBER]).zero? "#{vp[MAJOR_NUMBER]}.#{vp[MINOR_NUMBER]}.#{vp[HOTFIX_NUMBER]}.#{vp[BUILD_NUMBER]}" end |
.calc_prev_hotfix_version(version) ⇒ String
Compute the name of the previous hotfix version.
148 149 150 151 152 153 154 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_version_helper.rb', line 148 def self.calc_prev_hotfix_version(version) vp = get_version_parts(version) vp[HOTFIX_NUMBER] -= 1 unless (vp[HOTFIX_NUMBER]).zero? return "#{vp[MAJOR_NUMBER]}.#{vp[MINOR_NUMBER]}.#{vp[HOTFIX_NUMBER]}" unless (vp[HOTFIX_NUMBER]).zero? "#{vp[MAJOR_NUMBER]}.#{vp[MINOR_NUMBER]}" end |
.calc_prev_release_version(version) ⇒ String
Compute the name of the previous release version.
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_version_helper.rb', line 90 def self.calc_prev_release_version(version) vp = get_version_parts(version) if (vp[MINOR_NUMBER]).zero? vp[MAJOR_NUMBER] -= 1 vp[MINOR_NUMBER] = 9 else vp[MINOR_NUMBER] -= 1 end "#{vp[MAJOR_NUMBER]}.#{vp[MINOR_NUMBER]}" end |
.create_internal_version(version) ⇒ String
Create an internal version number, for which the build number is based on today’s date.
162 163 164 165 166 167 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_version_helper.rb', line 162 def self.create_internal_version(version) vp = get_version_parts(version) d = DateTime.now today_date = d.strftime('%Y%m%d') "#{vp[MAJOR_NUMBER]}.#{vp[MINOR_NUMBER]}.#{vp[HOTFIX_NUMBER]}.#{today_date}" end |
.get_build_version ⇒ String
Returns the current value of the ‘VERSION_LONG` key from the public xcconfig file
194 195 196 197 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_version_helper.rb', line 194 def self.get_build_version xcconfig_file = ENV['PUBLIC_CONFIG_FILE'] read_long_version_from_config_file(xcconfig_file) end |
.get_internal_version ⇒ String
Returns the current value of the ‘VERSION_LONG` key from the internal xcconfig file
203 204 205 206 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_version_helper.rb', line 203 def self.get_internal_version xcconfig_file = ENV['INTERNAL_CONFIG_FILE'] read_long_version_from_config_file(xcconfig_file) end |
.get_public_version ⇒ String
This method is going to be removed soon due to it’s dependency on ‘ENV` via `get_build_version`.
Returns the public-facing version string.
45 46 47 48 49 50 51 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_version_helper.rb', line 45 def self.get_public_version version = get_build_version vp = get_version_parts(version) return "#{vp[MAJOR_NUMBER]}.#{vp[MINOR_NUMBER]}" unless is_hotfix?(version) "#{vp[MAJOR_NUMBER]}.#{vp[MINOR_NUMBER]}.#{vp[HOTFIX_NUMBER]}" end |
.get_short_version_string(version) ⇒ String
Return the short version string “X.Y” from the full version.
78 79 80 81 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_version_helper.rb', line 78 def self.get_short_version_string(version) vp = get_version_parts(version) "#{vp[MAJOR_NUMBER]}.#{vp[MINOR_NUMBER]}" end |
.get_version_parts(version) ⇒ Array<String>
If the original version string contains less than 4 parts, the returned array is filled with zeros at the end to always contain 4 items.
Split a version string into its 4 parts, ensuring its parts count is valid
268 269 270 271 272 273 274 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_version_helper.rb', line 268 def self.get_version_parts(version) parts = version.split('.') parts = parts.fill('0', parts.length...4).map(&:to_i) UI.user_error!("Bad version string: #{version}") if parts.length > 4 parts end |
.get_xcconfig_public_version(xcconfig_file:) ⇒ String
Returns the public-facing version string.
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_version_helper.rb', line 26 def self.get_xcconfig_public_version(xcconfig_file:) version = read_long_version_from_config_file(xcconfig_file) UI.user_error!(".xcconfig file doesn't have a version configured") if version.nil? vp = get_version_parts(version) return "#{vp[MAJOR_NUMBER]}.#{vp[MINOR_NUMBER]}" unless is_hotfix?(version) "#{vp[MAJOR_NUMBER]}.#{vp[MINOR_NUMBER]}.#{vp[HOTFIX_NUMBER]}" end |
.is_hotfix?(version) ⇒ Bool
Determines if a version number corresponds to a hotfix
185 186 187 188 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_version_helper.rb', line 185 def self.is_hotfix?(version) vp = get_version_parts(version) (vp.length > 2) && (vp[HOTFIX_NUMBER] != 0) end |
.is_int?(string) ⇒ Bool
Check if a string is an integer
330 331 332 333 334 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_version_helper.rb', line 330 def self.is_int?(string) true if Integer(string) rescue StandardError false end |
.read_build_number_from_config_file(file_path) ⇒ String
Extract the BUILD_NUMBER entry from an ‘xcconfig` file
290 291 292 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_version_helper.rb', line 290 def self.read_build_number_from_config_file(file_path) read_from_config_file('BUILD_NUMBER', file_path) end |
.read_from_config_file(key, file_path) ⇒ String
Read the value of a given key from an ‘.xcconfig` file.
301 302 303 304 305 306 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_version_helper.rb', line 301 def self.read_from_config_file(key, file_path) UI.user_error!(".xcconfig file #{file_path} not found") unless File.exist?(file_path) config = Xcodeproj::Config.new(file_path) config.attributes[key] end |
.read_long_version_from_config_file(file_path) ⇒ String
Extract the VERSION_LONG entry from an ‘xcconfig` file
281 282 283 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_version_helper.rb', line 281 def self.read_long_version_from_config_file(file_path) read_from_config_file('VERSION_LONG', file_path) end |
.update_xc_config(file_path, new_version, new_version_short) ⇒ Object
Updates an xcconfig file with new values for VERSION_SHORT and VERSION_LONG entries. Also bumps the BUILD_NUMBER value from that config file if there is one present.
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_version_helper.rb', line 243 def self.update_xc_config(file_path, new_version, new_version_short) if File.exist?(file_path) UI.("Updating #{file_path} to version #{new_version_short}/#{new_version}") Action.sh("sed -i '' \"$(awk '/^VERSION_SHORT/{ print NR; exit }' \"#{file_path}\")s/=.*/=#{new_version_short}/\" \"#{file_path}\"") Action.sh("sed -i '' \"$(awk '/^VERSION_LONG/{ print NR; exit }' \"#{file_path}\")s/=.*/=#{new_version}/\" \"#{file_path}\"") build_number = read_build_number_from_config_file(file_path) unless build_number.nil? new_build_number = bump_build_number(build_number) Action.sh("sed -i '' \"$(awk '/^BUILD_NUMBER/{ print NR; exit }' \"#{file_path}\")s/=.*/=#{new_build_number}/\" \"#{file_path}\"") end else UI.user_error!("#{file_path} not found") end end |
.update_xc_configs(new_version, new_version_short, internal_version) ⇒ Object
Update the ‘.xcconfig` files (the public one, and the internal one if it exists) with the new version strings.
230 231 232 233 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_version_helper.rb', line 230 def self.update_xc_configs(new_version, new_version_short, internal_version) update_xc_config(ENV['PUBLIC_CONFIG_FILE'], new_version, new_version_short) update_xc_config(ENV['INTERNAL_CONFIG_FILE'], internal_version, new_version_short) unless ENV['INTERNAL_CONFIG_FILE'].nil? end |
.verify_version(version) ⇒ String
Ensure that the version provided is only composed of number parts and return the validated string
314 315 316 317 318 319 320 321 322 |
# File 'lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_version_helper.rb', line 314 def self.verify_version(version) v_parts = get_version_parts(version) v_parts.each do |part| UI.user_error!('Version value can only contains numbers.') unless is_int?(part) end "#{v_parts[MAJOR_NUMBER]}.#{v_parts[MINOR_NUMBER]}.#{v_parts[HOTFIX_NUMBER]}.#{v_parts[BUILD_NUMBER]}" end |