Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Breaking Changes

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

### New Features
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ class IosGetAppVersionAction < Action
def self.run(params)
require_relative '../../helper/ios/ios_version_helper'

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']

Fastlane::Helper::Ios::VersionHelper.get_public_version
public_version_xcconfig_file = params[:public_version_xcconfig_file]
Fastlane::Helper::Ios::VersionHelper.get_xcconfig_public_version(xcconfig_file: public_version_xcconfig_file)
end

#####################################################
Expand All @@ -22,7 +21,15 @@ def self.details
end

def self.available_options
# Define all options your action supports.
[
FastlaneCore::ConfigItem.new(
key: :public_version_xcconfig_file,
env_name: 'FL_IOS_PUBLIC_VERSION_XCCONFIG_FILE',
description: 'Path to the .xcconfig file containing the public app version',
type: String,
optional: false
),
]
end

def self.output
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,30 @@ module VersionHelper

# Returns the public-facing version string.
#
# @param [String] xcconfig_file The path for the .xcconfig file containing the public-facing version
#
# @return [String] The public-facing version number, extracted from the VERSION_LONG entry of the xcconfig file.
# - If this version is a hotfix (more than 2 parts and 3rd part is non-zero), returns the "X.Y.Z" formatted string
# - Otherwise (not a hotfix / 3rd part of version is 0), returns "X.Y" formatted version number
#
def self.get_xcconfig_public_version(xcconfig_file:)
version = read_long_version_from_config_file(xcconfig_file)
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

# Returns the public-facing version string.
#
# @return [String] The public-facing version number, extracted from the VERSION_LONG entry of the xcconfig file.
# - If this version is a hotfix (more than 2 parts and 3rd part is non-zero), returns the "X.Y.Z" formatted string
# - Otherwise (not a hotfix / 3rd part of version is 0), returns "X.Y" formatted version number
#
# @deprecated This method is going to be removed soon due to it's dependency on `ENV['PUBLIC_CONFIG_FILE']` via `get_build_version`.
#
def self.get_public_version
version = get_build_version
version = get_build_version()
vp = get_version_parts(version)
return "#{vp[MAJOR_NUMBER]}.#{vp[MINOR_NUMBER]}" unless is_hotfix?(version)

Expand Down Expand Up @@ -169,15 +187,17 @@ def self.is_hotfix?(version)
# @return [String] The current version according to the public xcconfig file.
#
def self.get_build_version
versions = get_version_strings()[0]
xcconfig_file = ENV['PUBLIC_CONFIG_FILE']
read_long_version_from_config_file(xcconfig_file)
end

# Returns the current value of the `VERSION_LONG` key from the internal xcconfig file
#
# @return [String] The current version according to the internal xcconfig file.
#
def self.get_internal_version
get_version_strings()[1]
xcconfig_file = ENV['INTERNAL_CONFIG_FILE']
read_long_version_from_config_file(xcconfig_file)
end

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

# Read the version numbers from the xcconfig file
#
# @env PUBLIC_CONFIG_FILE The path to the xcconfig file containing the public version numbers.
# @env INTERNAL_CONFIG_FILE The path to the xcconfig file containing the internal version numbers. Can be nil.
#
# @return [String] Array of long version strings found.
# The first element is always present and contains the version extracted from the public config file
# The second element is the version extracted from the internal config file, only present if one was provided.
def self.get_version_strings
version_strings = []
version_strings << read_long_version_from_config_file(ENV['PUBLIC_CONFIG_FILE'])
version_strings << read_long_version_from_config_file(ENV['INTERNAL_CONFIG_FILE']) unless ENV['INTERNAL_CONFIG_FILE'].nil?

return version_strings
end

# Ensure that the version provided is only composed of number parts and return the validated string
#
# @param [String] version The version string to validate
Expand Down
4 changes: 2 additions & 2 deletions spec/ios_bump_version_release_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe Fastlane::Actions::IosBumpVersionReleaseAction do
let(:default_branch) { 'my_new_branch' }
let(:versions) { ['6.30'] }
let(:version) { '6.30' }
let(:next_version) { '6.31.0.0' }
let(:next_version_short) { '6.31' }

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

allow(Fastlane::Helper::Ios::VersionHelper).to receive(:get_version_strings).and_return(versions)
allow(Fastlane::Helper::Ios::VersionHelper).to receive(:read_from_config_file).and_return(version)
allow(Fastlane::Helper::Ios::VersionHelper).to receive(:update_xc_configs).with(next_version, next_version_short, nil)
end

Expand Down
41 changes: 41 additions & 0 deletions spec/ios_get_app_version_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
require 'spec_helper'

describe Fastlane::Actions::IosGetAppVersionAction do
describe 'getting the public app version from the provided .xcconfig file' do
it 'parses the xcconfig file format correctly and gets the public version' do
xcconfig_mock_content = <<~CONTENT
// a comment
VERSION_SHORT=6
VERSION_LONG=6.30.0
CONTENT

allow(File).to receive(:exist?).and_return(true)

expect_version(xcconfig_mock_content: xcconfig_mock_content, expected_version: '6.30')
end

it 'parses the xcconfig file format correctly and gets the public hotfix version' do
xcconfig_mock_content = <<~CONTENT
VERSION_SHORT=6
// a comment
VERSION_LONG=6.30.1
CONTENT

allow(File).to receive(:exist?).and_return(true)

expect_version(xcconfig_mock_content: xcconfig_mock_content, expected_version: '6.30.1')
end

def expect_version(xcconfig_mock_content:, expected_version:)
xcconfig_mock_file_path = File.join('mock', 'file', 'path')

allow(File).to receive(:open).with(xcconfig_mock_file_path, 'r').and_yield(StringIO.new(xcconfig_mock_content))

version_result = run_described_fastlane_action(
public_version_xcconfig_file: xcconfig_mock_file_path
)

expect(version_result).to eq(expected_version)
end
end
end