1
1
# frozen_string_literal: true
2
2
3
+ fastlane_require 'httparty'
4
+ fastlane_require 'rexml/document'
5
+
3
6
UI . abort_with_message! ( 'Please run fastlane via `bundle exec`' ) unless FastlaneCore ::Helper . bundler?
4
7
5
8
########################################################################
@@ -8,8 +11,9 @@ UI.abort_with_message!('Please run fastlane via `bundle exec`') unless FastlaneC
8
11
DEFAULT_BRANCH = 'main'
9
12
RELEASE_BRANCH = 'release'
10
13
PROJECT_ROOT_FOLDER = File . dirname ( File . expand_path ( __dir__ ) )
14
+ INFO_PLIST = File . join ( PROJECT_ROOT_FOLDER , 'DuckDuckGo/Info.plist' )
11
15
VERSION_CONFIG_PATH = File . join ( PROJECT_ROOT_FOLDER , 'Configuration/Version.xcconfig' )
12
- APP_STORE_BUILD_NUMBER_CONFIG_PATH = File . join ( PROJECT_ROOT_FOLDER , 'Configuration/AppStoreBuildNumber .xcconfig' )
16
+ BUILD_NUMBER_CONFIG_PATH = File . join ( PROJECT_ROOT_FOLDER , 'Configuration/BuildNumber .xcconfig' )
13
17
VERSION_CONFIG_DEFINITION = 'MARKETING_VERSION'
14
18
BUILD_NUMBER_CONFIG_DEFINITION = 'CURRENT_PROJECT_VERSION'
15
19
UPGRADABLE_EMBEDDED_FILES = [
@@ -99,23 +103,27 @@ platform :mac do
99
103
#
100
104
# - Cuts a new release branch
101
105
# - Updates submodules and embedded files
106
+ # - Pushes changes to remote
102
107
#
103
108
# @option [String] version (default: nil) Marketing version string
104
- # @option [Boolean] skip_confirm (default: false) If true, avoids any interactive prompt
105
109
# @option [Boolean] resume (default: false) If true, the lane can run from a release/ branch and will run dedicated prechecks.
110
+ # @option [Boolean] force (default: false) Don't ask for confirmation.
106
111
#
107
112
desc 'Executes the release preparation work in the repository'
108
113
lane :code_freeze do |options |
109
114
begin
110
115
options [ :resume ] ? macos_codefreeze_resume_prechecks : macos_codefreeze_prechecks
111
116
new_version = validate_new_version ( options )
112
- app_store_build_number = increment_app_store_build_number ( options )
117
+ build_number = increment_current_build_number ( options )
113
118
macos_create_release_branch ( version : new_version ) unless options [ :resume ]
114
119
macos_update_embedded_files
115
120
macos_update_version_and_build_number_config (
116
121
version : new_version ,
117
- build_number : app_store_build_number
122
+ build_number : build_number ,
123
+ force : options [ :force ]
118
124
)
125
+ sh ( 'git' , 'push' )
126
+
119
127
rescue => exception
120
128
if exception . message == "Tests have failed"
121
129
UI . user_error! %{Tests have failed.
@@ -131,6 +139,75 @@ platform :mac do
131
139
end
132
140
end
133
141
142
+ # Bumps build number for the current version and updates embedded files.
143
+ # Pushes changes to remote.
144
+ #
145
+ # - Should be called on an existing internal release branch.
146
+ # - Also runs unit tests after updating embedded files.
147
+ #
148
+ # @option [Boolean] force (default: false) Don't ask for confirmation.
149
+ #
150
+ desc 'Prepares new internal release on top of an existing one'
151
+ lane :bump_internal_release do |options |
152
+ begin
153
+ unless git_branch . start_with? ( RELEASE_BRANCH )
154
+ UI . abort_with_message! ( "Incorrect branch. Branch name must start with '#{ RELEASE_BRANCH } /'." )
155
+ end
156
+
157
+ force = options [ :force ] . nil? ? false : options [ :force ]
158
+ current_version = macos_current_version
159
+ current_build_number = macos_current_build_number
160
+ build_number = increment_current_build_number ( options )
161
+
162
+ UI . important ( "Current version is #{ current_version } (#{ current_build_number } )." )
163
+ UI . important ( "Will update to #{ current_version } (#{ build_number } )." )
164
+
165
+ unless force
166
+ unless UI . confirm ( "Do you want to continue?" )
167
+ UI . abort_with_message! ( 'Aborted by user.' )
168
+ end
169
+ end
170
+
171
+ macos_update_embedded_files
172
+ macos_update_version_and_build_number_config (
173
+ version : current_version ,
174
+ build_number : build_number ,
175
+ force : true
176
+ )
177
+ sh ( 'git' , 'push' )
178
+
179
+ rescue => exception
180
+ if exception . message == "Tests have failed"
181
+ UI . user_error! %{Tests have failed.
182
+ * If you believe the failing test is flaky, please retry the same fastlane command.
183
+ * If the failure looks legitimate, try to fix it, commit the fix (be sure to only
184
+ include the files you've changed while making a fix and leave other changed files
185
+ unmodified), and run the command again appending `resume:true`.
186
+ }
187
+ else
188
+ raise exception
189
+ end
190
+ end
191
+ end
192
+
193
+ # Updates marketing version to the specified one and increments build number by 1.
194
+ #
195
+ # @option [String] version Marketing version string.
196
+ # @option [Boolean] force (default: false) Don't ask for confirmation.
197
+ #
198
+ desc 'Executes the release preparation work in the repository'
199
+ lane :set_version do |options |
200
+ unless options [ :version ]
201
+ UI . user_error! 'You must provide a version.'
202
+ end
203
+ new_version = validate_new_version ( options )
204
+ build_number = increment_current_build_number ( options )
205
+ macos_update_version_and_build_number_config (
206
+ version : new_version ,
207
+ build_number : build_number
208
+ )
209
+ end
210
+
134
211
#################################################
135
212
# Helper functions
136
213
#################################################
@@ -229,30 +306,52 @@ platform :mac do
229
306
end
230
307
end
231
308
232
- # Calculates the new version or validate the provided one, if it exists
309
+ # Calculates the new version or validates the provided one, if it exists
233
310
# and prompts the user to confirm
234
311
#
235
312
# @option [String] version (default: nil) Marketing version string
313
+ # @option [Boolean] force (default: false) Don't ask for confirmation.
236
314
#
237
315
private_lane :validate_new_version do |options |
238
316
current_version = macos_current_version
239
317
user_version = format_user_version ( options [ :version ] )
240
318
new_version = user_version . nil? ? macos_bump_minor_version ( current_version ) : user_version
241
- unless UI . confirm (
242
- "Current version is #{ current_version } .\n New version is #{ new_version } .\n Do you want to continue?"
243
- )
244
- UI . abort_with_message! ( 'Aborted by user.' )
319
+ force = options [ :force ] . nil? ? false : options [ :force ]
320
+ unless force
321
+ unless UI . confirm (
322
+ "Current version is #{ current_version } .\n New version is #{ new_version } .\n Do you want to continue?"
323
+ )
324
+ UI . abort_with_message! ( 'Aborted by user.' )
325
+ end
245
326
end
246
327
new_version
247
328
end
248
329
249
330
# Checks current build number and increments it by 1.
250
331
#
251
- desc 'Increment App Store build number'
252
- private_lane :increment_app_store_build_number do
332
+ desc 'Increment build number'
333
+ private_lane :increment_current_build_number do
334
+ macos_current_build_number = [ fetch_testflight_build_number , fetch_appcast_build_number ] . max
253
335
macos_current_build_number + 1
254
336
end
255
337
338
+ private_lane :fetch_testflight_build_number do |options |
339
+ build_number = latest_testflight_build_number (
340
+ api_key : get_api_key ,
341
+ username : get_username ( options ) ,
342
+ platform : 'osx'
343
+ )
344
+ build_number
345
+ end
346
+
347
+ private_lane :fetch_appcast_build_number do |options |
348
+ url = sh ( "plutil -extract SUFeedURL raw #{ INFO_PLIST } " ) . chomp
349
+ xml = HTTParty . get ( url ) . body
350
+ xml_data = REXML ::Document . new ( xml )
351
+ versions = xml_data . get_elements ( '//rss/channel/item/sparkle:version' ) . map { |e | e . text . split ( '.' ) [ 0 ] . to_i }
352
+ versions . max
353
+ end
354
+
256
355
# Checks out a new branch from the current commit and pushes it
257
356
#
258
357
# @option [String] version (default: nil) Marketing version string
@@ -279,7 +378,7 @@ platform :mac do
279
378
# - Runs automated tests
280
379
# - Commits and pushes
281
380
#
282
- private_lane :macos_update_embedded_files do
381
+ private_lane :macos_update_embedded_files do | options |
283
382
sh ( "cd #{ PROJECT_ROOT_FOLDER } && ./scripts/update_embedded.sh" )
284
383
285
384
# Verify no unexpected files were modified
@@ -300,36 +399,35 @@ platform :mac do
300
399
modified_files . each { |modified_file | sh ( 'git' , 'add' , modified_file . to_s ) }
301
400
sh ( 'git' , 'commit' , '-m' , 'Update embedded files' )
302
401
ensure_git_status_clean
303
- sh ( 'git' , 'push' )
304
402
end
305
403
306
404
# Updates version in the config file
307
405
#
308
- # @option [String] version (default: nil) Marketing version string
406
+ # @option [String] version Marketing version string
407
+ # @option [String] build_number Build number
309
408
#
310
409
private_lane :macos_update_version_and_build_number_config do |options |
311
410
version = options [ :version ]
312
411
build_number = options [ :build_number ]
313
412
File . write ( VERSION_CONFIG_PATH , "#{ VERSION_CONFIG_DEFINITION } = #{ version } \n " )
314
- File . write ( APP_STORE_BUILD_NUMBER_CONFIG_PATH , "#{ BUILD_NUMBER_CONFIG_DEFINITION } = #{ build_number } \n " )
413
+ File . write ( BUILD_NUMBER_CONFIG_PATH , "#{ BUILD_NUMBER_CONFIG_DEFINITION } = #{ build_number } \n " )
315
414
git_commit (
316
415
path : [
317
416
VERSION_CONFIG_PATH ,
318
- APP_STORE_BUILD_NUMBER_CONFIG_PATH
417
+ BUILD_NUMBER_CONFIG_PATH
319
418
] ,
320
419
message : "Bump version to #{ version } (#{ build_number } )"
321
420
)
322
- sh ( 'git' , 'push' )
323
421
end
324
422
325
- # Reads App Store build number from the config file
423
+ # Reads build number from the config file
326
424
#
327
425
# @return [String] build number read from the file, or nil in case of failure
328
426
#
329
427
def macos_current_build_number
330
428
current_build_number = 0
331
429
332
- file_data = File . read ( APP_STORE_BUILD_NUMBER_CONFIG_PATH ) . split ( "\n " )
430
+ file_data = File . read ( BUILD_NUMBER_CONFIG_PATH ) . split ( "\n " )
333
431
file_data . each do |line |
334
432
current_build_number = line . split ( '=' ) [ 1 ] . strip . to_i if line . start_with? ( BUILD_NUMBER_CONFIG_DEFINITION )
335
433
end
0 commit comments