-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFastfile
More file actions
427 lines (350 loc) · 12.4 KB
/
Fastfile
File metadata and controls
427 lines (350 loc) · 12.4 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
#!/usr/bin/ruby
fastlane_require 'spaceship'
fastlane_require 'json'
fastlane_require 'fastlane-plugin-update_provisioning_profile_specifier'
fastlane_require 'fastlane-plugin-versioning'
fastlane_require 'fastlane-plugin-badge'
fastlane_require 'fastlane-plugin-slack_train'
fastlane_version "2.99.1"
default_platform :ios
#####################################################
# Public lanes
#####################################################
desc "Download dSYM files from iTC and upload them to Crashlytics"
desc "you can specify `version`, latest will be used if not provided"
lane :refresh_dsyms do |options|
download_dsyms(version: options[:version] || "latest")
upload_symbols_to_crashlytics
clean_build_artifacts
end
desc "Creates all required certificates & provisioning profiles and stores them in a separate git repository"
desc "and automatically install the existing profiles from the Git repo in ~/Library/MobileDevice/Provisioning Profiles"
lane :generate_certificate do
profile_types = ["appstore", "development", "adhoc"]
profile_types.each { |profile_type|
match(type: profile_type)
}
end
#####################################################
# Private lanes
#####################################################
desc "Run unit tests"
private_lane :execute_test do
ensure_git_status_clean
clear_derived_data
update_pods
scan
slather
end
desc "Submit a new Crashlytics (Stage server) build from provided/develop branch with badge"
private_lane :execute_stage do |options|
branch = options[:branch]
checkout_if_needed(options[:builder], branch)
build_crashlytics(branch || git_branch, "stage", options[:build_number])
end
desc "Submit a new Crashlytics (Prod server) from provided/develop branch with badge"
private_lane :execute_prod do |options|
branch = options[:branch]
checkout_if_needed(options[:builder], branch)
build_crashlytics(branch || git_branch, "prod", options[:build_number])
end
desc "Submit a new AdHoc Build to Apple TestFlight from RC branch"
private_lane :execute_release_appstore do |options|
slack_train_start(distance: 7, train: "🚀", reverse_direction: true, rail: "✨")
ensure_git_status_clean
slack_train
update_pods
slack_train
fullfill_plists_with_configs
slack_train
build_appstore_release
slack_train
testflight
slack_train
refresh_dsyms(version:get_version_number_from_plist(scheme: ENV["APPSTORE_SCHEME"]))
slack_train
clean_build_artifacts
reset_git_repo
slack_train
post_to_slack(message: "Build is processed and ready to be tested #{get_version}")
end
desc "Checks if all configs settings exists in *.info plists"
private_lane :execute_fullfill_plists_with_configs do
project = Xcodeproj::Project.open(ENV["XCODE_PROJ_PATH"])
project.targets.each do |target|
plist_path = "../#{target.build_configurations[0].build_settings["INFOPLIST_FILE"]}"
plist = Xcodeproj::Plist.read_from_path(plist_path)
config = Xcodeproj::Config.new(ENV["XCODE_COFIG_PATH"])
config.attributes.each do |key, value|
plist[key] = "${#{key}}"
end
Xcodeproj::Plist.write_to_path(plist, plist_path)
end
end
desc "Passes firebase analytics argument on launchtime"
private_lane :execute_enable_firebase_debug_mode do
project_path = ENV["XCODE_PROJ_PATH"]
schemes = Xcodeproj::Project.schemes(project_path)
schemes.each do |value|
path = project_path + "/xcshareddata/xcschemes/" + value + ".xcscheme"
sheme = Xcodeproj::XCScheme.new(path)
sheme.launch_action.command_line_arguments = Xcodeproj::XCScheme::CommandLineArguments.new([{ :argument => '-FIRAnalyticsDebugEnabled', :enabled => true }])
sheme.save!
end
end
desc "Create a new release on GitHub from master branch, add tag from project version and upload changelog for it"
private_lane :execute_create_tag do
ensure_git_status_clean
git_checkout("master")
git_pull
version_number = get_version_number_from_plist(scheme: ENV["APPSTORE_SCHEME"])
puts "Last git tag is #{last_git_tag}"
raise "This version is already tagged!" if git_tag_exists(tag: "v.#{version_number}")
puts "New git tag is v.#{version_number}"
github_release = set_github_release(
repository_name: ENV["GITHUB_REPOSITORY_NAME"],
api_token: ENV["GITHUB_TOKEN"],
name: "Version #{version_number}",
tag_name: "v.#{version_number}",
description: (File.read("changelog.txt") rescue "No changelog provided"),
commitish: "master"
)
end
desc "Generate analytics"
private_lane :generate_analytics do
file = File.read(ENV["ANALYTICS_INPUT"])
json = JSON.parse(file)
def append(content)
open(ENV["ANALYTICS_OUTPUT"], 'a') { |output| output << content }
end
def newLine
append("\n")
end
def appendNewLine(content)
append(content)
newLine
end
def shouldGeneratePassedParameters(params)
params.any? { |param| param["value"] == "null" }
end
open(ENV["ANALYTICS_OUTPUT"], 'w') { |output| output.puts 'import Foundation' }
indentation = ' '
newLine
appendNewLine('struct Event {')
appendNewLine(indentation + 'let name: String')
appendNewLine(indentation + 'let parameters: [String: Any]')
appendNewLine('}')
newLine
appendNewLine('struct A {')
json.each do |category|
appendNewLine(indentation + 'struct ' + category['name'] + ' {')
category['events'].each do |event|
indentation = ' '
all = event['parameters'].map { |v| { v["name"]=>v["value"] } }.reduce(:merge)
if shouldGeneratePassedParameters(event['parameters'])
predefinedParams = all.select { |_, v| v != "null" }
injectedParams = all.select { |_, v| v == "null" }
injectedParamsNames = injectedParams.map { |k, _| k }
params = injectedParamsNames.map { |v| '_ ' + v.to_s }.join(": String, ") + ": String"
append(indentation + 'static let ')
append(event['name'].split('_').collect(&:capitalize).join.tap { |e| e[0] = e[0].downcase } + ': (' + params)
append(') -> Event = { ' + injectedParamsNames.join(", "))
append(' in Event(name: "' + event['name'] + '", parameters: [')
append(injectedParamsNames.map { |v| '"' + v.to_s + '": ' + v.to_s }.join(", "))
append(', ' + predefinedParams.to_json.sub(':"', ': "').sub('{', '').sub('}', '')) if predefinedParams.any?
append(', "' + category['name'] + '": "' + category['name'] + '"')
appendNewLine(']) }')
else
append(indentation + 'static let ')
append(event['name'].split('_').collect(&:capitalize).join.tap { |e| e[0] = e[0].downcase } + ' = Event(name: "')
append(event['name'] + '", parameters: [')
append(all.to_json.sub(':"', ': "').sub('{', '').sub('}', ''))
append(', "' + category['name'] + '": "' + category['name'] + '"')
appendNewLine('])')
end
end
indentation = ' '
appendNewLine(indentation + '}')
end
appendNewLine('}')
end
#####################################################
# Helpers
#####################################################
def get_version
return get_version_number(target: ENV["MAIN_TARGET"])
end
def checkout_if_needed(builder, branch)
if builder != "jenkins" && branch != nil
reset_git_repo
git_checkout branch
end
end
def upload_time
return Time.now.strftime("%d/%m/%Y %H:%M")
end
def update_pods
cocoapods(
clean: true,
try_repo_update_on_error: true
)
end
last_slack_progress = "[-----:train:]"
def post_to_slack(options)
progress = options[:progress]
last_slack_progress = progress
slack(
message: "#{progress} #{options[:message]}",
success: options[:success],
default_payloads: []
)
end
def git_checkout(branch)
command = [
'git',
'checkout',
branch
]
Actions.sh(command.join(' '))
UI.important "Successfully checkout branch #{branch}."
end
#####################################################
# Crashlytics Beta deploy
#####################################################
def build_crashlytics(branch, env, build_number)
UI.header "Building for branch: #{git_branch} environment: #{env}"
ensure_git_status_clean
set_build_number_if_needed(build_number)
clear_derived_data
update_pods
fullfill_plists_with_configs
enable_firebase_debug_mode
match(type: "adhoc")
# set_adhoc_provisioning_profiles
commit_hash = last_git_commit[:abbreviated_commit_hash]
message = nil
case env
when "stage"
add_badge(shield: "stage-#{get_version}-orange", no_badge: true)
gym(
scheme: ENV["STAGE_SCHEME"],
export_method: "ad-hoc",
configuration: "ReleaseStage"
)
message = "🎉 Stage build is ready to be tested #{get_version}, #{branch} 🎉"
notes = "Branch: #{branch}\nHash: #{commit_hash}\nUpload time: #{upload_time}\nServer: Staging"
when "prod"
add_badge(shield: "prod-#{get_version}-orange", no_badge: true)
gym(
scheme: ENV["PROD_SCHEME"],
export_method: "ad-hoc",
configuration: "ReleaseProd"
)
message = "🍷 Prod build is ready to be tested #{get_version}, #{branch} 🥃"
notes = "Branch: #{branch}\nHash: #{commit_hash}\nUpload time: #{upload_time}\nServer: Prod"
else
"You gave me #{env} -- I have no idea what to do with that."
end
crashlytics_upload(notes)
clean_build_artifacts
reset_git_repo
post_to_slack(message: message)
end
def set_build_number_if_needed(build_number)
if build_number != nil
UI.header "Set build number: #{build_number}"
increment_build_number_in_plist(
build_number: build_number,
target: ENV["MAIN_TARGET"]
)
end
end
def set_adhoc_provisioning_profiles
project = Xcodeproj::Project.open(ENV["XCODE_PROJ_PATH"])
profiles = eval(ENV["PROVISION_PROFILES_ADHOC"])
project.targets.each do |target|
unless profiles[target.name].nil?
["ReleaseStage", "ReleaseProd"].each do |config|
update_provisioning_profile_specifier(
target: target.name,
new_specifier: profiles[target.name],
configuration: config
)
end
end
end
end
def crashlytics_upload(notes)
crashlytics(
api_token: ENV["CRASHLYTICS_API_TOKEN"],
build_secret: ENV["CRASHLYTICS_BUILD_SECRET"],
emails: ENV["CRASHLYTICS_EMAILS"],
groups: nil,
notes: notes,
notifications: true
)
upload_symbols_to_crashlytics
end
#####################################################
# Appstore deploy
#####################################################
def build_appstore_release
match(type: "appstore")
# set_appstore_provisioning_profiles
version_number = get_version_number_from_plist(scheme: ENV["APPSTORE_SCHEME"])
version_current = latest_testflight_build_number(version: version_number).to_i + 1
version_live_raw = latest_live_version_build_number_if_exists
version_live = version_live_raw.to_i + 1
version = version_live > version_current ? version_live : version_current
increment_build_number_in_plist(
build_number: version.to_s,
target: ENV["MAIN_TARGET"]
)
gym(
scheme: ENV["APPSTORE_SCHEME"],
export_method: "app-store",
configuration: "ReleaseAppstore"
)
end
def set_appstore_provisioning_profiles
update_app_identifier(
plist_path: ENV["PLIST_PATH"],
xcodeproj: ENV["XCODE_PROJ"]
)
project = Xcodeproj::Project.open(ENV["XCODE_PROJ_PATH"])
profiles = eval(ENV["PROVISION_PROFILES_APPSTORE"])
project.targets.each do |target|
unless profiles[target.name].nil?
update_provisioning_profile_specifier(
target: target.name,
new_specifier: profiles[target.name],
configuration: "ReleaseAppstore"
)
end
end
end
def latest_live_version_build_number_if_exists
Spaceship::Tunes.login(CredentialsManager::AppfileConfig.try_fetch_value(:apple_id))
app = Spaceship::Tunes::Application.find(CredentialsManager::AppfileConfig.try_fetch_value(:app_identifier))
latest_version = app.live_version || app.latest_version
version = latest_version.version
build_number = latest_version.build_version ||= "1"
return build_number
end
#####################################################
# Error exception
#####################################################
error do |lane, exception|
clean_build_artifacts
reset_git_repo
UI.important "Fail? with '#{lane}' Exception #{exception} "
if lane == :execute_release_appstore
slack_train_crash
end
if lane == :execute_stage
post_to_slack(message: "Failed to deliver stage build #{exception}", success: false)
end
if lane == :execute_prod
post_to_slack(message: "Failed to deliver stage build #{exception}", success: false)
end
end