-
Notifications
You must be signed in to change notification settings - Fork 133
/
Fastfile
789 lines (708 loc) · 33.8 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
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
default_platform(:android)
fastlane_require 'dotenv'
unless FastlaneCore::Helper.bundler?
UI.user_error!('Please run fastlane via `bundle exec`')
end
before_all do |lane|
# Ensure we use the latest version of the toolkit
check_for_toolkit_updates unless is_ci || ENV['FASTLANE_SKIP_TOOLKIT_UPDATE_CHECK']
end
########################################################################
# Constants
########################################################################
PROJECT_ROOT_FOLDER = File.dirname(File.expand_path(__dir__))
BUILD_PRODUCTS_PATH = File.join(PROJECT_ROOT_FOLDER, 'artifacts')
INSTALLABLE_BUILD_DOMAIN = 'https://d2twmm2nzpx3bg.cloudfront.net'
METADATA_DIR_PATH = File.join(PROJECT_ROOT_FOLDER, 'WooCommerce', 'metadata')
RELEASE_NOTES_PATH = File.join(METADATA_DIR_PATH, 'release_notes.txt')
MAIN_STRINGS_PATH = File.join('WooCommerce', 'src', 'main', 'res', 'values', 'strings.xml')
FROZEN_STRINGS_DIR_PATH = "./fastlane/resources/values/"
REMOTE_LIBRARIES_STRINGS_PATHS = [
{
name: 'Login Library',
import_key: 'wordPressLoginVersion',
repository: 'wordpress-mobile/WordPress-Login-Flow-Android',
strings_file_path: 'WordPressLoginFlow/src/main/res/values/strings.xml',
exclusions: ['default_web_client_id']
},
{
name: 'About Library',
import_key: 'aboutAutomatticVersion', # key used in build.gradle to reference the version
repository: 'Automattic/about-automattic-android',
strings_file_path: 'library/src/main/res/values/strings.xml',
exclusions: []
}
].freeze
# URL of the GlotPress project containing the app's strings
GLOTPRESS_APP_STRINGS_PROJECT_URL = 'https://translate.wordpress.com/projects/woocommerce/woocommerce-android/'
# URL of the GlotPress project containing the Play Store metadata (title, keywords, release notes, …)
GLOTPRESS_PLAYSTORE_METADATA_PROJECT_URL = 'https://translate.wordpress.com/projects/woocommerce/woocommerce-android/release-notes/'
########################################################################
# Environment
########################################################################
Dotenv.load('~/.wcandroid-env.default')
ENV[GHHELPER_REPO="woocommerce/woocommerce-android"]
ENV["PROJECT_NAME"]="WooCommerce"
ENV["PROJECT_ROOT_FOLDER"]="./"
ENV['FL_RELEASE_TOOLKIT_DEFAULT_BRANCH'] = 'trunk'
REPOSITORY_NAME="woocommerce-android"
GH_ORG_NAME="woocommerce"
UPLOAD_TO_PLAY_STORE_JSON_KEY = File.join(Dir.home, '.configure', 'woocommerce-android', 'secrets', 'google-upload-credentials.json')
SUPPORTED_LOCALES = [
{ glotpress: "ar", android: "ar", google_play: "ar", promo_config: {}},
{ glotpress: "de", android: "de", google_play: "de-DE", promo_config: {} },
{ glotpress: "es", android: "es", google_play: "es-ES", promo_config: {} },
{ glotpress: "fr", android: "fr", google_play: "fr-FR", promo_config: {} },
{ glotpress: "he", android: "he", google_play: "iw-IL", promo_config: {} },
{ glotpress: "id", android: "id", google_play: "id", promo_config: {} },
{ glotpress: "it", android: "it", google_play: "it-IT", promo_config: {} },
{ glotpress: "ja", android: "ja", google_play: "ja-JP", promo_config: {} },
{ glotpress: "ko", android: "ko", google_play: "ko-KR", promo_config: {} },
{ glotpress: "nl", android: "nl", google_play: "nl-NL", promo_config: {} },
{ glotpress: "pt-br", android: "pt-rBR", google_play: "pt-BR", promo_config: {} },
{ glotpress: "ru", android: "ru", google_play: "ru-RU", promo_config: {} },
{ glotpress: "sv", android: "sv", google_play: "sv-SE", promo_config: {} },
{ glotpress: "tr", android: "tr", google_play: "tr-TR", promo_config: {} },
{ glotpress: "zh-cn", android: "zh-rCN", google_play: "zh-CN", promo_config: {} },
{ glotpress: "zh-tw", android: "zh-rTW", google_play: "zh-TW", promo_config: {} },
].freeze
SCREENSHOT_DIRECTORY = File.join(Dir.pwd, 'screenshots')
platform :android do
########################################################################
# Release Lanes
########################################################################
#####################################################################################
# code_freeze
# -----------------------------------------------------------------------------------
# This lane executes the steps planned on code freeze
# -----------------------------------------------------------------------------------
# Usage:
# bundle exec fastlane code_freeze codefreeze_version:<version> [update_release_branch_version:<update flag>] [skip_confirm:<skip confirm>]
#
# Example:
# bundle exec fastlane code_freeze
# bundle exec fastlane code_freeze skip_confirm:true
#####################################################################################
desc "Creates a new release branch from the current trunk"
lane :code_freeze do | options |
android_codefreeze_prechecks(options)
android_bump_version_release()
new_version = android_get_app_version()
extract_release_notes_for_version(
version: new_version,
release_notes_file_path: File.join(PROJECT_ROOT_FOLDER, 'RELEASE-NOTES.txt'),
extracted_notes_file_path: RELEASE_NOTES_PATH
)
android_update_release_notes(new_version: new_version)
setbranchprotection(repository:GHHELPER_REPO, branch: "release/#{new_version}")
setfrozentag(repository:GHHELPER_REPO, milestone: new_version)
end
#####################################################################################
# complete_code_freeze
# -----------------------------------------------------------------------------------
# This lane executes the last steps planned on code freeze
# -----------------------------------------------------------------------------------
# Usage:
# bundle exec fastlane complete_code_freeze [skip_confirm:<skip confirm>]
#
# Example:
# bundle exec fastlane complete_code_freeze
# bundle exec fastlane complete_code_freeze skip_confirm:true
#####################################################################################
desc "Creates a new release branch from the current trunk"
lane :complete_code_freeze do | options |
android_completecodefreeze_prechecks(options)
localize_libs()
send_strings_for_translation()
new_version = android_get_app_version()
trigger_release_build(branch_to_build: "release/#{new_version}")
end
#####################################################################################
# update_appstore_strings
# -----------------------------------------------------------------------------------
# This lane gets the data from the txt files in the WooCommerce/metadata/ folder
# and updates the .pot file that is then picked by GlotPress for translations.
# -----------------------------------------------------------------------------------
# Usage:
# fastlane update_appstore_strings version:<version>
#
# Example:
# fastlane update_appstore_strings version:1.1
#####################################################################################
desc "Updates the PlayStoreStrings.pot file"
lane :update_appstore_strings do |options|
ensure_git_status_clean
files = {
release_note: RELEASE_NOTES_PATH,
play_store_promo: File.join(METADATA_DIR_PATH, 'short_description.txt'),
play_store_desc: File.join(METADATA_DIR_PATH, 'full_description.txt'),
play_store_app_title: File.join(METADATA_DIR_PATH, 'title.txt'),
play_store_screenshot_1: File.join(METADATA_DIR_PATH, 'promo_screenshot_1.txt'),
play_store_screenshot_1_b: File.join(METADATA_DIR_PATH, 'promo_screenshot_1_b.txt'),
play_store_screenshot_2: File.join(METADATA_DIR_PATH, 'promo_screenshot_2.txt'),
play_store_screenshot_3: File.join(METADATA_DIR_PATH, 'promo_screenshot_3.txt'),
play_store_screenshot_4: File.join(METADATA_DIR_PATH, 'promo_screenshot_4.txt'),
play_store_screenshot_5: File.join(METADATA_DIR_PATH, 'promo_screenshot_5.txt'),
play_store_screenshot_6: File.join(METADATA_DIR_PATH, 'promo_screenshot_6.txt'),
play_store_screenshot_7: File.join(METADATA_DIR_PATH, 'promo_screenshot_7.txt'),
play_store_screenshot_8: File.join(METADATA_DIR_PATH, 'promo_screenshot_8.txt')
}
po_path = File.join(METADATA_DIR_PATH, 'PlayStoreStrings.pot')
an_update_metadata_source(
po_file_path: po_path,
source_files: files,
release_version: options[:version]
)
git_add(path: po_path)
git_commit(
path: po_path,
message: "Update `PlayStoreStrings.po` for #{options[:version]}",
allow_nothing_to_commit: true
)
end
#####################################################################################
# new_beta_release
# -----------------------------------------------------------------------------------
# This lane updates the release branch for a new beta release. It will update the
# current release branch by default. If you want to update a different branch
# (i.e. hotfix branch) pass the related version with the 'base_version' param
# (example: base_version:10.6.1 will work on the 10.6.1 branch)
# -----------------------------------------------------------------------------------
# Usage:
# bundle exec fastlane new_beta_release [skip_confirm:<skip confirm>] [base_version:<version>]
#
# Example:
# bundle exec fastlane new_beta_release
# bundle exec fastlane new_beta_release skip_confirm:true
# bundle exec fastlane new_beta_release base_version:10.6.1
#####################################################################################
desc "Updates a release branch for a new beta release"
lane :new_beta_release do | options |
android_betabuild_prechecks(options)
android_bump_version_beta()
new_version = android_get_app_version()
trigger_release_build(branch_to_build: "release/#{new_version}")
end
#####################################################################################
# new_hotfix_release
# -----------------------------------------------------------------------------------
# This lane updates the release branch for a new hotfix release.
# -----------------------------------------------------------------------------------
# Usage:
# bundle exec fastlane new_hotfix_release [skip_confirm:<skip confirm>] [version_name:<x.y.z>] [version_code:<nnnn>]
#
# Example:
# bundle exec fastlane new_hotfix_release version_name:10.6.1 version_code:1070
#####################################################################################
desc "Prepare a new hotfix branch cut from the previous tag, and bump the version"
lane :new_hotfix_release do |options|
hotfix_version = options[:version_name] || UI.input('Version number for the new hotfix?')
previous_tag = android_hotfix_prechecks(version_name: hotfix_version, skip_confirm: options[:skip_confirm])
android_bump_version_hotfix(previous_version_name: previous_tag, version_name: hotfix_version, version_code: options[:version_code])
end
#####################################################################################
# finalize_hotfix_release
# -----------------------------------------------------------------------------------
# This lane finalizes the hotfix branch.
# -----------------------------------------------------------------------------------
# Usage:
# bundle exec fastlane finalize_hotfix_release
#
# Example:
# bundle exec fastlane finalize_hotfix_release
desc "Finalizes a hotfix release by triggering a release build"
lane :finalize_hotfix_release do |options|
new_version = android_get_app_version()
trigger_release_build(branch_to_build: "release/#{new_version}")
end
#####################################################################################
# download_translations
# -----------------------------------------------------------------------------------
# This lane downloads the string translations from GlotPress
# -----------------------------------------------------------------------------------
# Usage:
# bundle exec fastlane download_translations
#####################################################################################
desc "Download the latest app translations from GlotPress and update the strings.xml files accordingly"
lane :download_translations do |options|
android_download_translations(
res_dir: File.join(ENV['PROJECT_NAME'], 'src', 'main', 'res'),
glotpress_url: GLOTPRESS_APP_STRINGS_PROJECT_URL,
locales: SUPPORTED_LOCALES,
lint_task: 'lintVanillaRelease'
)
end
#####################################################################################
# finalize_release
# -----------------------------------------------------------------------------------
# This lane finalize a release: updates store metadata and runs the release checks
# -----------------------------------------------------------------------------------
# Usage:
# bundle exec fastlane finalize_release [skip_confirm:<skip confirm>]
#
# Example:
# bundle exec fastlane finalize_release
# bundle exec fastlane finalize_release skip_confirm:true
#####################################################################################
desc "Updates store metadata and runs the release checks"
lane :finalize_release do | options |
UI.user_error!('Please use `finalize_hotfix_release` lane for hotfixes') if android_current_branch_is_hotfix
android_finalize_prechecks(options)
configure_apply(force: is_ci)
UI.message('Checking app strings translation status...')
check_translation_progress(
glotpress_url: GLOTPRESS_APP_STRINGS_PROJECT_URL,
abort_on_violations: false
)
UI.message("Checking release notes strings translation status...")
check_translation_progress(
glotpress_url: GLOTPRESS_PLAYSTORE_METADATA_PROJECT_URL,
abort_on_violations: false
)
download_translations(options)
android_bump_version_final_release()
version = android_get_release_version()
download_metadata_strings(version: version["name"], build_number: version["code"])
# Wrap up
removebranchprotection(repository:GHHELPER_REPO, branch: "release/#{version["name"]}")
setfrozentag(repository:GHHELPER_REPO, milestone: version["name"], freeze: false)
create_new_milestone(repository:GHHELPER_REPO)
close_milestone(repository:GHHELPER_REPO, milestone: version["name"])
trigger_release_build(branch_to_build: "release/#{version["name"]}")
end
#####################################################################################
# build_and_upload_google_play
# -----------------------------------------------------------------------------------
# This lane builds the app for Google Play, and will correctly select which build
# should be produced based on the build number.
# -----------------------------------------------------------------------------------
# Usage:
# bundle exec fastlane build_and_upload_google_play
#
# Example:
# bundle exec fastlane build_and_upload_google_play
#####################################################################################
desc "Builds and uploads a release to Google Play"
lane :build_and_upload_google_play do | options |
if is_beta_version(android_get_release_version)
build_and_upload_beta(
skip_confirm: is_ci,
skip_prechecks: true,
create_release: true
)
else
build_and_upload_release(
skip_confirm: is_ci,
skip_prechecks: true,
create_release: true
)
end
end
#####################################################################################
# build_and_upload_release
# -----------------------------------------------------------------------------------
# This lane builds the final release of the app and uploads it
# -----------------------------------------------------------------------------------
# Usage:
# bundle exec fastlane build_and_upload_release [skip_confirm:<skip confirm>] [create_release:<Create release on GH> ]
#
# Example:
# bundle exec fastlane build_and_upload_release
# bundle exec fastlane build_and_upload_release skip_confirm:true
# bundle exec fastlane build_and_upload_release create_release:true
#####################################################################################
desc "Builds and uploads release for distribution"
lane :build_and_upload_release do | options |
android_build_prechecks(skip_confirm: options[:skip_confirm],
alpha: false,
beta: false,
final: true)
android_build_preflight() unless options[:skip_prechecks]
# Create the file names
version = android_get_release_version()
build_bundle(version: version, flavor:"Vanilla")
aab_file_path = File.join(PROJECT_ROOT_FOLDER, "artifacts", aab_file_name(version))
UI.error("Unable to find a build artifact at #{aab_file_path}") unless File.exist? aab_file_path
upload_to_play_store(
package_name: 'com.woocommerce.android',
aab: aab_file_path,
track: 'production',
release_status: 'draft',
skip_upload_metadata: true,
skip_upload_changelogs: true,
skip_upload_images: true,
skip_upload_screenshots: true,
json_key: UPLOAD_TO_PLAY_STORE_JSON_KEY
)
create_gh_release(version: version) if options[:create_release]
end
#####################################################################################
# build_and_upload_beta
# -----------------------------------------------------------------------------------
# This lane builds the app for external beta distribution, and uploads the build
# to the beta channel (but does not release it).
# -----------------------------------------------------------------------------------
# Usage:
# bundle exec fastlane build_and_upload_beta [skip_confirm:<skip confirm>] [create_release:<Create release on GH> ]
#
# Example:
# bundle exec fastlane build_and_upload_beta
# bundle exec fastlane build_and_upload_beta skip_confirm:true
# bundle exec fastlane build_and_upload_beta create_release:true
#####################################################################################
desc "Builds and uploads a new beta build to Google Play (without releasing it)"
lane :build_and_upload_beta do | options |
android_build_prechecks(skip_confirm: options[:skip_confirm], alpha: false, beta: true, final: false) unless (options[:skip_prechecks])
android_build_preflight() unless options[:skip_prechecks]
# Create the file names
version = android_get_release_version()
build_bundle(version: version, flavor:"Vanilla")
aab_file_path = File.join(PROJECT_ROOT_FOLDER, "artifacts", aab_file_name(version))
UI.error("Unable to find a build artifact at #{aab_file_path}") unless File.exist? aab_file_path
upload_to_play_store(
package_name: 'com.woocommerce.android',
aab: aab_file_path,
track: 'beta',
release_status: 'draft',
skip_upload_metadata: true,
skip_upload_changelogs: true,
skip_upload_images: true,
skip_upload_screenshots: true,
json_key: UPLOAD_TO_PLAY_STORE_JSON_KEY
)
create_gh_release(version: version, prerelease: true) if options[:create_release]
end
#####################################################################################
# trigger_release_build
# -----------------------------------------------------------------------------------
# This lane triggers a stable release build on CI
# -----------------------------------------------------------------------------------
# Usage:
# bundle exec fastlane trigger_release_build [branch_to_build:<branch_name>]
#
#####################################################################################
desc "Tell Buildkite to trigger a release build"
lane :trigger_release_build do | options |
buildkite_trigger_build(
buildkite_organization: 'automattic',
buildkite_pipeline: 'woocommerce-android',
branch: options[:branch_to_build] || git_branch,
pipeline_file: 'release-builds.yml'
)
end
#####################################################################################
# localize_libs
# -----------------------------------------------------------------------------------
# This lane gets the data from the dependencies and updates the main strings.xml file
# -----------------------------------------------------------------------------------
# Usage:
# fastlane localize_libs
#
# Example:
# fastlane localize_libs
#####################################################################################
desc "Merge libraries strings files into the main app one"
lane :localize_libs do | options |
REMOTE_LIBRARIES_STRINGS_PATHS.each do | lib |
download_path = android_download_file_by_version(
library_name: lib[:name],
import_key: lib[:import_key],
repository: lib[:repository],
file_path: lib[:strings_file_path]
)
if download_path.nil?
error_message = <<~ERROR
Can't download strings file for #{lib[:name]}.
Strings for this library won't get translated.
Do you want to continue anyway?
ERROR
UI.user_error! "Abort." unless UI.confirm(error_message)
else
UI.message("Strings.xml file for #{lib[:name]} downloaded to #{download_path}.")
lib_to_merge = [{
library: lib[:name],
strings_path: download_path,
exclusions: lib[:exclusions]
}]
an_localize_libs(app_strings_path: MAIN_STRINGS_PATH, libs_strings_path: lib_to_merge)
File.delete(download_path) if File.exist?(download_path)
end
end
is_repo_clean = ("git status --porcelain").empty?
unless is_repo_clean then
commit_strings(options)
end
end
#####################################################################################
# download_metadata_string
# -----------------------------------------------------------------------------------
# This lane downloads the translated metadata (release notes,
# app store strings, title, etc.) from GlotPress and updates the local files
# -----------------------------------------------------------------------------------
# Usage:
# fastlane download_metadata_string build_number:<build_number> version:<version>
#
# Example:
# fastlane download_metadata_string build_number:573 version:10.3
#####################################################################################
desc "Downloads translated metadata from GlotPress"
lane :download_metadata_strings do |options|
values = options[:version].split('.')
files = {
"release_note_#{values[0].to_s.rjust(2, "0")}#{values[1]}" => { desc: "changelogs/#{options[:build_number]}.txt", max_size: 0 },
play_store_promo: { desc: "short_description.txt", max_size: 80 },
play_store_desc: { desc: "full_description.txt", max_size: 0 },
play_store_app_title: { desc: "title.txt", max_size: 50 }
}
delete_old_changelogs(build: options[:build_number])
# Notice that this is a different path from `METADATA_DIR_PATH`.
# This is the path for the Fastlane metadata, i.e. the ones for the Play Store, hence the `Dir.pwd`.
# `METADATA_DIR_PATH` is the path of the metadata the app uses at runtime.
download_path = File.join(Dir.pwd, 'metadata', 'android')
gp_downloadmetadata(
project_url: GLOTPRESS_PLAYSTORE_METADATA_PROJECT_URL,
target_files: files,
locales: SUPPORTED_LOCALES.map { |hsh| [hsh[:glotpress], hsh[:google_play]] },
source_locale: "en-US",
download_path: download_path
)
android_create_xml_release_notes(
download_path: download_path,
build_number: options[:build_number].to_s,
locales: SUPPORTED_LOCALES.map { |hsh| [hsh[:glotpress], hsh[:google_play]] }
)
add_us_release_notes(
release_notes_path: File.join(download_path, 'release_notes.xml'),
version_name: options[:version]
)
# We need to explicitly call `git_add`, despite the path being passed to `git_commit` as well.
# That's because we might have new files, that the commit command would otherwise miss.
git_add(path: download_path)
git_commit(
path: download_path,
message: "Update metadata translations for #{options[:version]}",
allow_nothing_to_commit: true
)
push_to_git_remote_with_confirmation
end
########################################################################
# Helper Lanes
########################################################################
private_lane :commit_strings do | options |
if (options[:auto_commit]) then
sh("cd .. && git add #{MAIN_STRINGS_PATH}")
sh("git commit -m 'Update strings for translation'")
sh("git push origin HEAD")
else
UI.important("Your #{MAIN_STRINGS_PATH} has changed.")
UI.input("Please, review the changes, commit them and press return to continue.")
end
end
#####################################################################################
# build_bundle
# -----------------------------------------------------------------------------------
# This lane builds an app bundle
# -----------------------------------------------------------------------------------
# Usage:
# bundle exec fastlane build_bundle [skip_confirm:<skip confirm>]
#####################################################################################
desc "Builds an app bundle"
lane :build_bundle do | options |
# Create the file names
version = options[:version]
name = aab_file_name(version)
aab_file = "WooCommerce-vanilla-release.aab"
output_dir = "WooCommerce/build/outputs/bundle/"
build_dir = "artifacts/"
# Build
Dir.chdir(".") do
UI.message("Cleaning branch...")
gradle(task: "clean")
UI.message("Running lint...")
gradle(task: "lint", flavor: options[:flavor], build_type: "Release")
UI.message("Building #{version["name"]} / #{version["code"]} - #{aab_file}...")
gradle(task: "bundle", flavor: options[:flavor], build_type: "Release")
end
Dir.chdir("..") do
sh("mkdir -p #{build_dir} && cp -v #{output_dir}#{options[:flavor].downcase}Release/#{aab_file} #{build_dir}#{name}")
UI.message("Bundle ready: #{name}")
end
"#{build_dir}#{name}"
end
#####################################################################################
# screenshots
# -----------------------------------------------------------------------------------
# This lane creates screenshots for light and dark modes
# -----------------------------------------------------------------------------------
# Usage:
# fastlane take_screenshots
#
# Example:
# fastlane take_screenshots
#####################################################################################
desc "Create raw screenshots"
lane :take_screenshots do |options|
# Build the app and test targets
gradle(task: "assembleVanillaDebug assembleVanillaDebugAndroidTest")
if options[:locales]
locales = options[:locales].split(',')
else
locales = SUPPORTED_LOCALES.
# Depending on how automated this is, possibly on whether we wipe the
# emulator before running or not, the zh-CN locale might break due to
# Pinwin Keyboard wanting contacts access. If that's the case, you can
# skip it by uncommeting the following line.
#reject { |locale| locale[:glotpress] == 'zh-cn' }.
map { |locale| locale[:google_play] }
end
UI.message("Attempting screenshots for locales: #{locales}")
screenshot_options = {
output_directory: SCREENSHOT_DIRECTORY,
app_package_name: "com.woocommerce.android",
app_apk_path: "WooCommerce/build/outputs/apk/vanilla/debug/WooCommerce-vanilla-debug.apk",
tests_apk_path: "WooCommerce/build/outputs/apk/androidTest/vanilla/debug/WooCommerce-vanilla-debug-androidTest.apk",
use_tests_in_classes: "com.woocommerce.android.screenshots.ScreenshotTest",
reinstall_app: false,
# By default, don't clear previous because we differentiate between light
# and dark mode
clear_previous_screenshots: options.fetch(:clear_previous_screenshots, false),
# Needs to be root to save screenshots consistently
use_adb_root: true,
locales: locales,
use_timestamp_suffix: false,
test_instrumentation_runner: "com.woocommerce.android.WooCommerceTestRunner",
# Don't care about the .html summary
skip_open_summary: true
}
UI.message("Taking screenshots for Dark theme...")
screengrab(
screenshot_options.merge(
{
launch_arguments: ["theme dark"]
}
)
)
UI.message("Taking screenshots for Light theme...")
screengrab(
screenshot_options.merge(
{
launch_arguments: ["theme light"]
}
)
)
end
#####################################################################################
# build_apk
# -----------------------------------------------------------------------------------
# This lane builds an apk
# -----------------------------------------------------------------------------------
# Usage:
# bundle exec fastlane build_apk
#####################################################################################
desc "Builds an APK"
lane :build_and_upload_installable_build do | options |
UI.user_error!("'BUILDKITE_ARTIFACTS_S3_BUCKET' must be defined as an environment variable.") unless ENV['BUILDKITE_ARTIFACTS_S3_BUCKET']
gradle(
task: "assemble",
flavor: "Jalapeno",
build_type: "Debug"
)
upload_path = upload_to_s3(
bucket: 'a8c-apps-public-artifacts',
key: "woocommerce-installable-build-#{generate_installable_build_number}.apk",
file: lane_context[SharedValues::GRADLE_APK_OUTPUT_PATH]
)
install_url = "#{INSTALLABLE_BUILD_DOMAIN}/#{upload_path}"
qr_code_url = "https://chart.googleapis.com/chart?chs=500x500&cht=qr&chl=#{URI::encode( install_url )}&choe=UTF-8"
comment_body = "You can test the changes on this Pull Request by <a href='#{install_url}'>downloading an installable build</a>, or scanning this QR code:<br><a href='#{install_url}'><img src='#{qr_code_url}' width='250' height='250' /></a>"
comment_on_pr(
project: 'woocommerce/woocommerce-android',
pr_number: Integer(ENV['BUILDKITE_PULL_REQUEST']),
reuse_identifier: 'installable-build-link',
body: comment_body
) unless ENV['BUILDKITE_PULL_REQUEST'].nil?
end
#####################################################################################
# Private lanes
#####################################################################################
private_lane :delete_old_changelogs do | options |
Dir.glob("./metadata/android/*/").each do | folder |
Dir["#{folder}changelogs/*"].each do | file |
File.delete(file) if Integer(File.basename(file, ".*")) < Integer(options[:build]) rescue puts "Cannot delete file #{file}"
end
end
end
private_lane :add_us_release_notes do | options |
en_release_notes_path = RELEASE_NOTES_PATH
File.open(options[:release_notes_path], "a") { |f|
f.puts("<en-US>")
f.puts("#{options[:version_name]}:")
f.puts(File.open(en_release_notes_path).read)
f.puts("</en-US>")
}
end
# Creates a new GitHub Release for the given version
#
# @param [Hash<String>] version The version to create. Expects keys "name" and "code"
# @param [Bool] prerelease If true, the GitHub Release will have the prerelease flag
#
private_lane :create_gh_release do | options |
version = options[:version]
prerelease = options[:prerelease] || false
# APKs built on CI are not signed with master key, which means Google Sign-In won't work with those.
# So don't attach them to the release, as this ends up being confusing for beta-testers.
apk_file_path = File.join(PROJECT_ROOT_FOLDER, 'artifacts', universal_apk_name(version)) unless is_ci
aab_file_path = File.join(PROJECT_ROOT_FOLDER, 'artifacts', aab_file_name(version))
release_assets = [apk_file_path, aab_file_path].compact
create_release(
repository: GHHELPER_REPO,
version: version["name"],
release_notes_file_path: RELEASE_NOTES_PATH,
prerelease: prerelease,
release_assets: release_assets.join(',')
)
end
private_lane :send_strings_for_translation do | options |
sh("cd .. && mkdir -p #{FROZEN_STRINGS_DIR_PATH} && cp #{MAIN_STRINGS_PATH} #{FROZEN_STRINGS_DIR_PATH} && git add #{FROZEN_STRINGS_DIR_PATH}strings.xml")
sh("git diff-index --quiet HEAD || git commit -m \"Send strings to translation.\"")
sh("git push origin HEAD")
end
#####################################################################################
# Utils
#####################################################################################
def aab_file_name(version)
"wcandroid-#{version["name"]}.aab"
end
def universal_apk_name(version)
"wcandroid-#{version["name"]}-universal.apk"
end
def is_beta_version(version)
version['name'].include? "-rc-"
end
# This function is Buildkite-specific
def generate_installable_build_number
if ENV['BUILDKITE']
commit = ENV['BUILDKITE_COMMIT'][0,7]
branch = ENV['BUILDKITE_BRANCH'].parameterize
pr_num = ENV['BUILDKITE_PULL_REQUEST']
return pr_num == 'false' ? "#{branch}-#{commit}" : "pr#{pr_num}-#{commit}"
else
repo = Git.open(PROJECT_ROOT_FOLDER)
commit = repo.current_branch.parameterize
branch = repo.revparse('HEAD')[0, 7]
return "#{branch}-#{commit}"
end
end
# Asks the user whether they want to push to the Git remote using `UI.confirm`.
#
# @note It supports an override environment variable flag, `RELEASE_TOOLKIT_SKIP_PUSH_CONFIRM`.
# If set to `false` the user won't be asked for confirmation.
#
def push_to_git_remote_with_confirmation
if ENV.fetch('RELEASE_TOOLKIT_SKIP_PUSH_CONFIRM', false) || UI.confirm('Push changes to remote?')
push_to_git_remote(tags: false)
else
UI.message('Continuing without pushing')
end
end
end