-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFastfile
421 lines (366 loc) · 10.9 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
fastlane_version "2.185.0"
default_platform(:ios)
platform :ios do
env_variables = {
core: {
fastlane_user: "FASTLANE_USER",
team_id: "TEAM_ID",
slack_webhook_url: "SLACK_WEBHOOK_URL",
upload_symbols_path: "UPLOAD_SYMBOLS_PATH",
project: "PROJECT",
#Store
app_id: "APP_ID",
scheme: "SCHEME",
ipa_name: "IPA_NAME",
info_plist: "GOOGLE_SERVICE_INFO_PLIST_PATH",
app_store_build_config: "APP_STORE_BUILD_CONFIGURATION",
itc_name: "FASTLANE_ITC_TEAM_NAME",
#Prod
prod_app_id: "PROD_APP_ID",
prod_scheme: "PROD_SCHEME",
prod_ipa_name: "PROD_IPA_NAME",
prod_info_plist: "PROD_GOOGLE_SERVICE_INFO_PLIST_PATH",
adhoc_build_config: "ADHOC_BUILD_CONFIGURATION",
#Preprod
preprod_app_id: "PREPROD_APP_ID",
preprod_scheme: "PREPROD_SCHEME",
preprod_ipa_name: "PREPROD_IPA_NAME",
preprod_info_plist: "PREPROD_GOOGLE_SERVICE_INFO_PLIST_PATH",
#Staging
staging_app_id: "STAGING_APP_ID",
staging_scheme: "STAGING_SCHEME",
staging_ipa_name: "STAGING_IPA_NAME",
staging_info_plist: "STAGING_GOOGLE_SERVICE_INFO_PLIST_PATH",
device: "DEVICE"
},
s3: {
bucket: "S3_BUCKET",
access_key: "S3_ACCESS_KEY",
secret_access_key: "S3_SECRET_ACCESS_KEY",
region: "S3_REGION"
},
match: {
key_id: "KEY_ID",
issuer_id: "ISSUER_ID",
key_content: "KEY_CONTENT",
in_house: "IN_HOUSE",
match_password: "MATCH_PASSWORD",
}
}
required_env_variables = {
shared: [
env_variables[:core][:fastlane_user],
env_variables[:core][:team_id],
env_variables[:core][:project],
env_variables[:core][:slack_webhook_url],
env_variables[:s3][:bucket],
env_variables[:s3][:access_key],
env_variables[:s3][:secret_access_key],
env_variables[:s3][:region],
env_variables[:match][:key_id],
env_variables[:match][:issuer_id],
env_variables[:match][:key_content],
env_variables[:match][:in_house],
env_variables[:match][:match_password]
],
store: [
env_variables[:core][:app_id],
env_variables[:core][:scheme],
env_variables[:core][:ipa_name],
env_variables[:core][:info_plist],
env_variables[:core][:app_store_build_config],
env_variables[:core][:itc_name]
],
prod: [
env_variables[:core][:prod_app_id],
env_variables[:core][:prod_scheme],
env_variables[:core][:prod_ipa_name],
env_variables[:core][:prod_info_plist],
env_variables[:core][:adhoc_build_config]
],
preprod: [
env_variables[:core][:preprod_app_id],
env_variables[:core][:preprod_scheme],
env_variables[:core][:preprod_ipa_name],
env_variables[:core][:preprod_info_plist],
env_variables[:core][:adhoc_build_config]
],
staging: [
env_variables[:core][:staging_app_id],
env_variables[:core][:staging_scheme],
env_variables[:core][:staging_ipa_name],
env_variables[:core][:staging_info_plist],
env_variables[:core][:adhoc_build_config]
]
}
before_all do |lane, options|
process_variables
ensure_env_vars(
env_vars: required_env_variables[:shared]
)
if ENV[env_variables[:core][:app_id]] != nil
ensure_env_vars(
env_vars: required_env_variables[:store]
)
end
if ENV[env_variables[:core][:prod_app_id]] != nil
ensure_env_vars(
env_vars: required_env_variables[:prod]
)
end
if ENV[env_variables[:core][:preprod_app_id]] != nil
ensure_env_vars(
env_vars: required_env_variables[:preprod]
)
end
if ENV[env_variables[:core][:staging_app_id]] != nil
ensure_env_vars(
env_vars: required_env_variables[:staging]
)
end
end
lane :process_variables do
end
# PUBLIC LANES
lane :build_store_app do |options|
build(
app_identifier: ENV[env_variables[:core][:app_id]],
scheme: ENV[env_variables[:core][:scheme]],
is_store: true
)
end
lane :build_staging_app do |options|
build(
app_identifier: ENV[env_variables[:core][:staging_app_id]],
scheme: ENV[env_variables[:core][:staging_scheme]],
is_store: false
)
end
lane :build_preprod_app do |options|
build(
app_identifier: ENV[env_variables[:core][:preprod_app_id]],
scheme: ENV[env_variables[:core][:preprod_scheme]],
is_store: false
)
end
lane :build_prod_app do |options|
build(
app_identifier: ENV[env_variables[:core][:prod_app_id]],
scheme: ENV[env_variables[:core][:prod_scheme]],
is_store: false
)
end
lane :deploy_all_apps_to_testflight do |options|
deploy_staging_app_to_testflight
deploy_preprod_app_to_testflight
deploy_store_app_to_testflight
end
lane :deploy_staging_app_to_testflight do |options|
deploy_to_testflight(
target: "Staging",
app_identifier: ENV[env_variables[:core][:staging_app_id]],
scheme: ENV[env_variables[:core][:staging_scheme]],
ipa_name: ENV[env_variables[:core][:staging_ipa_name]],
export_method: "ad-hoc",
google_service_info_plist_path: ENV[env_variables[:core][:staging_info_plist]]
)
end
lane :deploy_preprod_app_to_testflight do |options|
deploy_to_testflight(
target: "Preprod",
app_identifier: ENV[env_variables[:core][:preprod_app_id]],
scheme: ENV[env_variables[:core][:preprod_scheme]],
ipa_name: ENV[env_variables[:core][:preprod_ipa_name]],
export_method: "ad-hoc",
google_service_info_plist_path: ENV[env_variables[:core][:preprod_info_plist]]
)
end
lane :deploy_prod_app_to_testflight do |options|
deploy_to_testflight(
target: "Prod",
app_identifier: ENV[env_variables[:core][:prod_app_id]],
scheme: ENV[env_variables[:core][:prod_scheme]],
ipa_name: ENV[env_variables[:core][:prod_ipa_name]],
export_method: "ad-hoc",
google_service_info_plist_path: ENV[env_variables[:core][:prod_info_plist]]
)
end
lane :deploy_store_app_to_testflight do |options|
deploy_to_testflight(
target: "Store",
app_identifier: ENV[env_variables[:core][:app_id]],
scheme: ENV[env_variables[:core][:scheme]],
ipa_name: ENV[env_variables[:core][:ipa_name]],
export_method: "app-store",
google_service_info_plist_path: ENV[env_variables[:core][:info_plist]]
)
end
lane :sync_all_dev_certs do |options|
sync_staging_dev_cert
sync_preprod_dev_cert
sync_prod_dev_cert
end
lane :sync_staging_dev_cert do |options|
sync_dev_cert(
target: "Staging",
app_identifier: ENV[env_variables[:core][:staging_app_id]]
)
end
lane :sync_preprod_dev_cert do |options|
sync_dev_cert(
target: "Preprod",
app_identifier: ENV[env_variables[:core][:preprod_app_id]]
)
end
lane :sync_prod_dev_cert do |options|
sync_dev_cert(
target: "Prod",
app_identifier: ENV[env_variables[:core][:app_id]]
)
end
error do |lane, exception, options|
notify_slack_for_error(
message: "🚑 Houston, we have a problem!",
attachment_properties: {
fields: [
{
title: "Git Tag",
value: last_git_tag,
short: true
},
{
title: "Error",
value: exception.to_s,
short: false
}
]
}
)
end
lane :deploy_to_testflight do |options|
target = options[:target]
app_identifier = options[:app_identifier]
if app_identifier == nil
UI.important "No app is found to deploy to Testflight [#{target}]"
next
end
#1
clean_build_artifacts
#2
register_connect_api_key
#3
sign(
type: "appstore",
app_identifier: app_identifier
)
#4
archive(
configuration: ENV[env_variables[:core][:app_store_build_config]],
scheme: options[:scheme],
output_name: options[:ipa_name],
export_method: "app-store",
is_store: true
)
#5
upload_to_testflight(
skip_submission: true,
skip_waiting_for_build_processing: true
)
#6
upload_symbols_to_crashlytics(
gsp_path: options[:google_service_info_plist_path],
binary_path: ENV[env_variables[:core][:upload_symbols_path]]
)
#7
notify_slack_for_success(
message: "🚀 Released #{last_git_tag} to TestFlight!"
)
end
lane :sync_dev_cert do |options|
target = options[:target]
app_identifier = options[:app_identifier]
if app_identifier == nil
UI.important "No app is found to sync development certificates [#{target}]"
next
end
register_connect_api_key
sign(
type: "development",
app_identifier: app_identifier
)
end
# Sign Cerificates For Given Profile Type
lane :sign do |options|
match(
type: options[:type],
profile_name: "Profile #{options[:type]} #{options[:app_identifier]}",
app_identifier: options[:app_identifier],
force_for_new_devices: true,
verbose: true
)
end
#Register api key for app store connect
lane :register_connect_api_key do |options|
app_store_connect_api_key(
key_id: ENV[env_variables[:match][:key_id]],
issuer_id: ENV[env_variables[:match][:issuer_id]],
key_content: ENV[env_variables[:match][:key_content]],
in_house: ENV[env_variables[:match][:in_house]]
)
end
lane :build do |options|
device = ENV[env_variables[:core][:device]] || nil
#1
scan(
project: ENV[env_variables[:core][:project]],
app_identifier: options[:app_identifier],
scheme: options[:scheme],
clean: true,
build_for_testing: true,
device: device
)
end
lane :archive do |options|
#1
gym(
project: ENV[env_variables[:core][:project]],
configuration: options[:configuration],
scheme: options[:scheme],
clean: true,
output_directory: "./archive",
output_name: options[:output_name],
export_method: options[:export_method],
verbose: true
)
end
lane :notify_slack_for_success do |options|
notify_slack(
default_payloads: [],
is_success: true,
message: options[:message],
attachment_properties: options[:attachment_properties]
)
end
lane :notify_slack_for_error do |options|
notify_slack(
default_payloads: [],
is_success: false,
message: options[:message],
attachment_properties: options[:attachment_properties]
)
end
lane :notify_slack do |options|
slack_webhook_url = ENV[env_variables[:core][:slack_webhook_url]]
if slack_webhook_url == nil
UI.important "No 'Slack' webhook url is provided!"
next
end
slack(
slack_url: slack_webhook_url,
default_payloads: options[:default_payloads],
success: options[:is_success],
message: options[:message],
attachment_properties: options[:attachment_properties]
)
end
end