Skip to content

Commit 476cf80

Browse files
committed
Add ConfigItem for .xcconfig to replace env var on ios_get_app_version
1 parent 4b398ed commit 476cf80

File tree

2 files changed

+34
-23
lines changed

2 files changed

+34
-23
lines changed

lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_get_app_version.rb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ class IosGetAppVersionAction < Action
44
def self.run(params)
55
require_relative '../../helper/ios/ios_version_helper'
66

7-
UI.user_error!('You need to set at least the PUBLIC_CONFIG_FILE env var to the path to the public xcconfig file') unless ENV['PUBLIC_CONFIG_FILE']
8-
9-
Fastlane::Helper::Ios::VersionHelper.get_public_version
7+
public_version_xcconfig_file = params[:public_version_xcconfig_file]
8+
Fastlane::Helper::Ios::VersionHelper.get_xcconfig_public_version(xcconfig_file: public_version_xcconfig_file)
109
end
1110

1211
#####################################################
@@ -22,7 +21,15 @@ def self.details
2221
end
2322

2423
def self.available_options
25-
# Define all options your action supports.
24+
[
25+
FastlaneCore::ConfigItem.new(
26+
key: :public_version_xcconfig_file,
27+
env_name: 'FL_IOS_GET_APP_VERSION_PUBLIC_VERSION_XCCONFIG_FILE',
28+
description: 'Path to the .xcconfig file containing the public app version',
29+
type: String,
30+
optional: false
31+
),
32+
]
2633
end
2734

2835
def self.output

lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_version_helper.rb

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,30 @@ module VersionHelper
1515

1616
# Returns the public-facing version string.
1717
#
18+
# @param [String] xcconfig_file The path for the .xcconfig file containing the public-facing version
19+
#
1820
# @return [String] The public-facing version number, extracted from the VERSION_LONG entry of the xcconfig file.
1921
# - If this version is a hotfix (more than 2 parts and 3rd part is non-zero), returns the "X.Y.Z" formatted string
2022
# - Otherwise (not a hotfix / 3rd part of version is 0), returns "X.Y" formatted version number
2123
#
24+
def self.get_xcconfig_public_version(xcconfig_file:)
25+
version = read_long_version_from_config_file(xcconfig_file)
26+
vp = get_version_parts(version)
27+
return "#{vp[MAJOR_NUMBER]}.#{vp[MINOR_NUMBER]}" unless is_hotfix?(version)
28+
29+
"#{vp[MAJOR_NUMBER]}.#{vp[MINOR_NUMBER]}.#{vp[HOTFIX_NUMBER]}"
30+
end
31+
32+
# Returns the public-facing version string.
33+
#
34+
# @return [String] The public-facing version number, extracted from the VERSION_LONG entry of the xcconfig file.
35+
# - If this version is a hotfix (more than 2 parts and 3rd part is non-zero), returns the "X.Y.Z" formatted string
36+
# - Otherwise (not a hotfix / 3rd part of version is 0), returns "X.Y" formatted version number
37+
#
38+
# @deprecated This method is going to be removed soon due to it's dependency on `ENV['PUBLIC_CONFIG_FILE']` via `get_build_version`.
39+
#
2240
def self.get_public_version
23-
version = get_build_version
41+
version = get_build_version()
2442
vp = get_version_parts(version)
2543
return "#{vp[MAJOR_NUMBER]}.#{vp[MINOR_NUMBER]}" unless is_hotfix?(version)
2644

@@ -169,15 +187,17 @@ def self.is_hotfix?(version)
169187
# @return [String] The current version according to the public xcconfig file.
170188
#
171189
def self.get_build_version
172-
versions = get_version_strings()[0]
190+
xcconfig_file = ENV['PUBLIC_CONFIG_FILE']
191+
read_long_version_from_config_file(xcconfig_file)
173192
end
174193

175194
# Returns the current value of the `VERSION_LONG` key from the internal xcconfig file
176195
#
177196
# @return [String] The current version according to the internal xcconfig file.
178197
#
179198
def self.get_internal_version
180-
get_version_strings()[1]
199+
xcconfig_file = ENV['INTERNAL_CONFIG_FILE']
200+
read_long_version_from_config_file(xcconfig_file)
181201
end
182202

183203
# Prints the current and next release version numbers to stdout, then return the next release version
@@ -301,22 +321,6 @@ def self.read_from_config_file(key, filePath)
301321
return nil
302322
end
303323

304-
# Read the version numbers from the xcconfig file
305-
#
306-
# @env PUBLIC_CONFIG_FILE The path to the xcconfig file containing the public version numbers.
307-
# @env INTERNAL_CONFIG_FILE The path to the xcconfig file containing the internal version numbers. Can be nil.
308-
#
309-
# @return [String] Array of long version strings found.
310-
# The first element is always present and contains the version extracted from the public config file
311-
# The second element is the version extracted from the internal config file, only present if one was provided.
312-
def self.get_version_strings
313-
version_strings = []
314-
version_strings << read_long_version_from_config_file(ENV['PUBLIC_CONFIG_FILE'])
315-
version_strings << read_long_version_from_config_file(ENV['INTERNAL_CONFIG_FILE']) unless ENV['INTERNAL_CONFIG_FILE'].nil?
316-
317-
return version_strings
318-
end
319-
320324
# Ensure that the version provided is only composed of number parts and return the validated string
321325
#
322326
# @param [String] version The version string to validate

0 commit comments

Comments
 (0)