Skip to content

Commit 5cf95d2

Browse files
Merge pull request #458 from wordpress-mobile/add/get-build-number-action
Add `ios_get_build_number` action
2 parents e4b28a4 + d514621 commit 5cf95d2

File tree

3 files changed

+120
-1
lines changed

3 files changed

+120
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ _None_
1010

1111
### New Features
1212

13-
_None_
13+
- Add `ios_get_build_number` action to get the current build number from an `xcconfig` file. [#458]
14+
1415

1516
### Bug Fixes
1617

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
module Fastlane
2+
module Actions
3+
class IosGetBuildNumberAction < Action
4+
def self.run(params)
5+
require_relative '../../helper/ios/ios_version_helper'
6+
7+
xcconfig_file_path = params[:xcconfig_file_path]
8+
Fastlane::Helper::Ios::VersionHelper.read_build_number_from_config_file(xcconfig_file_path)
9+
end
10+
11+
#####################################################
12+
# @!group Documentation
13+
#####################################################
14+
15+
def self.description
16+
'Gets the build number of the app'
17+
end
18+
19+
def self.details
20+
'Gets the build number of the app'
21+
end
22+
23+
def self.available_options
24+
[
25+
FastlaneCore::ConfigItem.new(
26+
key: :xcconfig_file_path,
27+
env_name: 'FL_IOS_XCCONFIG_FILE_PATH',
28+
description: 'Path to the .xcconfig file containing the build number',
29+
type: String,
30+
optional: false
31+
),
32+
]
33+
end
34+
35+
def self.output
36+
# Define the shared values you are going to provide
37+
end
38+
39+
def self.return_value
40+
# If you method provides a return value, you can describe here what it does
41+
'Return the build number of the app'
42+
end
43+
44+
def self.authors
45+
# So no one will ever forget your contribution to fastlane :) You are awesome btw!
46+
['Automattic']
47+
end
48+
49+
def self.is_supported?(platform)
50+
[:ios, :mac].include?(platform)
51+
end
52+
end
53+
end
54+
end

spec/ios_get_build_number_spec.rb

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
require 'spec_helper'
2+
3+
describe Fastlane::Actions::IosGetBuildNumberAction do
4+
describe 'getting the build number from the provided .xcconfig file' do
5+
it 'parses an xcconfig file with keys without spacing and returns the correct build number' do
6+
xcconfig_mock_content = <<~CONTENT
7+
// a comment
8+
VERSION_SHORT=6
9+
VERSION_LONG=6.30.0
10+
BUILD_NUMBER=1940
11+
CONTENT
12+
13+
expect_build_number(xcconfig_mock_content: xcconfig_mock_content, expected_build_number: '1940')
14+
end
15+
16+
it 'parses an xcconfig file with keys with spaces and returns a nil build number' do
17+
xcconfig_mock_content = <<~CONTENT
18+
VERSION_SHORT = 6
19+
VERSION_LONG = 6.30.1
20+
BUILD_NUMBER = 1940
21+
CONTENT
22+
23+
expect_build_number(xcconfig_mock_content: xcconfig_mock_content, expected_build_number: nil)
24+
end
25+
26+
it 'parses an xcconfig file with an invalid format and returns a nil build number' do
27+
xcconfig_mock_content = <<~CONTENT
28+
VERSION_SHORT = 6
29+
VERSION_LONG = 6.30.1
30+
BUILD_NUMBER 1940
31+
CONTENT
32+
33+
expect_build_number(xcconfig_mock_content: xcconfig_mock_content, expected_build_number: nil)
34+
end
35+
36+
it 'parses an xcconfig file with no build number and returns a nil build number' do
37+
xcconfig_mock_content = <<~CONTENT
38+
VERSION_SHORT = 6
39+
// a comment
40+
CONTENT
41+
42+
expect_build_number(xcconfig_mock_content: xcconfig_mock_content, expected_build_number: nil)
43+
end
44+
45+
it 'throws an error when the xcconfig file does not exist' do
46+
expect do
47+
run_described_fastlane_action(
48+
xcconfig_file_path: 'file/not/found'
49+
)
50+
# Ruby error for 'No such file or directory': https://ruby-doc.org/core-2.7.4/SystemCallError.html
51+
end.to raise_error(Errno::ENOENT)
52+
end
53+
54+
def expect_build_number(xcconfig_mock_content:, expected_build_number:)
55+
with_tmp_file(named: 'mock_xcconfig.xcconfig', content: xcconfig_mock_content) do |tmp_file_path|
56+
build_number_result = run_described_fastlane_action(
57+
xcconfig_file_path: tmp_file_path
58+
)
59+
60+
expect(build_number_result).to eq(expected_build_number)
61+
end
62+
end
63+
end
64+
end

0 commit comments

Comments
 (0)