-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathFastfile
297 lines (257 loc) · 9.36 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
# frozen_string_literal: true
default_platform(:ios)
platform :ios do
desc 'Run tests'
lane :tests do |options|
skip_docs
sh('rm -rf test_output/*')
scan(
project: 'TICE.xcodeproj',
scheme: 'TICE',
cloned_source_packages_path: '.swift-packages',
xcpretty_args: '--color',
build_for_testing: true,
clean: true
)
begin
test_plan = options[:test_plan] || 'UnitTests'
puts "Running test plan '#{test_plan}'"
scan(
project: 'TICE.xcodeproj',
scheme: 'TICE',
testplan: test_plan,
cloned_source_packages_path: '.swift-packages',
xcpretty_args: '--color',
test_without_building: true,
reset_simulator: true,
reinstall_app: true,
app_identifier: 'app.tice.TICE.development',
device: 'iPhone 12',
result_bundle: true
)
ensure
sh('bundle exec xcparse screenshots test_output/TICE.xcresult test_output/screenshots')
end
end
desc 'Run linter'
lane :lint do
skip_docs
swiftlint(config_file: '.swiftlint.yml', quiet: true, strict: true, ignore_exit_status: true)
end
desc 'Prepare merge request'
lane :pr do
skip_docs
sh('git', 'push', '--dry-run')
lint_result = lint
if lint_result != '' && (prompt(text: 'Lint step exited with warnings/errors. Do you want to proceed anyway?',
boolean: true) == false)
UI.user_error!('Aborting as requested.')
next
end
sh('BRANCH=`git rev-parse --abbrev-ref HEAD | sed -e "s~/~%2F~g"` && open "https://github.com/TICESoftware/TICE-ios/compare/develop...${BRANCH}"')
sh('open "https://tenor.com"')
end
desc 'Download provisioning profiles'
lane :download_provisioning_profiles do
sh 'bundle exec fastlane sigh download_all'
end
desc 'Deploy ad-hoc testing'
lane :deployAdHoc do |options|
skip_docs
if options[:ci]
unlock_keychain(
path: 'Development',
add_to_search_list: :replace,
password: ENV['DEVELOPMENT_KEYCHAIN_PASSWORD']
)
directory = '~/.jenkins/userContent/testing'
label = ENV['GIT_BRANCH']
else
directory = './testing'
label = 'testing'
end
download_provisioning_profiles
testing_dir = '/usr/local/var/www/testing'
base_url = 'https://ci.tice.software/testing/'
file_name = "TICE-#{label}.ipa"
url = base_url + file_name
manifest_template_file = './fastlane/manifest-testing.plist'
manifest_filename = "manifest-#{label}.plist"
manifest_file = "./build/#{manifest_filename}"
version = getAppVersion
Dir.chdir('..') do
puts 'Cleaning old ad hoc builds'
sh "find #{directory} -type f -mtime +14 -print0 | xargs -0 rm -v --"
sh "find #{testing_dir} -type f -mtime +14 -print0 | xargs -0 rm -v --"
if options[:ci]
puts 'Cleaning old xcarchives'
sh "find ~/Library/Developer/Xcode/Archives -type d -name 'TICE-*.xcarchive' " \
"-not \\( -path '*TICE-release *.xcarchive' -prune \\) -mtime +30 -print0 | " \
'xargs -0 rm -rv --'
end
end
build_app(
project: 'TICE.xcodeproj',
configuration: 'Testing',
clean: true,
scheme: 'TICE',
cloned_source_packages_path: '.swift-packages',
export_method: 'ad-hoc',
output_directory: directory,
output_name: file_name
)
if options[:ci]
Dir.chdir('..') do
puts "Setting url #{url} in Manifest"
sh "mkdir -p $(dirname #{manifest_file})"
sh "cp \"#{manifest_template_file}\" \"#{manifest_file}\""
sh "/usr/libexec/PlistBuddy -c \"Set :items:0:assets:0:url #{url}\" \"#{manifest_file}\""
sh "/usr/libexec/PlistBuddy -c \"Set :items:0:metadata:bundle-version #{version}\" \"#{manifest_file}\""
sh "/usr/libexec/PlistBuddy -c \"Set :items:0:metadata:title TICE - Testing #{label}\" \"#{manifest_file}\""
end
puts 'Copying files to publicly accessible directory'
ipa_path = lane_context[SharedValues::IPA_OUTPUT_PATH]
artifacts = [ipa_path, manifest_file]
copy_artifacts(artifacts: artifacts, target_path: testing_dir, fail_on_missing: true)
encoded_manifest_url = URI.encode_www_form_component(base_url + manifest_filename)
itms_url = "itms-services://nohost?action=download-manifest&url=#{encoded_manifest_url}"
slack(
message: "A new testing build for #{label} (#{version}) is ready for testing.",
slack_url: ENV['SLACK_WEBHOOK_URL'],
attachment_properties: {
actions: [
{
type: 'button',
name: 'download_button',
text: 'Download on iOS',
url: itms_url,
style: 'primary'
}
]
}
)
end
end
desc 'Trigger Preview'
lane :preview do |options|
buildPreview(options)
deliverPreview(options)
end
desc 'Update App Version'
lane :updateAppVersion do |options|
puts "Updating with #{options}"
rel_path = options[:rel_path] || '../'
puts rel_path
project = Xcodeproj::Project.open("#{rel_path}TICE.xcodeproj")
puts project
project.build_configuration_list.build_configurations.each do |build_configuration|
puts "Bumping version of #{build_configuration} from \
#{build_configuration.build_settings['APP_VERSION']} to #{options[:version]}"
build_configuration.build_settings['APP_VERSION'] = options[:version]
end
project.save
puts "Saved project. Returning #{options[:version]}"
options[:version]
end
desc 'Get App Version'
lane :getAppVersion do |options|
rel_path = options[:rel_path] || '../'
project = Xcodeproj::Project.open("#{rel_path}TICE.xcodeproj")
project.build_settings('Production')['APP_VERSION']
end
desc 'Build Preview'
lane :buildPreview do |options|
new_version = options[:version]
should_bump_version = !new_version.empty?
skip_increment_build_number = options[:skip_increment_build_number] == true
skip_docs
ensure_git_status_clean
download_provisioning_profiles
increment_build_number unless skip_increment_build_number
version = if should_bump_version
updateAppVersion(version: new_version)
else
getAppVersion
end
build_number = get_build_number
commit_version_bump(xcodeproj: './TICE.xcodeproj') if !skip_increment_build_number || should_bump_version
build_app(
project: 'TICE.xcodeproj',
configuration: 'Preview',
clean: true,
scheme: 'TICE',
cloned_source_packages_path: '.swift-packages',
export_method: 'app-store'
)
if !skip_increment_build_number || should_bump_version
add_git_tag(tag: "#{version}-#{build_number}-preview")
push_to_git_remote
end
end
desc 'Deliver Preview'
lane :deliverPreview do
pilot(skip_waiting_for_build_processing: true)
end
desc 'Trigger Release'
lane :release do |options|
buildRelease(options)
deliverRelease(options)
end
desc 'Build Release'
lane :buildRelease do |_options|
skip_docs
ensure_git_status_clean
build_app(
project: 'TICE.xcodeproj',
configuration: 'Production',
clean: true,
scheme: 'TICE',
cloned_source_packages_path: '.swift-packages',
export_method: 'app-store'
)
version = getAppVersion
build_number = get_build_number
add_git_tag(tag: "#{version}-#{build_number}")
push_to_git_remote
end
desc 'Deliver Release'
lane :deliverRelease do |options|
make_screenshots = options[:screenshots] == true
deliver(
force: true,
submission_information: {
add_id_info_uses_idfa: false
},
skip_screenshots: !make_screenshots,
precheck_include_in_app_purchases: false
)
end
desc 'Bump version'
lane :bumpVersion do
skip_docs
increment_build_number
version = getAppVersion
build_number = get_build_number
commit_version_bump(xcodeproj: './TICE.xcodeproj')
add_git_tag(tag: "#{version}-#{build_number}")
end
desc 'Style screenshots'
lane :style_screenshots do
frame_screenshots(path: './fastlane/snapshots', resume: true)
copy_artifacts(target_path: './fastlane/screenshots/de-DE', artifacts: './fastlane/snapshots/de-DE/*_framed.png')
copy_artifacts(target_path: './fastlane/screenshots/en-US', artifacts: './fastlane/snapshots/en-US/*_framed.png')
copy_artifacts(target_path: './fastlane/screenshots/en-GB', artifacts: './fastlane/snapshots/en-US/*_framed.png')
copy_artifacts(target_path: './fastlane/screenshots/fr-FR', artifacts: './fastlane/snapshots/fr-FR/*_framed.png')
copy_artifacts(target_path: './fastlane/screenshots/pt-BR', artifacts: './fastlane/snapshots/pt-BR/*_framed.png')
copy_artifacts(target_path: './fastlane/screenshots/es-ES', artifacts: './fastlane/snapshots/es-ES/*_framed.png')
copy_artifacts(target_path: './fastlane/screenshots/es-MX', artifacts: './fastlane/snapshots/es-ES/*_framed.png')
copy_artifacts(target_path: './fastlane/screenshots/da', artifacts: './fastlane/snapshots/da/*_framed.png')
end
error do |lane, _exception, _options|
if %i[preview
release].include?(lane) && prompt(text: 'Lane failed. Should I run git reset on the repo?', boolean: true,
ci_input: 'n')
reset_git_repo(skip_clean: true, force: true)
end
end
end