-
Notifications
You must be signed in to change notification settings - Fork 1
/
Forge.rb
451 lines (376 loc) · 11.9 KB
/
Forge.rb
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
###########################
# Overrides methods #
###########################
before_all do
UI.user_error! 'You must run fastlane using `bundle exec fastlane`' if ENV['BUNDLE_GEMFILE'].nil?
fastlane_require 'fastlane-plugin-badge'
fastlane_require 'fastlane-plugin-brew'
fastlane_require 'fastlane-plugin-changelog'
fastlane_require 'fastlane-plugin-dependency_check_ios_analyzer'
fastlane_require 'fastlane-plugin-firebase_app_distribution'
fastlane_require 'fastlane-plugin-xcconfig'
fastlane_require 'fastlane-plugin-xcodegen'
end
after_all do |lane|
next if is_ci
notification(
title: "✅ fastlane #{lane}",
message: "Configuration: #{ENV['CONFIGURATION'] || '(none)'}",
app_icon: 'https://s3-eu-west-1.amazonaws.com/fastlane.tools/fastlane.png',
sound: 'default'
)
end
error do |lane, exception|
next if is_ci
notification(
title: "🛑 fastlane #{lane}",
message: "Error: #{exception}",
app_icon: 'https://s3-eu-west-1.amazonaws.com/fastlane.tools/fastlane.png',
sound: 'hero'
)
end
###########################
# Requirement #
###########################
desc 'Install developer tools'
lane :install_developer_tools do
# Install rbenv for initializing ruby in the project
brew(command: 'install rbenv') unless is_ci
# Install ruby-build, an rbenv plugin to easily install any version of ruby
brew(command: 'install ruby-build') unless is_ci
# Install pyenv for python initialization in the project
brew(command: 'install pyenv') unless is_ci
# Install swiftlint
brew(command: 'install swiftlint')
# Install swiftformat
brew(command: 'install swiftformat')
# Install periphery
brew(command: 'install peripheryapp/periphery/periphery')
end
desc 'Prepare configuration'
lane :config do |options|
# override method
end
desc 'Switch to the specified environment'
lane :switch_to_env do |options|
# override method
end
###########################
# Prepare #
###########################
desc 'Before prepare'
lane :before_prepare do |options|
# override method
end
desc 'Generate project and install pods'
lane :prepare do |options|
install_developer_tools
before_prepare(options)
switch_to_env(options) if options[:env]
config(options) if options[:config]
swiftgen unless ENV['SWIFTGEN_PATH'].nil?
xcodegen(spec: ENV['XCODEGEN_PATH']) unless ENV['XCODEGEN_PATH'].nil?
cocoapods unless ENV['PODFILE_PATH'].nil?
after_prepare(options)
end
desc 'After prepare'
lane :after_prepare do |options|
# override method
end
###########################
# Test #
###########################
desc 'Runs all the tests'
lane :test do |options|
prepare(options)
if ENV['PODFILE_PATH'].nil?
scan_with_project
else
scan_with_workspace
end
danger(dangerfile: ENV['DANGERFILE_PATH']) if is_ci && !ENV['DANGERFILE_PATH'].nil?
after_test(options)
end
lane :after_test do |options|
# override method
end
desc 'Scan with project for SPM project'
private_lane :scan_with_project do
scan(
project: ENV.fetch('XCPROJECT', nil),
scheme: ENV.fetch('SCHEME', nil),
clean: false,
output_types: 'junit',
result_bundle: true,
code_coverage: true,
derived_data_path: ENV.fetch('DERIVED_DATA_PATH', nil),
output_directory: ENV.fetch('REPORTS_PATH', nil),
fail_build: ENV.fetch('FAIL_BUILD', 'true') == 'true'
)
end
desc 'Scan with workspace for CocoaPods project'
private_lane :scan_with_workspace do
scan(
workspace: ENV.fetch('XCWORKSPACE', nil),
scheme: ENV.fetch('SCHEME', nil),
clean: false,
output_types: 'junit',
result_bundle: true,
code_coverage: true,
derived_data_path: ENV.fetch('DERIVED_DATA_PATH', nil),
output_directory: ENV.fetch('REPORTS_PATH', nil),
fail_build: ENV.fetch('FAIL_BUILD', 'true') == 'true'
)
end
###########################
# Archive #
###########################
desc 'Build and archive the app'
lane :archive do |options|
distribution_method = options[:enterprise] == true ? 'enterprise' : 'ad-hoc'
export_method = options[:appstore] == true ? 'app-store' : distribution_method
symbols_inclusion = options[:appstore] == true ? false : true
prepare(options)
set_build_number unless ENV['PLIST_PATH'].nil?
badge_icon
if options[:icloud] == true
export_options = {
iCloudContainerEnvironment: ENV['ICLOUD_CONTAINER_ENVIRONMENT']
}
end
if ENV['PODFILE_PATH'].nil?
gym_with_project(
export_method: export_method,
export_options: export_options,
symbols_inclusion: symbols_inclusion
)
else
gym_with_workspace(
export_method: export_method,
export_options: export_options,
symbols_inclusion: symbols_inclusion
)
end
end
desc 'Gym with project for SPM project'
private_lane :gym_with_project do |options|
gym(
project: ENV.fetch('XCPROJECT', nil),
scheme: ENV.fetch('SCHEME', nil),
configuration: ENV.fetch('CONFIGURATION', nil),
output_name: "#{ENV['APP_NAME']}.ipa",
export_method: options[:export_method],
sdk: 'iphoneos',
silent: true,
clean: false,
build_path: ENV.fetch('BUILD_PATH', nil),
output_directory: ENV.fetch('BUILD_PATH', nil),
export_options: options[:export_options],
include_symbols: options[:symbols_inclusion]
)
end
desc 'Gym with workspace for CocoaPods project'
private_lane :gym_with_workspace do |options|
gym(
workspace: ENV.fetch('XCWORKSPACE', nil),
scheme: ENV.fetch('SCHEME', nil),
configuration: ENV.fetch('CONFIGURATION', nil),
output_name: "#{ENV['APP_NAME']}.ipa",
export_method: options[:export_method],
sdk: 'iphoneos',
silent: true,
clean: false,
build_path: ENV.fetch('BUILD_PATH', nil),
output_directory: ENV.fetch('BUILD_PATH', nil),
export_options: options[:export_options],
include_symbols: options[:symbols_inclusion]
)
end
desc 'Extract the build number from bitrise into environment variables and set in Info.plist'
private_lane :set_build_number do
UI.message 'Extracting Build number'
if ENV['BITRISE_BUILD_NUMBER']
UI.message "==> bitrise build number : #{ENV['BITRISE_BUILD_NUMBER']}"
set_info_plist_value(
path: ENV.fetch('PLIST_PATH', nil),
key: 'CFBundleVersion',
value: ENV['BITRISE_BUILD_NUMBER']
)
end
end
desc 'Extract the version & build number from the project into environment variables'
private_lane :get_versions_from_project do
UI.message 'Extracting Version & Build number…'
current_version = get_xcconfig_value(
path: ENV.fetch('APP_VERSION_PATH', nil),
name: 'APP_VERSION'
)
current_build_number = get_xcconfig_value(
path: ENV.fetch('APP_VERSION_PATH', nil),
name: 'APP_BUILD_NUMBER'
)
ENV['VERSION_NUMBER'] = current_version
ENV['BUILD_NUMBER'] = ENV['BITRISE_BUILD_NUMBER'] || current_build_number
UI.message "==> v#{ENV['VERSION_NUMBER']} (#{ENV['BUILD_NUMBER']})"
end
desc 'Add a badge to the bottom of the icon with the version/build/env info'
# @option add_badge: true|false — defaults to false (which just git-resets the icon to remove the badge)
private_lane :badge_icon do |options|
if options[:badge]
brew(command: 'install imagemagick')
# Reset the icon
Dir['../**/*.appiconset'].each do |path|
puts %(Reverting: git checkout -- "#{path}")
`git checkout -- "#{path}"`
end
get_versions_from_project
# Add the shield.io badge
add_badge(
shield: "#{ENV['VERSION_NUMBER']}%20(#{ENV['BUILD_NUMBER']})-#{ENV['APP_ENVIRONMENT']}-blue",
shield_gravity: 'SouthEast',
no_badge: true # Remove default "Beta" banner
)
end
end
###########################
# Deploy #
###########################
desc 'Before OTA upload'
lane :before_ota_upload do |options|
# override method
end
desc 'Build and distribute OTA to Firebase App Distribution'
lane :ota do |options|
archive(options)
before_ota_upload(options)
changelog = File.read(ENV['CHANGELOG_PATH'])
firebase_app_distribution(
googleservice_info_plist_path: ENV.fetch('GS_INFO_PLIST_ARCHIVE_PATH', nil),
release_notes: changelog,
service_credentials_file: ENV.fetch('GOOGLE_APPLICATION_CREDENTIALS', nil),
groups: ENV.fetch('FIREBASE_TEST_GROUP', nil)
)
end
desc 'Before beta upload'
lane :before_beta_upload do |options|
# override method
end
desc 'Submit a new Beta Build to Apple TestFlight'
lane :beta do |options|
options[:appstore] = true
archive(options)
before_beta_upload(options)
app_store_connect_api_key(
key_id: ENV.fetch('KEY_ID', nil),
issuer_id: ENV.fetch('ISSUER_ID', nil),
key_filepath: ENV.fetch('KEY_FILEPATH', nil)
)
pilot(
skip_submission: true,
skip_waiting_for_build_processing: true
)
end
###########################
# Metrics / Sonar #
###########################
desc "Install all metrics tools"
private_lane :install_metrics_tools do
sh('pip3 install --upgrade mobsfscan')
brew(command: 'install sonar-scanner')
end
desc "Send all metrics to Sonar"
lane :send_metrics do |options|
test(options)
install_metrics_tools
version = get_version_number(
xcodeproj: ENV.fetch('XCPROJECT', nil),
target: ENV.fetch('TARGET', nil)
)
sonar(project_version: version)
end
###########################
# Poesie #
###########################
desc 'Import Localizable.string from POEditor'
lane :poesie do
sh("bash #{ENV['POESIE_PATH']}")
end
###########################
# SwiftGen #
###########################
desc 'Generate assets with SwiftGen'
lane :swiftgen do
Dir.chdir("..") do
brew(command: 'install swiftgen')
sh("swiftgen config run --config #{ENV['SWIFTGEN_PATH']}")
end
end
###########################
# Versioning #
###########################
desc "Increment the patch number of APP_VERSION"
lane :increment_patch do
# get current version with xcconfig plugin
current_version = get_xcconfig_value(
path: ENV.fetch('APP_VERSION_PATH', nil),
name: 'APP_VERSION'
)
# parse version number and add 1 to the patch number
parsed_version = current_version.split(".").map(&:to_i)
new_version = "#{parsed_version[0]}.#{parsed_version[1]}.#{parsed_version[2] + 1}"
# update version with xcconfig plugin
update_xcconfig_value(
path: ENV.fetch('APP_VERSION_PATH', nil),
name: 'APP_VERSION',
value: new_version.to_s
)
end
desc "Increment the minor number of APP_VERSION"
lane :increment_minor do
# get current version with xcconfig plugin
current_version = get_xcconfig_value(
path: ENV.fetch('APP_VERSION_PATH', nil),
name: 'APP_VERSION'
)
# parse version number, add 1 to the minor number and reset patch number
parsed_version = current_version.split(".").map(&:to_i)
new_version = "#{parsed_version[0]}.#{parsed_version[1] + 1}.0"
# update version with xcconfig plugin
update_xcconfig_value(
path: ENV.fetch('APP_VERSION_PATH', nil),
name: 'APP_VERSION',
value: new_version.to_s
)
end
desc "Increment the major number of APP_VERSION"
lane :increment_major do
# get current version with xcconfig plugin
current_version = get_xcconfig_value(
path: ENV.fetch('APP_VERSION_PATH', nil),
name: 'APP_VERSION'
)
# parse version number, add 1 to the major number and reset minor and patch numbers
parsed_version = current_version.split(".").map(&:to_i)
new_version = "#{parsed_version[0] + 1}.0.0"
# update version with xcconfig plugin
update_xcconfig_value(
path: ENV.fetch('APP_VERSION_PATH', nil),
name: 'APP_VERSION',
value: new_version.to_s
)
end
####################
# Dependency check #
####################
desc 'OWASP dependency-check iOS analyzers'
lane :dependency_check do
is_using_spm = ENV['PODFILE_PATH'].nil?
dependency_check_ios_analyzer(
skip_spm_analysis: !is_using_spm,
skip_pods_analysis: is_using_spm,
project_name: ENV['APP_NAME'],
output_directory: ENV['REPORTS_PATH'],
output_types: 'all',
suppression: ENV['DEPENDENCY_CHECK_SUPPRESSION_FILE_PATH']
)
end