fastlane-plugin-versioning 0.3.4 → 0.4.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +140 -8
- data/lib/fastlane/plugin/versioning/actions/ci_build_number.rb +11 -3
- data/lib/fastlane/plugin/versioning/actions/get_app_store_version_number.rb +6 -6
- data/lib/fastlane/plugin/versioning/actions/get_build_number_from_plist.rb +19 -7
- data/lib/fastlane/plugin/versioning/actions/get_build_number_from_xcodeproj.rb +127 -0
- data/lib/fastlane/plugin/versioning/actions/get_info_plist_path.rb +45 -50
- data/lib/fastlane/plugin/versioning/actions/get_version_number_from_git_branch.rb +1 -1
- data/lib/fastlane/plugin/versioning/actions/get_version_number_from_plist.rb +20 -8
- data/lib/fastlane/plugin/versioning/actions/get_version_number_from_xcodeproj.rb +111 -0
- data/lib/fastlane/plugin/versioning/actions/increment_build_number_in_plist.rb +36 -10
- data/lib/fastlane/plugin/versioning/actions/increment_build_number_in_xcodeproj.rb +127 -0
- data/lib/fastlane/plugin/versioning/actions/increment_version_number_in_plist.rb +39 -14
- data/lib/fastlane/plugin/versioning/actions/increment_version_number_in_xcodeproj.rb +178 -0
- data/lib/fastlane/plugin/versioning/version.rb +1 -1
- metadata +11 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a1f3c3811fd467e7d69c94314d4847e624fb962f5b32b52bc0f1e752b3fc6255
|
4
|
+
data.tar.gz: 3ef305e276491b37de4c7f7067fc8e1e5d0f6e10ce4fe36b5ad5ddc9e5d2809c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c26a7e8269c4d60aabab4d1c04323cedbd91c74df6042431275537fe1f3b6496526d66a93f317e60cd7b79d3db7c1b0c2cf9c40986b6b0dddef41f044e4f2509
|
7
|
+
data.tar.gz: fe91e4da9d9aeccb554f81bd9160bd40e41aea4414f68be97340ec26524c822af0737191d21c02d7d85c0cae922ad3088fda94f47ab352cc782f4ca64b839eb0
|
data/README.md
CHANGED
@@ -5,7 +5,6 @@
|
|
5
5
|
[![Gem](https://img.shields.io/gem/v/fastlane-plugin-versioning.svg?style=flat)](http://rubygems.org/gems/fastlane-plugin-versioning)
|
6
6
|
[![fastlane Plugin Badge](https://rawcdn.githack.com/fastlane/fastlane/master/fastlane/assets/plugin-badge.svg)](https://rubygems.org/gems/fastlane-plugin-versioning)
|
7
7
|
|
8
|
-
|
9
8
|
## Getting Started
|
10
9
|
|
11
10
|
This project is a [fastlane](https://github.com/fastlane/fastlane) plugin. To get started with fastlane-plugin-versioning, add it to your project by running:
|
@@ -17,14 +16,24 @@ fastlane add_plugin versioning
|
|
17
16
|
## About versioning
|
18
17
|
|
19
18
|
Extends fastlane versioning actions. Allows to set/get versions without using agvtool and do some other small tricks.
|
20
|
-
Note that all schemes that you pass to actions like `increment_version_number_in_plist` or `get_info_plist_path` in `scheme` parameter must be shared.
|
21
|
-
To make your scheme shared go to "Manage schemes" in Xcode and
|
19
|
+
Note that all schemes that you pass to actions like `increment_version_number_in_plist`, `increment_build_number_in_xcodeproj` or `get_info_plist_path` in `scheme` parameter must be shared.
|
20
|
+
To make your scheme shared go to "Manage schemes" in Xcode and tick "Shared" checkbox near your scheme.
|
21
|
+
|
22
|
+
|
23
|
+
### what is this `plist_build_setting_support` stuff about?!
|
24
|
+
If you have a xcodeproject and have updated to Xcode 11, you'll notice that if you change your build and version numbers through the UI, the actual numbers are now stored inside build settings inside build confiugration. The Info.plist file -- where they used to be stored -- now contains build setting variables (looks like `$(CURRENT_PROJECT_VERSION)` or `$(MARKETING_VERSION)`, for build number and version number respectively).
|
25
|
+
If you are at this migration 'turning point', you have two options. you can either:
|
26
|
+
1. simply add `plist_build_setting_support: true` to your plist action parameters
|
27
|
+
2. change the command to be the xcodeproj variants - i.e. `increment_version_number_in_xcodeproj` or `increment_build_number_in_xcodeproj`
|
28
|
+
|
29
|
+
these also apply to the `getters` of build and version numbers.
|
30
|
+
We will leave the plist actions in, as for those consumers who are limited to their upgrade path.
|
22
31
|
|
23
32
|
## Actions
|
24
33
|
|
25
34
|
### increment_version_number_in_plist
|
26
35
|
|
27
|
-
Increment/set version number in Info.plist of specific target. Doesn't use agvtool (unlike default increment_version_number).
|
36
|
+
Increment/set the version number in a Info.plist of specific target. Doesn't use `agvtool` (unlike default `increment_version_number`).
|
28
37
|
|
29
38
|
```ruby
|
30
39
|
increment_version_number_in_plist # Automatically increment patch version number.
|
@@ -58,20 +67,42 @@ increment_version_number_in_plist(
|
|
58
67
|
# (optional)
|
59
68
|
target: 'TestTarget' # or `scheme`
|
60
69
|
)
|
70
|
+
|
71
|
+
increment_version_number_in_plist(
|
72
|
+
# specify specific version number (optional, omitting it increments patch version number)
|
73
|
+
version_number: '2.1.1',
|
74
|
+
# (optional, you must specify the path to your main Xcode project if it is not in the project root directory
|
75
|
+
# or if you have multiple xcodeproj's in the root directory)
|
76
|
+
xcodeproj: './path/to/MyApp.xcodeproj'
|
77
|
+
# (optional)
|
78
|
+
target: 'TestTarget' # or `scheme`
|
79
|
+
plist_build_setting_support: true, # optional, and defaulting to false.
|
80
|
+
# setting this will resolve the version number using the relevant build settings from your xcodeproj.
|
81
|
+
)
|
82
|
+
|
61
83
|
```
|
62
84
|
|
85
|
+
#### plist_build_setting_support
|
86
|
+
`get_version_number_from_plist` supports the `plist_build_setting_support` flag, and will either use the other parameters you pass to resolve a particular build configuration to edit, _OR_ change __ALL__ of them.
|
87
|
+
|
88
|
+
|
63
89
|
### get_version_number_from_plist
|
64
90
|
|
65
|
-
Get version number from Info.plist of specific target. Doesn't use agvtool (unlike default get_version_number).
|
91
|
+
Get the version number from an Info.plist of specific target. Doesn't use `agvtool` (unlike default `get_version_number`).
|
66
92
|
|
67
93
|
```ruby
|
68
94
|
version = get_version_number_from_plist(xcodeproj: 'Project.xcodeproj', # optional
|
69
95
|
target: 'TestTarget', # optional, or `scheme`
|
70
96
|
# optional, must be specified if you have different Info.plist build settings
|
71
97
|
# for different build configurations
|
98
|
+
plist_build_setting_support: true, # optional, and defaulting to false. setting this will
|
99
|
+
# resolve the version number using the relevant build settings from your xcodeproj.
|
72
100
|
build_configuration_name: 'Release')
|
73
101
|
```
|
74
102
|
|
103
|
+
#### plist_build_setting_support
|
104
|
+
`get_version_number_from_plist` supports the `plist_build_setting_support` flag, and will either use the other parameters you pass to resolve a particular build configuration to retrieve, _OR_ pick the first it finds.
|
105
|
+
|
75
106
|
### get_app_store_version_number
|
76
107
|
|
77
108
|
|
@@ -98,7 +129,7 @@ version = get_version_number_from_git_branch(pattern: 'release-#')
|
|
98
129
|
|
99
130
|
### increment_build_number_in_plist
|
100
131
|
|
101
|
-
Increment/set build number in Info.plist of specific target. Doesn't use agvtool (unlike default increment_version_number).
|
132
|
+
Increment/set build number in Info.plist of specific target. Doesn't use `agvtool` (unlike default `increment_version_number`).
|
102
133
|
|
103
134
|
```ruby
|
104
135
|
increment_build_number_in_plist # Automatically increments the last part of the build number.
|
@@ -107,16 +138,115 @@ increment_build_number_in_plist(
|
|
107
138
|
)
|
108
139
|
```
|
109
140
|
|
141
|
+
#### plist_build_setting_support
|
142
|
+
`increment_build_number_in_plist` supports the `plist_build_setting_support` flag, and will either use the other parameters you pass to resolve a particular build configuration to edit, _OR_ change __ALL__ of them.
|
143
|
+
|
110
144
|
### get_build_number_from_plist
|
111
145
|
|
112
|
-
Get build number from Info.plist of specific target. Doesn't use agvtool (unlike default get_build_number).
|
146
|
+
Get the build number from an Info.plist of specific target. Doesn't use `agvtool` (unlike default `get_build_number`).
|
113
147
|
|
114
148
|
```ruby
|
115
149
|
version = get_build_number_from_plist(xcodeproj: "Project.xcodeproj", # optional
|
150
|
+
target: 'TestTarget', # optional, or `scheme`
|
151
|
+
plist_build_setting_support: true, # optional, and defaulting to false. setting this will
|
152
|
+
# resolve the build number using the relevant build settings from your xcodeproj.
|
153
|
+
build_configuration_name: 'Release') # optional, must be specified if you have different Info.plist build settings for different build configurations
|
154
|
+
```
|
155
|
+
|
156
|
+
#### plist_build_setting_support
|
157
|
+
`get_build_number_from_plist` supports the `plist_build_setting_support` flag, and will either use the other parameters you pass to resolve a particular build configuration to retrieve, _OR_ pick the first it finds.
|
158
|
+
|
159
|
+
### get_build_number_from_xcodeproj
|
160
|
+
|
161
|
+
Get the build number from a xcodeproj - specific to a target. Doesn't use `agvtool` (unlike default `get_build_number`).
|
162
|
+
|
163
|
+
```ruby
|
164
|
+
version = get_build_number_from_xcodeproj(xcodeproj: "Project.xcodeproj", # optional
|
116
165
|
target: 'TestTarget', # optional, or `scheme`
|
117
166
|
build_configuration_name: 'Release') # optional, must be specified if you have different Info.plist build settings for different build configurations
|
118
167
|
```
|
119
168
|
|
169
|
+
### get_version_number_from_xcodeproj
|
170
|
+
|
171
|
+
Get the version number from a xcodeproj - specific to a target. Doesn't use `agvtool` (unlike default `get_build_number`).
|
172
|
+
|
173
|
+
```ruby
|
174
|
+
version = get_version_number_from_xcodeproj(xcodeproj: 'Project.xcodeproj', # optional
|
175
|
+
target: 'TestTarget', # optional, or `scheme`
|
176
|
+
# optional, must be specified if you have different Info.plist build settings
|
177
|
+
# for different build configurations
|
178
|
+
build_configuration_name: 'Release')
|
179
|
+
```
|
180
|
+
|
181
|
+
### increment_version_number_in_xcodeproj
|
182
|
+
|
183
|
+
Increment/set the version number in a xcodeproj of specific target. Doesn't use `agvtool` (unlike default `increment_version_number`).
|
184
|
+
|
185
|
+
```ruby
|
186
|
+
increment_version_number_in_xcodeproj # Automatically increment patch version number.
|
187
|
+
increment_version_number_in_xcodeproj(
|
188
|
+
bump_type: 'patch' # Automatically increment patch version number
|
189
|
+
)
|
190
|
+
increment_version_number_in_xcodeproj(
|
191
|
+
bump_type: 'minor' # Automatically increment minor version number
|
192
|
+
)
|
193
|
+
increment_version_number_in_xcodeproj(
|
194
|
+
bump_type: 'minor',
|
195
|
+
omit_zero_patch_version: true # if true omits zero in patch version(so 42.10.0 will become 42.10 and 42.10.1 will remain 42.10.1), default is false
|
196
|
+
)
|
197
|
+
increment_version_number_in_xcodeproj(
|
198
|
+
bump_type: 'major' # Automatically increment major version number
|
199
|
+
)
|
200
|
+
increment_version_number_in_xcodeproj(
|
201
|
+
version_number: '2.1.1' # Set a specific version number
|
202
|
+
)
|
203
|
+
increment_version_number_in_xcodeproj(
|
204
|
+
# Automatically increment patch version number. Use App Store version number as a source.
|
205
|
+
version_source: 'appstore'
|
206
|
+
)
|
207
|
+
|
208
|
+
increment_version_number_in_xcodeproj(
|
209
|
+
# specify specific version number (optional, omitting it increments patch version number)
|
210
|
+
version_number: '2.1.1',
|
211
|
+
# (optional, you must specify the path to your main Xcode project if it is not in the project root directory
|
212
|
+
# or if you have multiple xcodeproj's in the root directory)
|
213
|
+
xcodeproj: './path/to/MyApp.xcodeproj'
|
214
|
+
# (optional)
|
215
|
+
target: 'TestTarget' # or `scheme`
|
216
|
+
)
|
217
|
+
|
218
|
+
```
|
219
|
+
|
220
|
+
### get_version_number_from_plist
|
221
|
+
|
222
|
+
Get version number from Info.plist of specific target. Doesn't use agvtool (unlike default `get_version_number`).
|
223
|
+
|
224
|
+
```ruby
|
225
|
+
version = get_version_number_from_plist(xcodeproj: 'Project.xcodeproj', # optional
|
226
|
+
target: 'TestTarget', # optional, or `scheme`
|
227
|
+
# optional, must be specified if you have different Info.plist build settings
|
228
|
+
# for different build configurations
|
229
|
+
plist_build_setting_support: true, # optional, and defaulting to false. setting this will
|
230
|
+
# resolve the version number using the relevant build settings from your xcodeproj.
|
231
|
+
build_configuration_name: 'Release')
|
232
|
+
```
|
233
|
+
|
234
|
+
#### plist_build_setting_support
|
235
|
+
`get_version_number_from_plist` supports the `plist_build_setting_support` flag, and will either use the other parameters you pass to resolve a particular build configuration to retrieve, _OR_ pick the first it finds.
|
236
|
+
|
237
|
+
### get_app_store_version_number
|
238
|
+
|
239
|
+
|
240
|
+
```ruby
|
241
|
+
version = get_app_store_version_number(xcodeproj: 'Project.xcodeproj', # optional
|
242
|
+
target: 'TestTarget', # optional, or `scheme`
|
243
|
+
# optional, must be specified if you have different Info.plist build settings
|
244
|
+
# for different build configurations
|
245
|
+
build_configuration_name: 'Release')
|
246
|
+
)
|
247
|
+
version = get_app_store_version_number(bundle_id: 'com.apple.Numbers')
|
248
|
+
|
249
|
+
```
|
120
250
|
|
121
251
|
### get_info_plist_path
|
122
252
|
|
@@ -131,7 +261,7 @@ get_info_plist_path(xcodeproj: 'Test.xcodeproj', # optional
|
|
131
261
|
|
132
262
|
### ci_build_number
|
133
263
|
|
134
|
-
Get CI system build number. Determined using environment variables defined by CI systems. Supports Jenkins, Travis CI, Circle CI, TeamCity, GoCD, Bamboo, Gitlab CI, Xcode Server, Bitbucket Pipelines
|
264
|
+
Get CI system build number. Determined using environment variables defined by CI systems. Supports Jenkins, Travis CI, Circle CI, TeamCity, GoCD, Bamboo, Gitlab CI, Xcode Server, Bitbucket Pipelines, BuddyBuild, AppVeyor. Returns `1` if build number cannot be determined.
|
135
265
|
|
136
266
|
```ruby
|
137
267
|
increment_build_number_in_plist(
|
@@ -139,6 +269,8 @@ increment_build_number_in_plist(
|
|
139
269
|
)
|
140
270
|
```
|
141
271
|
|
272
|
+
|
273
|
+
|
142
274
|
## Issues and Feedback
|
143
275
|
|
144
276
|
For any other issues and feedback about this plugin, please submit it to this repository.
|
@@ -27,7 +27,7 @@ module Fastlane
|
|
27
27
|
end
|
28
28
|
|
29
29
|
if ENV.key?('GITLAB_CI')
|
30
|
-
return ENV['CI_JOB_ID']
|
30
|
+
return ENV['CI_PIPELINE_IID'] || ENV['CI_JOB_ID']
|
31
31
|
end
|
32
32
|
|
33
33
|
if ENV.key?('XCS')
|
@@ -38,11 +38,19 @@ module Fastlane
|
|
38
38
|
return ENV['BITBUCKET_BUILD_NUMBER']
|
39
39
|
end
|
40
40
|
|
41
|
+
if ENV.key?('BITRISE_BUILD_NUMBER')
|
42
|
+
return ENV['BITRISE_BUILD_NUMBER']
|
43
|
+
end
|
44
|
+
|
41
45
|
if ENV.key?('BUDDYBUILD_BUILD_NUMBER')
|
42
46
|
return ENV['BUDDYBUILD_BUILD_NUMBER']
|
43
47
|
end
|
44
48
|
|
45
|
-
|
49
|
+
if ENV.key?('APPVEYOR_BUILD_NUMBER')
|
50
|
+
return ENV['APPVEYOR_BUILD_NUMBER']
|
51
|
+
end
|
52
|
+
|
53
|
+
UI.error("Cannot detect current CI build number. Defaulting to \"1\".")
|
46
54
|
"1"
|
47
55
|
end
|
48
56
|
|
@@ -55,7 +63,7 @@ module Fastlane
|
|
55
63
|
end
|
56
64
|
|
57
65
|
def self.authors
|
58
|
-
["Siarhei Fedartsou"]
|
66
|
+
["Siarhei Fedartsou", "John Douglas"]
|
59
67
|
end
|
60
68
|
|
61
69
|
def self.example_code
|
@@ -9,11 +9,11 @@ module Fastlane
|
|
9
9
|
bundle_id = params[:bundle_id]
|
10
10
|
else
|
11
11
|
if Helper.test?
|
12
|
-
plist = "/tmp/fastlane/tests/fastlane/Info.plist"
|
12
|
+
plist = "/tmp/fastlane/tests/fastlane/plist/Info.plist"
|
13
13
|
else
|
14
14
|
plist = GetInfoPlistPathAction.run(params)
|
15
15
|
end
|
16
|
-
bundle_id = GetInfoPlistValueAction.run(path: plist, key: 'CFBundleIdentifier')
|
16
|
+
bundle_id = GetInfoPlistValueAction.run(path: plist, key: 'CFBundleIdentifier') # TODO: add same kind of flag to support build setting variables
|
17
17
|
end
|
18
18
|
|
19
19
|
uri = URI("http://itunes.apple.com/lookup?bundleId=#{bundle_id}")
|
@@ -42,7 +42,7 @@ module Fastlane
|
|
42
42
|
env_name: "FL_APPSTORE_VERSION_NUMBER_BUNDLE_ID",
|
43
43
|
description: "Bundle ID of the application",
|
44
44
|
optional: true,
|
45
|
-
conflicting_options: [
|
45
|
+
conflicting_options: %i[xcodeproj target scheme build_configuration_name],
|
46
46
|
is_string: true),
|
47
47
|
FastlaneCore::ConfigItem.new(key: :xcodeproj,
|
48
48
|
env_name: "FL_VERSION_NUMBER_PROJECT",
|
@@ -56,12 +56,12 @@ module Fastlane
|
|
56
56
|
FastlaneCore::ConfigItem.new(key: :target,
|
57
57
|
env_name: "FL_VERSION_NUMBER_TARGET",
|
58
58
|
optional: true,
|
59
|
-
conflicting_options: [
|
59
|
+
conflicting_options: %i[bundle_id scheme],
|
60
60
|
description: "Specify a specific target if you have multiple per project, optional"),
|
61
61
|
FastlaneCore::ConfigItem.new(key: :scheme,
|
62
62
|
env_name: "FL_VERSION_NUMBER_SCHEME",
|
63
63
|
optional: true,
|
64
|
-
conflicting_options: [
|
64
|
+
conflicting_options: %i[bundle_id target],
|
65
65
|
description: "Specify a specific scheme if you have multiple per project, optional"),
|
66
66
|
FastlaneCore::ConfigItem.new(key: :build_configuration_name,
|
67
67
|
optional: true,
|
@@ -75,7 +75,7 @@ module Fastlane
|
|
75
75
|
end
|
76
76
|
|
77
77
|
def self.is_supported?(platform)
|
78
|
-
[
|
78
|
+
%i[ios mac].include? platform
|
79
79
|
end
|
80
80
|
end
|
81
81
|
end
|
@@ -3,14 +3,22 @@ module Fastlane
|
|
3
3
|
class GetBuildNumberFromPlistAction < Action
|
4
4
|
def self.run(params)
|
5
5
|
if Helper.test?
|
6
|
-
plist = "/tmp/fastlane/tests/fastlane/Info.plist"
|
6
|
+
plist = "/tmp/fastlane/tests/fastlane/plist/Info.plist"
|
7
7
|
else
|
8
8
|
plist = GetInfoPlistPathAction.run(params)
|
9
9
|
end
|
10
10
|
|
11
|
-
|
11
|
+
if params[:plist_build_setting_support]
|
12
|
+
UI.important "build number will originate from xcodeproj"
|
13
|
+
build_number = GetBuildNumberFromXcodeprojAction.run(params)
|
14
|
+
else
|
15
|
+
UI.important "build number will originate from plist."
|
16
|
+
build_number = GetInfoPlistValueAction.run(path: plist, key: 'CFBundleVersion')
|
17
|
+
end
|
18
|
+
|
12
19
|
# Store the number in the shared hash
|
13
|
-
Actions.lane_context[SharedValues::BUILD_NUMBER] =
|
20
|
+
Actions.lane_context[SharedValues::BUILD_NUMBER] = build_number
|
21
|
+
build_number
|
14
22
|
end
|
15
23
|
|
16
24
|
#####################################################
|
@@ -23,7 +31,8 @@ module Fastlane
|
|
23
31
|
|
24
32
|
def self.details
|
25
33
|
[
|
26
|
-
"This action will return the current build number set on your project's Info.plist."
|
34
|
+
"This action will return the current build number set on your project's Info.plist.",
|
35
|
+
"note that you can pass plist_build_setting_support: true, in which case it will return from your xcodeproj."
|
27
36
|
].join(' ')
|
28
37
|
end
|
29
38
|
|
@@ -49,8 +58,11 @@ module Fastlane
|
|
49
58
|
description: "Specify a specific scheme if you have multiple per project, optional"),
|
50
59
|
FastlaneCore::ConfigItem.new(key: :build_configuration_name,
|
51
60
|
optional: true,
|
52
|
-
description: "Specify a specific build configuration if you have different Info.plist build settings for each configuration")
|
53
|
-
|
61
|
+
description: "Specify a specific build configuration if you have different Info.plist build settings for each configuration"),
|
62
|
+
FastlaneCore::ConfigItem.new(key: :plist_build_setting_support,
|
63
|
+
description: "support automatic resolution of build setting from xcodeproj if not a literal value in the plist",
|
64
|
+
is_string: false,
|
65
|
+
default_value: false)
|
54
66
|
]
|
55
67
|
end
|
56
68
|
|
@@ -65,7 +77,7 @@ module Fastlane
|
|
65
77
|
end
|
66
78
|
|
67
79
|
def self.is_supported?(platform)
|
68
|
-
[
|
80
|
+
%i[ios mac].include? platform
|
69
81
|
end
|
70
82
|
end
|
71
83
|
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
module Fastlane
|
2
|
+
module Actions
|
3
|
+
class GetBuildNumberFromXcodeprojAction < Action
|
4
|
+
require 'xcodeproj'
|
5
|
+
require 'pathname'
|
6
|
+
|
7
|
+
def self.run(params)
|
8
|
+
unless params[:xcodeproj]
|
9
|
+
if Helper.test?
|
10
|
+
params[:xcodeproj] = "/tmp/fastlane/tests/fastlane/xcodeproj/versioning_fixture_project.xcodeproj"
|
11
|
+
else
|
12
|
+
params[:xcodeproj] = Dir["*.xcodeproj"][0] unless params[:xcodeproj]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
if params[:target]
|
17
|
+
build_number = get_build_number_using_target(params)
|
18
|
+
elsif params[:build_configuration_name] && params[:scheme]
|
19
|
+
build_number = get_build_number_using_scheme(params)
|
20
|
+
else
|
21
|
+
UI.important "not enough information to pick a specific target or build configuration. taking the first one from the project"
|
22
|
+
build_number = get_first_build_number_in_xcodeproj(params)
|
23
|
+
end
|
24
|
+
|
25
|
+
Actions.lane_context[SharedValues::BUILD_NUMBER] = build_number
|
26
|
+
build_number
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.get_first_build_number_in_xcodeproj(params)
|
30
|
+
project = Xcodeproj::Project.open(params[:xcodeproj])
|
31
|
+
configs = project.objects.select { |obj| select_build_configuration_predicate(nil, obj) }
|
32
|
+
configs.first.build_settings["CURRENT_PROJECT_VERSION"]
|
33
|
+
end
|
34
|
+
|
35
|
+
private_class_method
|
36
|
+
def self.select_build_configuration_predicate(name, configuration)
|
37
|
+
is_build_valid_configuration = configuration.isa == "XCBuildConfiguration" && !configuration.build_settings["PRODUCT_BUNDLE_IDENTIFIER"].nil?
|
38
|
+
is_build_valid_configuration &&= configuration.name == name unless name.nil?
|
39
|
+
return is_build_valid_configuration
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.get_build_number_using_target(params)
|
43
|
+
project = Xcodeproj::Project.open(params[:xcodeproj])
|
44
|
+
if params[:target]
|
45
|
+
target = project.targets.detect { |t| t.name == params[:target] }
|
46
|
+
else
|
47
|
+
# firstly we are trying to find modern application target
|
48
|
+
target = project.targets.detect do |t|
|
49
|
+
t.kind_of?(Xcodeproj::Project::Object::PBXNativeTarget) &&
|
50
|
+
t.product_type == 'com.apple.product-type.application'
|
51
|
+
end
|
52
|
+
target = project.targets[0] if target.nil?
|
53
|
+
end
|
54
|
+
|
55
|
+
build_number = target.resolved_build_setting('CURRENT_PROJECT_VERSION', true)
|
56
|
+
UI.user_error! 'Cannot resolve build number build setting.' if build_number.nil? || build_number.empty?
|
57
|
+
|
58
|
+
if !(build_configuration_name = params[:build_configuration_name]).nil?
|
59
|
+
build_number = build_number[build_configuration_name]
|
60
|
+
UI.user_error! "Cannot resolve $(CURRENT_PROJECT_VERSION) build setting for #{build_configuration_name}." if build_number.nil?
|
61
|
+
else
|
62
|
+
build_number = build_number.values.compact.uniq
|
63
|
+
UI.user_error! 'Cannot accurately resolve $(CURRENT_PROJECT_VERSION) build setting, try specifying :build_configuration_name.' if build_number.count > 1
|
64
|
+
build_number = build_number.first
|
65
|
+
end
|
66
|
+
|
67
|
+
build_number
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.get_build_number_using_scheme(params)
|
71
|
+
config = { project: params[:xcodeproj], scheme: params[:scheme], configuration: params[:build_configuration_name] }
|
72
|
+
project = FastlaneCore::Project.new(config)
|
73
|
+
project.select_scheme
|
74
|
+
|
75
|
+
build_number = project.build_settings(key: 'CURRENT_PROJECT_VERSION')
|
76
|
+
UI.user_error! "Cannot resolve $(CURRENT_PROJECT_VERSION) in for the scheme #{config.scheme} with the name #{params.configuration}" if build_number.nil? || build_number.empty?
|
77
|
+
build_number
|
78
|
+
end
|
79
|
+
|
80
|
+
#####################################################
|
81
|
+
# @!group Documentation
|
82
|
+
#####################################################
|
83
|
+
|
84
|
+
def self.description
|
85
|
+
"Get the build number of your project"
|
86
|
+
end
|
87
|
+
|
88
|
+
def self.details
|
89
|
+
'Gets the $(CURRENT_PROJECT_VERSION) build setting using the specified parameters, or the first if not enough parameters are passed.'
|
90
|
+
end
|
91
|
+
|
92
|
+
def self.available_options
|
93
|
+
[
|
94
|
+
FastlaneCore::ConfigItem.new(key: :xcodeproj,
|
95
|
+
env_name: "FL_BUILD_NUMBER_PROJECT",
|
96
|
+
description: "Optional, you must specify the path to your main Xcode project if it is not in the project root directory or if you have multiple *.xcodeproj's in the root directory",
|
97
|
+
optional: true,
|
98
|
+
verify_block: proc do |value|
|
99
|
+
UI.user_error!("Please pass the path to the project, not the workspace") if value.end_with? ".xcworkspace"
|
100
|
+
UI.user_error!("Could not find Xcode project at path '#{File.expand_path(value)}'") if !File.exist?(value) and !Helper.is_test?
|
101
|
+
end),
|
102
|
+
FastlaneCore::ConfigItem.new(key: :target,
|
103
|
+
env_name: "FL_BUILD_NUMBER_TARGET",
|
104
|
+
optional: true,
|
105
|
+
conflicting_options: [:scheme],
|
106
|
+
description: "Specify a specific target if you have multiple per project, optional"),
|
107
|
+
FastlaneCore::ConfigItem.new(key: :scheme,
|
108
|
+
env_name: "FL_BUILD_NUMBER_SCHEME",
|
109
|
+
optional: true,
|
110
|
+
conflicting_options: [:target],
|
111
|
+
description: "Specify a specific scheme if you have multiple per project, optional"),
|
112
|
+
FastlaneCore::ConfigItem.new(key: :build_configuration_name,
|
113
|
+
optional: true,
|
114
|
+
description: "Specify a specific build configuration if you have different build settings for each configuration")
|
115
|
+
]
|
116
|
+
end
|
117
|
+
|
118
|
+
def self.authors
|
119
|
+
["jdouglas-nz"]
|
120
|
+
end
|
121
|
+
|
122
|
+
def self.is_supported?(platform)
|
123
|
+
%i[ios mac].include? platform
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|