forked from fastlane/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Fastfile
434 lines (352 loc) · 12.3 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
422
423
424
425
426
427
428
429
430
431
432
433
434
require 'time'
require 'commander'
require 'pathname'
fastlane_version "1.57.0"
# Store the current CFBundleVersion and CFBundleShortVersionString in the fastlane context before every lane.
before_all do
Actions.lane_context[SharedValues::VERSION_NUMBER] = get_version_number
Actions.lane_context[SharedValues::BUILD_NUMBER] = get_build_number
end
desc "Install the necessary distribution certificates and private keys to sign the app. Ask a Timehop employee for the shared password to unlock the private keys."
lane :keys do
sh("security add-trusted-cert -d -r trustRoot -k $HOME/Library/Keychains/login.keychain ../certs/app_store.cer")
sh("security add-trusted-cert -d -r trustRoot -k $HOME/Library/Keychains/login.keychain ../certs/dist_enterprise.cer")
sh("security import ../certs/app_store.p12 -k login.keychain")
sh("security import ../certs/dist_enterprise.p12 -k login.keychain")
end
desc "Install the Timehop Xcode templates"
lane :templates do
sh("rm -rf ~/Library/Developer/Xcode/Templates/File\\ Templates/Timehop")
sh("mkdir -p ~/Library/Developer/Xcode/Templates/File\\ Templates/Timehop")
sh("cp -R ../Templates/* ~/Library/Developer/Xcode/Templates/File\\ Templates/Timehop")
end
desc "Send a notification when a build is done processing in iTunes Connect"
lane :watch do
sh("watchbuild -a com.timehop.ios.Timehop -u doc@timehop.com")
end
desc "Submit a new Beta Build to HockeyApp"
desc "This will also make sure the profile is up to date"
lane :beta do
ensure_git_status_clean
ensure_git_in_sync
slack(
message: "Beta incoming from branch " + sh("git rev-parse --abbrev-ref HEAD"),
channel: "#ios",
default_payloads: [:git_author]
)
cocoapods
# Get and format all the commits since the last version bump commit.
notes = changelog_from_git_commits
notes = notes + "\n\n" + "[View diff on Github](#{compare_url})"
# Bump the CFBundleVersion
new_build_number = next_version
set_build_number(
new_build_number
)
# Check for the necessary provisioning profile and download it from the developer portal if necessary.
sigh(
output_path: "/tmp",
skip_certificate_verification: true,
app_identifier: "com.timehop.ios.TimehopEnterprise"
)
# Use the UDID of the newly created provisioning profile.
# The Xcode project is configured to read the provision profile UUID through this environmental variable.
# See here for more information: https://github.com/fastlane/fastlane/blob/master/docs/CodeSigning.md#deprecated-using-environment-variables
ENV["PROFILE_UDID"] = lane_context[SharedValues::SIGH_UDID]
# Build the app.
gym(
workspace: "TimehopThree.xcworkspace",
configuration: "Beta",
scheme: "TimehopThree Beta",
export_method: 'enterprise',
codesigning_identity: "iPhone Distribution: DOUBLEDUB INC",
use_legacy_build_api: true # There's a bug in the new Xcode 7 API that causes problems. This forces use of the old API.
)
# Upload the build to HockeyApp.
hockey(
api_token: ENV['HOCKEYAPP_TOKEN'],
public_identifier: ENV['HOCKEYAPP_BETA_ID'],
notes: notes,
notes_type: "1",
commit_sha: `git rev-parse HEAD`.strip
)
clean_build_artifacts
commit_version_bump(
message: "Version bump " + new_build_number,
force: true
)
push_to_git_remote
end
desc "Submit a new Gamma Build (external beta) to HockeyApp"
desc "This will also make sure the profile is up to date"
lane :gamma do
ensure_git_status_clean
ensure_git_in_sync
slack(
message: "Gamma incoming from branch " + sh("git rev-parse --abbrev-ref HEAD"),
channel: "#ios",
default_payloads: [:git_author]
)
cocoapods
# Prompts for the HockeyApp release notes.
notes = prompt(
text: "Enter release notes",
multi_line_end_keyword: "END"
)
# Bump the CFBundleVersion
new_build_number = next_version
set_build_number(
new_build_number
)
# Check for the necessary provisioning profile and download it from the developer portal if necessary.
sigh(
output_path: "/tmp",
skip_certificate_verification: true,
app_identifier: "com.timehop.ios.TimehopMaybe"
)
# Use the UDID of the newly created provisioning profile.
# The Xcode project is configured to read the provision profile UUID through this environmental variable.
# See here for more information: https://github.com/fastlane/fastlane/blob/master/docs/CodeSigning.md#deprecated-using-environment-variables
ENV["PROFILE_UDID"] = lane_context[SharedValues::SIGH_UDID]
# Build the app.
gym(
workspace: "TimehopThree.xcworkspace",
configuration: "Gamma",
scheme: "TimehopThree Gamma",
export_method: 'enterprise'
)
# Upload the build to HockeyApp.
hockey(
api_token: ENV['HOCKEYAPP_TOKEN'],
public_identifier: ENV['HOCKEYAPP_GAMMA_ID'],
notes: notes,
notes_type: "1",
commit_sha: `git rev-parse HEAD`.strip
)
clean_build_artifacts
commit_version_bump(
message: "Version bump " + new_build_number,
force: true
)
push_to_git_remote
end
desc "Deploy a new version to the App Store"
lane :appstore do
ensure_git_branch
ensure_git_status_clean
ensure_git_in_sync
slack(
message: "App Store build incoming",
channel: "#ios",
default_payloads: [:git_author]
)
cocoapods
# Ask for a new CFBundleShortVersionString and bump the CFBundleVersion.
new_build_number = next_version
version = ask("Enter a new version number: ")
set_build_number(
new_build_number
)
set_version_number(
version
)
# Check for the necessary provisioning profile and download it from the developer portal if necessary.
sigh(
output_path: "/tmp",
app_identifier: "com.timehop.ios.Timehop"
)
# Use the UDID of the newly created provisioning profile.
# The Xcode project is configured to read the provision profile UUID through this environmental variable.
# See here for more information: https://github.com/fastlane/fastlane/blob/master/docs/CodeSigning.md#deprecated-using-environment-variables
ENV["PROFILE_UDID"] = lane_context[SharedValues::SIGH_UDID]
# Generate a name for the xcarchive file.
# Also generate the destination path which is inside the Timehop dropbox folder.
archive_name = version + " - TimehopThree " + Time.now.strftime("%F %H.%M.%S") + ".xcarchive"
archive_path = archive_destination(archive_name)
# Build the app.
gym(
workspace: "TimehopThree.xcworkspace",
configuration: "Release",
scheme: "TimehopThree",
clean: false,
codesigning_identity: "iPhone Distribution: DOUBLEDUB INC (SYMQPHZ6U8)",
archive_path: archive_path,
export_team_id: "SYMQPHZ6U8",
use_legacy_build_api: true # There's a bug in the new Xcode 7 API that causes problems. This forces use of the old API.
)
# Upload the build to iTunes Connect.
deliver(
force: true,
skip_screenshots: true
)
clean_build_artifacts
commit_version_bump(
message: "Version bump " + version + ", " + new_build_number,
force: true
)
push_to_git_remote
end
desc "Build and package the app for submission to Facebook"
lane :facebook do
ensure_git_branch
ensure_git_status_clean
ensure_git_in_sync
cocoapods
# Check for the necessary provisioning profile and download it from the developer portal if necessary.
sigh(
output_path: "/tmp"
)
# Use the UDID of the newly created provisioning profile.
# The Xcode project is configured to read the provision profile UUID through this environmental variable.
# See here for more information: https://github.com/fastlane/fastlane/blob/master/docs/CodeSigning.md#deprecated-using-environment-variables
ENV["PROFILE_UDID"] = lane_context[SharedValues::SIGH_UDID]
# Build the app.
path = Pathname.getwd.dirname.to_s + "/build"
xcbuild(
workspace: "TimehopThree.xcworkspace",
scheme: "TimehopThree",
sdk: "iphonesimulator",
configuration: "Release",
derivedDataPath: path.to_s
)
# Zip the app.
app_path = path + "/Build/Products/Release-iphonesimulator/"
zip_path = "~/Desktop/Timehop.zip"
sh("cd #{app_path};zip -r #{zip_path} Timehop.app")
clean_build_artifacts
end
desc "Edits the release notes for all languages at once and uploads them to iTunes Connect"
lane :release_notes do
ensure_git_branch
ensure_git_status_clean
# Prompt for release notes.
notes = prompt(
text: "Enter release notes",
multi_line_end_keyword: "END"
)
# Update the release notes for every language.
Dir.foreach('./metadata') do |filename|
next if filename == '.' or filename == '..' or !File.directory?("./metadata/#{filename}")
File.open("./metadata/#{filename}/release_notes.txt", 'w') do |file|
file.write notes
end
end
puts "Use the deliver command to upload the metadata"
commit_metadata(force: true)
push_to_git_remote
end
desc "Bump both version numbers"
lane :bump do
ensure_git_status_clean
ensure_git_in_sync
# Ask for a new CFBundleShortVersionString and bump the CFBundleVersion.
new_build_number = next_version
version = ask("Enter a new version number: ")
set_build_number(
new_build_number
)
set_version_number(
version
)
commit_version_bump(
message: "Version bump " + version + ", " + new_build_number,
force: true
)
push_to_git_remote
end
desc "Compare the current git state to the last version bump"
lane :compare do
puts compare_url
end
desc "Upload screenshots from the specified directory to iTunes Connect"
lane :screenshots do
directory = prompt(:text => "Where are the screenshots located?")
# Copy the screenshots to the directory for each language.
Dir.foreach('./screenshots') do |filename|
next if filename == '.' or filename == '..' or !File.directory?("./metadata/#{filename}")
sh("rm ./screenshots/#{filename}/*.*")
sh("cp #{directory}/* ./screenshots/#{filename}/")
end
puts "Use the deliver command to upload the metadata"
sh("git add ./screenshots")
sh("git commit -m 'Update app store screenshots'")
push_to_git_remote
end
after_all do |lane|
ship_it
notify("Lane #{lane} completed successfully!")
end
error do |lane, exception|
clean_build_artifacts
puts "\n(╯°□°)╯︵ ┻━┻\n".red
notify("Lane #{lane} failed to complete.")
end
# Helper functions
def next_version
Time.now.strftime("%Y%m%d%H%M")
end
def get_build_number
`/usr/libexec/PlistBuddy -c 'Print CFBundleVersion' ../TimehopThree/TimehopThree-Info.plist`.strip
end
def get_version_number
`/usr/libexec/PlistBuddy -c 'Print CFBundleShortVersionString' ../TimehopThree/TimehopThree-Info.plist`.strip
end
def set_build_number(build_number = nil)
raise if build_number.nil?
puts "Setting build number to #{build_number}"
Actions.lane_context[SharedValues::BUILD_NUMBER] = build_number
sh("/usr/libexec/PlistBuddy -c 'Set CFBundleVersion #{build_number}' ../TimehopThree/TimehopThree-Info.plist")
end
def set_version_number(version_number = nil)
raise if version_number.nil?
puts "Setting version number to #{version_number}"
Actions.lane_context[SharedValues::VERSION_NUMBER] = version_number
sh("/usr/libexec/PlistBuddy -c 'Set CFBundleShortVersionString #{version_number}' ../TimehopThree/TimehopThree-Info.plist")
end
def archive_destination(filename = nil)
raise "non-nil filename required" if filename.nil?
dropbox_folder = File.expand_path("~/Dropbox (Timehop)")
if !File.exist? dropbox_folder
dropbox_folder = File.expand_path(ask("Where is your Timehop Dropbox folder?"))
end
raise "Could not find Timehop Dropbox folder at #{dropbox_folder}" if !File.exist?(dropbox_folder)
"#{dropbox_folder}/Timehop Product/Tech/iOS Submitted Apps/#{filename}"
end
def compare_url
last_bump_hash = sh("cd ../;git log --pretty=format:'%s %h' | grep -i '^version bump [0-9]\\{12\\}\\b' | awk '{print $NF}' | head -n1").strip
current_hash = sh("git rev-parse HEAD").strip
"https://github.com/timehop/TimehopThree-iOS/compare/#{last_bump_hash}...#{current_hash}"
end
def ship_it
rand = Random.rand(0..1)
if rand == 0
squirrel
elsif rand == 1
boat
end
end
def squirrel
puts "
!!!!
!!!!!!!!
!!!!!!!!!!! O_O
!!! !!!!!!! /@ @\\
!!!!!! \\ x /
!!!!!!/ m !m
!!!!/ __ |
!!!!|/ \\__
!!!\\______\\
"
end
def boat
puts "
. o ..
o . o o.o
...oo
__[]__
__|_o_o_o\__
\\\"\"\"\"\"\"\"\"\"\"/
\\. .. . /
^^^^^^^^^^^^^^^^^^^^
"
end