Skip to content

Commit 5ca4081

Browse files
authored
Merge pull request #445 from iangmaia/add/xconfig-param-on-ios_get_app_version
Add configuration item for .xcconfig file in `ios_get_app_version`
2 parents 4b398ed + fce43b3 commit 5ca4081

File tree

5 files changed

+78
-25
lines changed

5 files changed

+78
-25
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
### Breaking Changes
88

99
- Remove the `skip_glotpress` parameter from the `ios_bump_version_release` action [#443]
10+
- Add the `public_version_xcconfig_file` parameter to the `ios_get_app_version` action to replace the need for an environment variable [#445]
1011
- Remove the `ios_localize_project` and `ios_update_metadata` actions [#447]
1112

1213
### New Features

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_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

spec/ios_bump_version_release_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
describe Fastlane::Actions::IosBumpVersionReleaseAction do
44
let(:default_branch) { 'my_new_branch' }
5-
let(:versions) { ['6.30'] }
5+
let(:version) { '6.30' }
66
let(:next_version) { '6.31.0.0' }
77
let(:next_version_short) { '6.31' }
88

@@ -15,7 +15,7 @@
1515
allow(Fastlane::Helper::GitHelper).to receive(:checkout_and_pull).with(default_branch)
1616
allow(Fastlane::Helper::GitHelper).to receive(:create_branch).with("release/#{next_version_short}", from: default_branch)
1717

18-
allow(Fastlane::Helper::Ios::VersionHelper).to receive(:get_version_strings).and_return(versions)
18+
allow(Fastlane::Helper::Ios::VersionHelper).to receive(:read_from_config_file).and_return(version)
1919
allow(Fastlane::Helper::Ios::VersionHelper).to receive(:update_xc_configs).with(next_version, next_version_short, nil)
2020
end
2121

spec/ios_get_app_version_spec.rb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
require 'spec_helper'
2+
3+
describe Fastlane::Actions::IosGetAppVersionAction do
4+
describe 'getting the public app version from the provided .xcconfig file' do
5+
it 'parses the xcconfig file format correctly and gets the public version' do
6+
xcconfig_mock_content = <<~CONTENT
7+
// a comment
8+
VERSION_SHORT=6
9+
VERSION_LONG=6.30.0
10+
CONTENT
11+
12+
allow(File).to receive(:exist?).and_return(true)
13+
14+
expect_version(xcconfig_mock_content: xcconfig_mock_content, expected_version: '6.30')
15+
end
16+
17+
it 'parses the xcconfig file format correctly and gets the public hotfix version' do
18+
xcconfig_mock_content = <<~CONTENT
19+
VERSION_SHORT=6
20+
// a comment
21+
VERSION_LONG=6.30.1
22+
CONTENT
23+
24+
allow(File).to receive(:exist?).and_return(true)
25+
26+
expect_version(xcconfig_mock_content: xcconfig_mock_content, expected_version: '6.30.1')
27+
end
28+
29+
def expect_version(xcconfig_mock_content:, expected_version:)
30+
xcconfig_mock_file_path = File.join('mock', 'file', 'path')
31+
32+
allow(File).to receive(:open).with(xcconfig_mock_file_path, 'r').and_yield(StringIO.new(xcconfig_mock_content))
33+
34+
version_result = run_described_fastlane_action(
35+
public_version_xcconfig_file: xcconfig_mock_file_path
36+
)
37+
38+
expect(version_result).to eq(expected_version)
39+
end
40+
end
41+
end

0 commit comments

Comments
 (0)