-
Notifications
You must be signed in to change notification settings - Fork 486
/
Fastfile
509 lines (442 loc) · 18.4 KB
/
Fastfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
# This file contains the fastlane.tools configuration
# You can find the documentation at https://docs.fastlane.tools
#
# For a list of all available actions, check out
#
# https://docs.fastlane.tools/actions
#
# For a list of all available plugins, check out
#
# https://docs.fastlane.tools/plugins/available-plugins
#
min_fastlane_version('2.156.0')
fastlane_require "dotenv"
fastlane_require "uri"
default_platform(:ios)
platform :ios do
#### Pre ####
before_all do
# Ensure used Xcode version
xcversion(version: "15.2")
end
#### Public ####
desc "Builds an adhoc ipa"
lane :adhoc do |options|
options[:adhoc] = true
if !options.has_key?(:build_number)
build_number = generate_build_number()
options = { build_number: build_number }.merge(options)
end
build_release(options)
end
desc "Builds an ipa for the App Store"
lane :app_store do |options|
UI.user_error!("'SENTRY_AUTH_TOKEN' environment variable should be set to use this lane, see Passbolt") unless !ENV["SENTRY_AUTH_TOKEN"].to_s.empty?
sentry_check_cli_installed
if !options.has_key?(:build_number)
build_number = generate_build_number()
options = { build_number: build_number }.merge(options)
end
build_release(options)
upload_dsyms_to_sentry
end
desc "Builds an Alpha ipa for pull request branches"
lane :alpha do
# Check we have all the tokens and tools necessary
UI.user_error!("'DIAWI_API_TOKEN' environment variable should be set to use this lane") unless !ENV["DIAWI_API_TOKEN"].to_s.empty?
# Generate the "Alpha" app variant
setup_app_variant(name: "Alpha")
# Builds an Ad Hoc IPA
adhoc
# Upload to Diawi
upload_to_diawi
end
desc "Upload IPA to Diawi"
lane :upload_to_diawi do
UI.user_error!("'DIAWI_API_TOKEN' environment variable should be set to use this lane") unless !ENV["DIAWI_API_TOKEN"].to_s.empty?
# Upload to Diawi
diawi(
token: ENV["DIAWI_API_TOKEN"],
wall_of_apps: false,
file: lane_context[SharedValues::IPA_OUTPUT_PATH]
)
# Get the Diawi link from Diawi action shared value
diawi_link = lane_context[SharedValues::UPLOADED_FILE_LINK_TO_DIAWI]
UI.command_output("Diawi link: " + diawi_link.to_s)
# Generate the Diawi QR code file link
diawi_app_id = URI(diawi_link).path.split('/').last
diawi_qr_code_link = "https://www.diawi.com/qrcode/link/#{diawi_app_id}"
UI.command_output("Diawi QR code link: " + diawi_qr_code_link.to_s)
# Set "DIAWI_FILE_LINK" to GitHub environment variables for Github actions
if is_ci
sh("echo DIAWI_FILE_LINK=#{diawi_link} >> $GITHUB_ENV")
sh("echo DIAWI_QR_CODE_LINK=#{diawi_qr_code_link} >> $GITHUB_ENV")
end
end
desc "Builds the ipa for the AppStore, then uploads it"
lane :deploy_release do |options|
# build the IPA
app_store(options)
# upload the IPA and metadata
deliver()
# We haven't yet implemented/tested deliver/upload_to_appstore properly so keep it manual for now
# UI.message("IPA is available at path '#{ENV['IPA_OUTPUT_PATH']}'. Please upload manually using Application Loader.")
# UI.confirm("Have you uploaded the IPA to the AppStore now?")
#
end
desc "Use an app variant. An app variant overwrite default project configuration or ressource files with custom values"
lane :setup_app_variant do |options|
appVariantScript = "../Variants/setup_app_variant.sh"
# Make sure app variant script can be executed
sh "chmod 775 #{appVariantScript}"
# Run app variant script with variant name
sh(appVariantScript, options[:name])
# Force reloading env variables
Dotenv.overload(".env.default")
end
desc "Build the app for simulator to ensure it compiles"
lane :build do |options|
xcodegen(spec: "project.yml")
cocoapods
app_name = "Riot"
build_app(
clean: true,
scheme: app_name,
derived_data_path: "./DerivedData/",
buildlog_path: "./DerivedData/Logs/",
# skip_package_ipa: true,
skip_archive: true,
destination: "generic/platform=iOS Simulator",
)
end
desc "Run tests"
lane :test do
xcodegen(spec: "project.yml")
cocoapods
run_tests(
workspace: "Riot.xcworkspace",
scheme: "RiotSwiftUI",
code_coverage: true,
# Test result configuration
result_bundle: true,
output_directory: "./build/test",
output_files: "riot.swiftui.unit.test.html,riot.swiftui.unit.test.report.junit.xml",
open_report: !is_ci?
)
run_tests(
workspace: "Riot.xcworkspace",
scheme: "Riot",
code_coverage: true,
# Test result configuration
result_bundle: true,
output_directory: "./build/test",
output_files: "riot.unit.test.html,riot.unit.test.report.junit.xml",
open_report: !is_ci?
)
slather(
cobertura_xml: true,
output_directory: "./build/test",
workspace: "Riot.xcworkspace",
proj: "Riot.xcodeproj",
scheme: "Riot",
binary_basename: "Element",
)
end
desc "Run UI tests"
lane :uitest do
xcodegen(spec: "project.yml")
cocoapods
run_tests(
workspace: "Riot.xcworkspace",
scheme: "RiotSwiftUITests",
device: "iPhone 15",
code_coverage: true,
# Test result configuration
result_bundle: true,
output_directory: "./build/test",
output_files: "riot.swiftui.ui.test.html,riot.swiftui.ui.test.report.junit.xml",
open_report: !is_ci?
)
slather(
cobertura_xml: true,
output_directory: "./build/test",
workspace: "Riot.xcworkspace",
proj: "Riot.xcodeproj",
scheme: "RiotSwiftUITests",
binary_basename: "RiotSwiftUI",
)
end
#### Private ####
desc "Download App Store or Ad-Hoc provisioning profiles"
private_lane :build_release do |options|
if is_ci
UI.user_error!("'APPSTORECONNECT_KEY_ID' environment variable should be set to use this lane") unless !ENV["APPSTORECONNECT_KEY_ID"].to_s.empty?
UI.user_error!("'APPSTORECONNECT_KEY_ISSUER_ID' environment variable should be set to use this lane") unless !ENV["APPSTORECONNECT_KEY_ISSUER_ID"].to_s.empty?
UI.user_error!("'APPSTORECONNECT_KEY_CONTENT' environment variable should be set to use this lane") unless !ENV["APPSTORECONNECT_KEY_CONTENT"].to_s.empty?
app_store_connect_api_key(
key_id: ENV["APPSTORECONNECT_KEY_ID"],
issuer_id: ENV["APPSTORECONNECT_KEY_ISSUER_ID"],
key_content: ENV["APPSTORECONNECT_KEY_CONTENT"]
)
else
UI.user_error!("'APPLE_ID' environment variable should be set to use this lane") unless !ENV["APPLE_ID"].to_s.empty?
end
build_number = options[:build_number]
UI.user_error!("'build_number' parameter is missing") unless !build_number.to_s.empty?
# ad-hoc or app-store?
adhoc = options.fetch(:adhoc, false)
# Extract git information to show within the app
git_branch_name = options[:git_tag]
if git_branch_name.to_s.empty?
# Retrieve the current git branch as a fallback
git_branch_name = mx_git_branch
end
UI.user_error!("Unable to retrieve GIT tag or branch") unless !git_branch_name.to_s.empty?
# Fetch team id from Appfile
team_id = CredentialsManager::AppfileConfig.try_fetch_value(:team_id)
UI.user_error!("Fail to fetch team id from Appfile") unless !team_id.to_s.empty?
# Generate versioning preprocessor macros
additional_preprocessor_definitions_hash = release_versioning_preprocessor_definitions(git_branch: git_branch_name, build_number: build_number)
additional_preprocessor_definitions = additional_preprocessor_definitions_hash.map { |k, v| "#{k}=\"#{v}\"" }.join(" ")
# Generate xcodebuild additional arguments
xcargs_hash = {
"GCC_PREPROCESSOR_DEFINITIONS" => "$(GCC_PREPROCESSOR_DEFINITIONS) #{additional_preprocessor_definitions}",
# Fix XCode 14 code signing issues for Swift packages containing resources bundles.
"CODE_SIGN_STYLE" => "Manual",
}
xcargs = xcargs_hash.map { |k, v| "#{k}=#{v.shellescape}" }.join(" ")
# Generate the project
xcodegen(spec: "project.yml")
# Clear derived data
clear_derived_data(derived_data_path: ENV["DERIVED_DATA_PATH"])
# Setup project provisioning profiles
download_provisioning_profiles(adhoc: adhoc)
disable_automatic_code_signing
update_project_provisioning_profiles
# Update build number
update_build_number(build_number: build_number)
# Perform a pod install
cocoapods(repo_update: true)
# Select a config
if adhoc
export_method = "ad-hoc"
main_provisioning_profile = ENV["ADHOC_MAIN_PROVISIONING_PROFILE_SPECIFIER"]
share_extension_provisioning_profile = ENV["ADHOC_SHARE_EXTENSION_PROVISIONING_PROFILE_SPECIFIER"]
siri_intents_provisioning_profile = ENV["ADHOC_SIRI_INTENTS_EXTENSION_PROVISIONING_PROFILE_SPECIFIER"]
nse_provisioning_profile = ENV["ADHOC_NSE_PROVISIONING_PROFILE_SPECIFIER"]
broadcast_upload_extension_provisioning_profile = ENV["ADHOC_BROADCAST_UPLOAD_EXTENSION_PROVISIONING_PROFILE_SPECIFIER"]
else
export_method = "app-store"
main_provisioning_profile = ENV["APPSTORE_MAIN_PROVISIONING_PROFILE_SPECIFIER"]
share_extension_provisioning_profile = ENV["APPSTORE_SHARE_EXTENSION_PROVISIONING_PROFILE_SPECIFIER"]
siri_intents_provisioning_profile = ENV["APPSTORE_SIRI_INTENTS_EXTENSION_PROVISIONING_PROFILE_SPECIFIER"]
nse_provisioning_profile = ENV["APPSTORE_NSE_PROVISIONING_PROFILE_SPECIFIER"]
broadcast_upload_extension_provisioning_profile = ENV["APPSTORE_BROADCAST_UPLOAD_EXTENSION_PROVISIONING_PROFILE_SPECIFIER"]
end
# Build app and create ipa
build_app(
clean: true,
scheme: ENV["SCHEME"],
xcargs: xcargs,
export_method: export_method,
derived_data_path: ENV["DERIVED_DATA_PATH"],
archive_path: ENV["ARCHIVE_PATH"],
output_directory: ENV["BUILD_OUTPUT_DIRECTORY"],
output_name: "#{ENV["IPA_NAME"]}.ipa",
buildlog_path: ENV["BUILD_LOG_DIRECTORY"],
codesigning_identity: ENV["APPSTORE_CODESIGNING_IDENTITY"],
skip_profile_detection: true,
export_options: {
method: export_method,
signingStyle: "manual",
teamID: team_id,
signingCertificate: ENV["APPSTORE_SIGNING_CERTIFICATE"],
provisioningProfiles: {
ENV["MAIN_BUNDLE_ID"] => main_provisioning_profile,
ENV["SHARE_EXTENSION_BUNDLE_ID"] => share_extension_provisioning_profile,
ENV["NSE_BUNDLE_ID"] => nse_provisioning_profile,
ENV["SIRI_INTENTS_EXTENSION_BUNDLE_ID"] => siri_intents_provisioning_profile,
ENV["BROADCAST_UPLOAD_EXTENSION_BUNDLE_ID"] => broadcast_upload_extension_provisioning_profile,
},
iCloudContainerEnvironment: "Production",
},
)
end
#### Private ####
desc "Download App Store or Ad-Hoc provisioning profiles"
private_lane :download_provisioning_profiles do |options|
adhoc = options.fetch(:adhoc, false)
output_path = ENV["PROVISIONING_PROFILES_PATH"]
skip_certificate_verification = false
main_provisioning_name = adhoc ? ENV["ADHOC_MAIN_PROVISIONING_PROFILE_SPECIFIER"] : ENV["APPSTORE_MAIN_PROVISIONING_PROFILE_SPECIFIER"]
share_extension_provisioning_name = adhoc ? ENV["ADHOC_SHARE_EXTENSION_PROVISIONING_PROFILE_SPECIFIER"] : ENV["APPSTORE_SHARE_EXTENSION_PROVISIONING_PROFILE_SPECIFIER"]
siri_intents_provisioning_name = adhoc ? ENV["ADHOC_SIRI_INTENTS_EXTENSION_PROVISIONING_PROFILE_SPECIFIER"] : ENV["APPSTORE_SIRI_INTENTS_EXTENSION_PROVISIONING_PROFILE_SPECIFIER"]
notification_service_extension_provisioning_name = adhoc ? ENV["ADHOC_NSE_PROVISIONING_PROFILE_SPECIFIER"] : ENV["APPSTORE_NSE_PROVISIONING_PROFILE_SPECIFIER"]
broadcast_upload_extension_provisioning_name = adhoc ? ENV["ADHOC_BROADCAST_UPLOAD_EXTENSION_PROVISIONING_PROFILE_SPECIFIER"] : ENV["APPSTORE_BROADCAST_UPLOAD_EXTENSION_PROVISIONING_PROFILE_SPECIFIER"]
# Main application
get_provisioning_profile(
app_identifier: ENV["MAIN_BUNDLE_ID"],
provisioning_name: main_provisioning_name,
ignore_profiles_with_different_name: true,
adhoc: adhoc,
skip_certificate_verification: skip_certificate_verification,
output_path: output_path,
filename: ENV["MAIN_PROVISIONING_PROFILE_FILENAME"],
readonly: true,
)
# Share extension
get_provisioning_profile(
app_identifier: ENV["SHARE_EXTENSION_BUNDLE_ID"],
provisioning_name: share_extension_provisioning_name,
ignore_profiles_with_different_name: true,
adhoc: adhoc,
skip_certificate_verification: skip_certificate_verification,
output_path: output_path,
filename: ENV["SHARE_EXTENSION_PROVISIONING_PROFILE_FILENAME"],
readonly: true,
)
# Siri Intents extension
get_provisioning_profile(
app_identifier: ENV["SIRI_INTENTS_EXTENSION_BUNDLE_ID"],
provisioning_name: siri_intents_provisioning_name,
ignore_profiles_with_different_name: true,
adhoc: adhoc,
skip_certificate_verification: skip_certificate_verification,
output_path: output_path,
filename: ENV["SIRI_INTENTS_EXTENSION_PROVISIONING_PROFILE_FILENAME"],
readonly: true,
)
# NSE
get_provisioning_profile(
app_identifier: ENV["NSE_BUNDLE_ID"],
provisioning_name: notification_service_extension_provisioning_name,
ignore_profiles_with_different_name: true,
adhoc: adhoc,
skip_certificate_verification: skip_certificate_verification,
output_path: output_path,
filename: ENV["NSE_PROVISIONING_PROFILE_FILENAME"],
readonly: true,
)
# Broadcast Upload Extension
get_provisioning_profile(
app_identifier: ENV["BROADCAST_UPLOAD_EXTENSION_BUNDLE_ID"],
provisioning_name: broadcast_upload_extension_provisioning_name,
ignore_profiles_with_different_name: true,
adhoc: adhoc,
skip_certificate_verification: skip_certificate_verification,
output_path: output_path,
filename: ENV["BROADCAST_UPLOAD_EXTENSION_PROVISIONING_PROFILE_FILENAME"],
readonly: true,
)
end
desc "Update provisioning profiles for each target"
private_lane :update_project_provisioning_profiles do
provisioning_profiles_path = ENV["PROVISIONING_PROFILES_PATH"]
build_configuration = "Release"
xcodeproj = ENV["PROJECT_PATH"]
# Main application
update_project_provisioning(
xcodeproj: xcodeproj,
profile: "#{provisioning_profiles_path}#{ENV["MAIN_PROVISIONING_PROFILE_FILENAME"]}",
target_filter: ENV["MAIN_TARGET"],
build_configuration: build_configuration,
)
# Share extension
update_project_provisioning(
xcodeproj: xcodeproj,
profile: "#{provisioning_profiles_path}#{ENV["SHARE_EXTENSION_PROVISIONING_PROFILE_FILENAME"]}",
target_filter: ENV["SHARE_EXTENSION_TARGET"],
build_configuration: build_configuration,
)
# Siri Intents extension
update_project_provisioning(
xcodeproj: xcodeproj,
profile: "#{provisioning_profiles_path}#{ENV["SIRI_INTENTS_EXTENSION_PROVISIONING_PROFILE_FILENAME"]}",
target_filter: ENV["SIRI_INTENTS_EXTENSION_TARGET"],
build_configuration: build_configuration,
)
# NSE
update_project_provisioning(
xcodeproj: xcodeproj,
profile: "#{provisioning_profiles_path}#{ENV["NSE_PROVISIONING_PROFILE_FILENAME"]}",
target_filter: ENV["NSE_TARGET"],
build_configuration: build_configuration,
)
# Broadcast Upload Extension
update_project_provisioning(
xcodeproj: xcodeproj,
profile: "#{provisioning_profiles_path}#{ENV["BROADCAST_UPLOAD_EXTENSION_PROVISIONING_PROFILE_FILENAME"]}",
target_filter: ENV["BROADCAST_UPLOAD_EXTENSION_TARGET"],
build_configuration: build_configuration,
)
end
desc "Update application build number for all targets"
private_lane :update_build_number do |options|
build_number = options[:build_number]
update_file_content(
"../Config/AppVersion.xcconfig",
/(CURRENT_PROJECT_VERSION\s*=)\s*.*/ => "\\1 #{build_number}"
)
end
desc "Returns version identifiers hash to inject in GCC_PREPROCESSOR_DEFINITIONS for release builds"
private_lane :release_versioning_preprocessor_definitions do |options|
preprocessor_definitions = Hash.new
git_branch_name = options[:git_branch]
build_number = options[:build_number]
if !git_branch_name.to_s.empty?
preprocessor_definitions["GIT_BRANCH"] = git_branch_name.sub("origin/", "").sub("heads/", "")
end
if !build_number.to_s.empty?
preprocessor_definitions["BUILD_NUMBER"] = build_number
end
preprocessor_definitions
end
desc "Upload dsym files to Sentry to symbolicate crashes"
private_lane :upload_dsyms_to_sentry do
UI.user_error!("'SENTRY_AUTH_TOKEN' environment variable should be set to use this lane") unless !ENV["SENTRY_AUTH_TOKEN"].to_s.empty?
dsym_path = "#{ENV["BUILD_OUTPUT_DIRECTORY"]}/#{ENV["IPA_NAME"]}.app.dSYM.zip"
sentry_upload_dif(
auth_token: ENV["SENTRY_AUTH_TOKEN"],
org_slug: 'element',
project_slug: 'element-ios',
url: 'https://sentry.tools.element.io/',
path: dsym_path,
)
end
# git_branch can return an empty screen with some CI tools (like GH actions)
# The CI build script needs to define MX_GIT_BRANCH with the right branch.
def mx_git_branch
mx_git_branch = git_branch
if mx_git_branch == ""
ensure_env_vars(
env_vars: ['MX_GIT_BRANCH']
)
mx_git_branch = ENV["MX_GIT_BRANCH"]
end
return mx_git_branch
end
# Find the latest branch with the given name pattern in the given repo
def find_branch(repo_slug, pattern)
list = `git ls-remote --heads --sort=version:refname https://github.com/#{repo_slug} #{pattern}`
list.split("\n")
.map { |line| line.sub(%r{[0-9a-f]+\trefs/heads/}, '').chomp }
.last # Latest ref found, in "version:refname" semantic order
end
end
# Update an arbitrary file by applying some RegExp replacements to its content
#
# @param [String] file The path to the file that needs replacing
# @param [Hash<RegExp, String>] replacements A list of replacements to apply
#
def update_file_content(file, replacements)
content = File.read(file)
replacements.each do |pattern, replacement|
content.gsub!(pattern, replacement)
end
File.write(file, content)
end
# Generates a new build number based on timestamp
def generate_build_number()
require 'date'
return DateTime.now.strftime("%Y%m%d%H%M%S")
end