-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFastfile_Template.rb
More file actions
443 lines (411 loc) · 14.8 KB
/
Copy pathFastfile_Template.rb
File metadata and controls
443 lines (411 loc) · 14.8 KB
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
# 기본 플랫폼 설정
# 차후 Android 적용 검토시 확인 필요
default_platform(:ios)
# 상수 설정
# 프로젝트에 맞게 값 수정
module Constant
# 프로젝트 이름
PROJECT_NAME = "PROJECT_NAME"
# Slack notification을 보낼 웹 후크 URL
SLACK_URL = "SLACK_URL"
# Slack notification icon URL
SLACK_ICON_URL = "SLACK_ICON_URL"
# Fastlane에서 애플 인증시 사용할 애플 개발자 계정에 대한 앱 암호
FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD = "FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD"
# match passphrase
MATCH_PASSWORD = "MATCH_PASSWORD"
# 프로젝트 워크스페이스 파일 이름
WORKSPACE = "WORKSPACE"
# Firebase 설치시 발급되는 CLI 토큰
FIREBASE_CLI_TOKEN = "FIREBASE_CLI_TOKEN"
# Firebase App Distribution에서 배포할 그룹 이름
FIREBASE_GROUP_NAME = "FIREBASE_GROUP_NAME"
# 프로젝트 테스트 코드를 실행할 시뮬레이터
TESTING_DEVICES = ["TESTING_DEVICE", ...]
# 앱스토어 커넥트 API 키
APP_STORE_CONNECT_KEY_ID = "APP_STORE_CONNECT_KEY_ID "
# Issuer ID
APP_STORE_CONNECT_ISSUER_ID = "APP_STORE_CONNECT_ISSUER_ID"
# API key Content
APP_STORE_CONNECT_KEY_CONTENT = "APP_STORE_CONNECT_KEY_CONTENT"
# Debug scheme constants
# scheme 이름
DEBUG_SCHEME = "DEBUG_SCHEME"
# app bundle identifier
DEBUG_BUNDLE_IDENTIFIER = "DEBUG_BUNDLE_IDENTIFIER"
# app display name
DEBUG_APP_DISPLAY_NAME = "DEBUG_APP_DISPLAY_NAME"
# Firebase 앱 등록시 발급되는 app id
DEBUG_FIREBASE_APP_ID = "DEBUG_FIREBASE_APP_ID"
# Release scheme constants
# scheme 이름
RELEASE_SCHEME = "RELEASE_SCHEME"
# app bundle identifier
RELEASE_BUNDLE_IDENTIFIER = "RELEASE_BUNDLE_IDENTIFIER"
# app display name
RELEASE_APP_DISPLAY_NAME = "RELEASE_APP_DISPLAY_NAME"
# Firebase 앱 등록시 발급되는 app id
RELEASE_FIREBASE_APP_ID = "RELEASE_FIREBASE_APP_ID"
end
# iOS 플랫폼 lanes
platform :ios do
# 특정 lane 실행 전 실행되는 블록
before_all do
app_store_connect_api_key(
key_id: Constant::APP_STORE_CONNECT_KEY_ID,
issuer_id: Constant::APP_STORE_CONNECT_ISSUER_ID,
key_content: Constant::APP_STORE_CONNECT_KEY_CONTENT
)
ENV["SLACK_URL"] = Constant::SLACK_URL
ENV["FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD"] = Constant::FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD
ENV["MATCH_PASSWORD"] = Constant::MATCH_PASSWORD
end
# 특정 lane 실행 후 실행되는 블록
after_all do |lane|
end
# 특정 lane에서 에러 발생시 실행되는 블록
error do |lane, exception|
case lane.to_s
when "update_pods"
slack(
username: Constant::PROJECT_NAME,
icon_url: Constant::SLACK_ICON_URL,
pretext: "<!here|here>\n*#{Constant::PROJECT_NAME} Pod 업데이트 실패*",
success: false,
payload: {
"App version" => "#{get_version_number}",
"Build number" => "#{get_build_number}"
},
default_payloads: []
)
when "deploy_debug_to_firebase"
slack(
username: Constant::PROJECT_NAME,
icon_url: Constant::SLACK_ICON_URL,
pretext: "<!here|here>\n*#{Constant::PROJECT_NAME} 개발 빌드 Firebase 배포 실패*",
success: false,
payload: {
"App version" => "#{get_version_number}",
"Build number" => "#{get_build_number}"
},
default_payloads: ["git_branch", "last_git_commit", "last_git_commit_hash"]
)
when "deploy_release_to_firebase"
slack(
username: Constant::PROJECT_NAME,
icon_url: Constant::SLACK_ICON_URL,
pretext: "<!here|here>\n*#{Constant::PROJECT_NAME} 배포 빌드 Firebase 배포 실패*",
success: false,
payload: {
"App version" => "#{get_version_number}",
"Build number" => "#{get_build_number}"
},
default_payloads: ["git_branch", "last_git_commit", "last_git_commit_hash"]
)
when "deploy_release_to_testflight"
slack(
username: Constant::PROJECT_NAME,
icon_url: Constant::SLACK_ICON_URL,
pretext: "<!here|here>\n*#{Constant::PROJECT_NAME} 배포 빌드 Testflight 배포 실패*",
success: false,
payload: {
"App version" => "#{get_version_number}",
"Build number" => "#{get_build_number}"
},
default_payloads: ["git_branch", "last_git_commit", "last_git_commit_hash"]
)
end
end
# Provisioning Profile 생성
desc "Create provisioning profiles"
lane :create_provisioning_profiles do
sync_code_signing(app_identifier: Constant::RELEASE_BUNDLE_IDENTIFIER,
type: "development",
readonly: false,
force_for_new_devices: true)
sync_code_signing(app_identifier: Constant::RELEASE_BUNDLE_IDENTIFIER,
type: "appstore",
readonly: false,
force_for_new_devices: true)
sync_code_signing(app_identifier: Constant::RELEASE_BUNDLE_IDENTIFIER,
type: "adhoc",
readonly: false,
force_for_new_devices: true)
sync_code_signing(app_identifier: Constant::DEBUG_BUNDLE_IDENTIFIER,
type: "development",
readonly: false,
force_for_new_devices: true)
sync_code_signing(app_identifier: Constant::DEBUG_BUNDLE_IDENTIFIER,
type: "appstore",
readonly: false,
force_for_new_devices: true)
sync_code_signing(app_identifier: Constant::DEBUG_BUNDLE_IDENTIFIER,
type: "adhoc",
readonly: false,
force_for_new_devices: true)
end
# Provisioning Profile 동기화
desc "Fetch provisioning profiles"
lane :fetch_provisioning_profiles do
sync_code_signing(app_identifier: Constant::RELEASE_BUNDLE_IDENTIFIER,
type: "development",
readonly: true)
sync_code_signing(app_identifier: Constant::RELEASE_BUNDLE_IDENTIFIER,
type: "appstore",
readonly: true)
sync_code_signing(app_identifier: Constant::RELEASE_BUNDLE_IDENTIFIER,
type: "adhoc",
readonly: true)
sync_code_signing(app_identifier: Constant::DEBUG_BUNDLE_IDENTIFIER,
type: "development",
readonly: true)
sync_code_signing(app_identifier: Constant::DEBUG_BUNDLE_IDENTIFIER,
type: "appstore",
readonly: true)
sync_code_signing(app_identifier: Constant::DEBUG_BUNDLE_IDENTIFIER,
type: "adhoc",
readonly: true)
end
# Pods 업데이트
desc "Update pods"
lane :update_pods do
increase_build_number_from_firebase
cocoapods(
use_bundle_exec: false
)
slack(
username: Constant::PROJECT_NAME,
icon_url: Constant::SLACK_ICON_URL,
pretext: "*#{Constant::PROJECT_NAME} Pod 업데이트 완료*",
success: true,
payload: {
"App version" => "#{get_version_number}",
"Build number" => "#{get_build_number}"
},
default_payloads: []
)
end
# 테스트 코드 실행
desc "Run tests"
lane :run_test_codes do
increase_build_number_from_firebase
run_tests(
workspace: Constant::WORKSPACE,
scheme: Constant::DEBUG_SCHEME,
devices: Constant::TESTING_DEVICES,
reinstall_app: true,
app_identifier: Constant::DEBUG_BUNDLE_IDENTIFIER,
clean: true,
app_name: "*#{Constant::PROJECT_NAME}*",
configuration: "Debug",
slack_username: Constant::PROJECT_NAME,
slack_icon_url: Constant::SLACK_ICON_URL,
slack_message: ">*App version*\n>#{get_version_number}\n>*Build number*\n>#{get_build_number}",
slack_default_payloads: ["test_result", "git_branch", "last_git_commit", "last_git_commit_hash"]
)
end
# Debug scheme Firebase App Distribution에 배포
desc "Deploy debug scheme to Firebase App Distribution"
lane :deploy_debug_to_firebase do
increase_build_number_from_firebase
sync_code_signing(
type: "adhoc",
force_for_new_devices: true
)
build_app(
scheme: Constant::DEBUG_SCHEME,
workspace: Constant::WORKSPACE,
export_method: "ad-hoc",
clean: true,
include_bitcode: false,
configuration: "Debug"
)
firebase_app_distribution(
app: Constant::DEBUG_FIREBASE_APP_ID,
firebase_cli_token: Constant::FIREBASE_CLI_TOKEN,
groups: Constant::FIREBASE_GROUP_NAME,
debug: true
)
build_number = get_debug_build_number_from_firebase
slack(
username: Constant::PROJECT_NAME,
icon_url: Constant::SLACK_ICON_URL,
pretext: "*#{Constant::PROJECT_NAME} 개발 빌드 Firebase 배포 완료*",
success: true,
payload: {
"App version" => "#{get_version_number}",
"Build number" => "#{build_number}"
},
default_payloads: ["git_branch", "last_git_commit", "last_git_commit_hash"]
)
end
# Release scheme Firebase App Distribution에 배포
desc "Deploy release scheme to Firebase App Distribution"
lane :deploy_release_to_firebase do
increase_build_number_from_firebase
sync_code_signing(
type: "adhoc",
force_for_new_devices: true
)
build_app(
scheme: Constant::RELEASE_SCHEME,
workspace: Constant::WORKSPACE,
export_method: "ad-hoc",
clean: true,
include_bitcode: false,
configuration: "Release"
)
firebase_app_distribution(
app: Constant::RELEASE_FIREBASE_APP_ID,
firebase_cli_token: Constant::FIREBASE_CLI_TOKEN,
groups: Constant::FIREBASE_GROUP_NAME,
debug: true
)
build_number = get_release_build_number_from_firebase
slack(
username: Constant::PROJECT_NAME,
icon_url: Constant::SLACK_ICON_URL,
pretext: "*#{Constant::PROJECT_NAME} 배포 빌드 Firebase 배포 완료*",
success: true,
payload: {
"App version" => "#{get_version_number}",
"Build number" => "#{build_number}"
},
default_payloads: ["git_branch", "last_git_commit", "last_git_commit_hash"]
)
end
# Debug, Release scheme Firebase App Distribution에 배포
desc "Deploy debug, release scheme to Firebase App Distribution"
lane :deploy_to_firebase do
deploy_debug_to_firebase
deploy_release_to_firebase
end
# Release scheme Testflight에 배포
desc "Deploy release scheme to Testflight"
lane :deploy_release_to_testflight do
set_build_number_from_firebase
sync_code_signing(
type: "appstore",
force_for_new_devices: true
)
build_app(
scheme: Constant::RELEASE_SCHEME,
workspace: Constant::WORKSPACE,
export_method: "app-store",
clean: true,
include_bitcode: false,
configuration: "Release"
)
upload_to_testflight(
notify_external_testers: false
)
build_number = get_build_number_from_testflight
slack(
username: Constant::PROJECT_NAME,
icon_url: Constant::SLACK_ICON_URL,
pretext: "*#{Constant::PROJECT_NAME} 배포 빌드 Testflight 배포 완료*",
success: true,
payload: {
"App version" => "#{get_version_number}",
"Build number" => "#{build_number}"
},
default_payloads: ["git_branch", "last_git_commit", "last_git_commit_hash"]
)
end
end
# Methods
def get_debug_build_number_from_firebase
firebase_version_number = firebase_app_distribution_get_latest_release(
app: Constant::DEBUG_FIREBASE_APP_ID,
firebase_cli_token: Constant::FIREBASE_CLI_TOKEN
).nil? ? "0.0.0" : firebase_app_distribution_get_latest_release(
app: Constant::DEBUG_FIREBASE_APP_ID,
firebase_cli_token: Constant::FIREBASE_CLI_TOKEN
)[:displayVersion]
if get_version_number != firebase_version_number
return 0
end
build_number = firebase_app_distribution_get_latest_release(
app: Constant::DEBUG_FIREBASE_APP_ID,
firebase_cli_token: Constant::FIREBASE_CLI_TOKEN
).nil? ? "0" : firebase_app_distribution_get_latest_release(
app: Constant::DEBUG_FIREBASE_APP_ID,
firebase_cli_token: Constant::FIREBASE_CLI_TOKEN
)[:buildVersion]
return build_number.to_i
end
def get_release_build_number_from_firebase
firebase_version_number = firebase_app_distribution_get_latest_release(
app: Constant::RELEASE_FIREBASE_APP_ID,
firebase_cli_token: Constant::FIREBASE_CLI_TOKEN
).nil? ? "0.0.0" : firebase_app_distribution_get_latest_release(
app: Constant::RELEASE_FIREBASE_APP_ID,
firebase_cli_token: Constant::FIREBASE_CLI_TOKEN
)[:displayVersion]
if get_version_number != firebase_version_number
return 0
end
build_number = firebase_app_distribution_get_latest_release(
app: Constant::RELEASE_FIREBASE_APP_ID,
firebase_cli_token: Constant::FIREBASE_CLI_TOKEN
).nil? ? "0" : firebase_app_distribution_get_latest_release(
app: Constant::RELEASE_FIREBASE_APP_ID,
firebase_cli_token: Constant::FIREBASE_CLI_TOKEN
)[:buildVersion]
return build_number.to_i
end
def get_build_number_from_testflight
build_number = latest_testflight_build_number(
app_identifier: Constant::RELEASE_BUNDLE_IDENTIFIER,
version: get_version_number,
platform: "ios"
)
return build_number.to_i
end
def get_build_number_from_firebase
debug_build_number = get_debug_build_number_from_firebase
release_build_number = get_release_build_number_from_firebase
if debug_build_number == release_build_number
return debug_build_number
else
raise StandardError.new "Check Firebase App Distribution debug and release build number"
end
end
def set_build_number_from_firebase
firebase_debug_scheme_build_number = get_debug_build_number_from_firebase
firebase_release_scheme_build_number = get_release_build_number_from_firebase
build_number_array = [
firebase_debug_scheme_build_number,
firebase_release_scheme_build_number
]
new_build_number = build_number_array.max
increment_build_number(
build_number: new_build_number
)
return new_build_number
end
def set_build_number_from_testflight
testflight_build_number = get_build_number_from_testflight
new_build_number = build_number
increment_build_number(
build_number: new_build_number
)
return new_build_number
end
def increase_build_number_from_firebase
firebase_debug_scheme_build_number = get_debug_build_number_from_firebase
firebase_release_scheme_build_number = get_release_build_number_from_firebase
build_number_array = [
firebase_debug_scheme_build_number,
firebase_release_scheme_build_number
]
if build_number_array.min == build_number_array.max
new_build_number = build_number_array.max + 1
else
new_build_number = build_number_array.max
end
increment_build_number(
build_number: new_build_number
)
return new_build_number
end