-
Notifications
You must be signed in to change notification settings - Fork 114
/
Fastfile
1498 lines (1261 loc) · 58.9 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
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# frozen_string_literal: true
default_platform(:ios)
fastlane_require 'dotenv'
fastlane_require 'git'
UI.user_error!('Please run fastlane via `bundle exec`') unless FastlaneCore::Helper.bundler?
USER_ENV_FILE_PATH = File.join(Dir.home, '.wcios-env.default')
SECRETS_DIR = File.join(Dir.home, '.configure', 'woocommerce-ios', 'secrets')
PROJECT_ENV_FILE_PATH = File.join(SECRETS_DIR, 'project.env')
GITHUB_REPO = 'woocommerce/woocommerce-ios'
DEFAULT_BRANCH = 'trunk'
# Constants
PROJECT_ROOT_FOLDER = File.dirname(File.expand_path(__dir__))
RESOURCES_FOLDER = File.join(PROJECT_ROOT_FOLDER, 'WooCommerce', 'Resources')
PUBLIC_CONFIG_FILE = File.join(PROJECT_ROOT_FOLDER, 'config', 'Version.Public.xcconfig')
RELEASE_NOTES_PATH = File.join(RESOURCES_FOLDER, 'release_notes.txt')
RELEASE_NOTES_SOURCE_PATH = File.join(PROJECT_ROOT_FOLDER, 'RELEASE-NOTES.txt')
FASTLANE_DIR = File.join(PROJECT_ROOT_FOLDER, 'fastlane')
DERIVED_DATA_DIR = File.join(FASTLANE_DIR, 'DerivedData')
SCREENSHOTS_DIR = File.join(FASTLANE_DIR, 'screenshots')
FASTLANE_METADATA_FOLDER = File.join(FASTLANE_DIR, 'metadata')
WORKSPACE_PATH = File.join(PROJECT_ROOT_FOLDER, 'WooCommerce.xcworkspace')
IOS_LOCALES = %w[ar de-DE en-US es-ES fr-FR he id it ja ko nl-NL pt-BR ru sv tr zh-Hans zh-Hant].freeze
SIMULATOR_VERSION = '15.5' # For screenshots
SCREENSHOTS_SCHEME = 'WooCommerceScreenshots'
SCREENSHOT_DEVICES = [
'iPhone 11 Pro Max',
'iPhone 8 Plus',
'iPad Pro (12.9-inch) (2nd generation)',
'iPad Pro (12.9-inch) (3rd generation)'
].freeze
# Instantiate versioning classes
VERSION_CALCULATOR = Fastlane::Wpmreleasetoolkit::Versioning::MarketingVersionCalculator.new
VERSION_FORMATTER = Fastlane::Wpmreleasetoolkit::Versioning::FourPartVersionFormatter.new
BUILD_CODE_FORMATTER = Fastlane::Wpmreleasetoolkit::Versioning::FourPartBuildCodeFormatter.new
BUILD_CODE_KEY = 'VERSION_LONG'
VERSION_FILE = Fastlane::Wpmreleasetoolkit::Versioning::IOSVersionFile.new(xcconfig_path: PUBLIC_CONFIG_FILE)
APP_STORE_VERSION_BUNDLE_IDENTIFIER = 'com.automattic.woocommerce'
# Registered in our main account, for development and App Store
MAIN_BUNDLE_IDENTIFIERS = [
APP_STORE_VERSION_BUNDLE_IDENTIFIER,
"#{APP_STORE_VERSION_BUNDLE_IDENTIFIER}.storewidgets",
"#{APP_STORE_VERSION_BUNDLE_IDENTIFIER}.notificationcontentextension",
"#{APP_STORE_VERSION_BUNDLE_IDENTIFIER}.watchkitapp",
"#{APP_STORE_VERSION_BUNDLE_IDENTIFIER}.watchkitapp.widgets"
].freeze
ALPHA_VERSION_BUNDLE_IDENTIFIER = 'com.automattic.alpha.woocommerce'
# Registered in our Enterprise account, for App Center / Prototype Builds
ALPHA_BUNDLE_IDENTIFIERS = MAIN_BUNDLE_IDENTIFIERS.map do |id|
id.gsub(APP_STORE_VERSION_BUNDLE_IDENTIFIER, ALPHA_VERSION_BUNDLE_IDENTIFIER)
end.freeze
# Shared options to use when invoking `gym` / `build_app`.
#
# - `manageAppVersionAndBuildNumber: false` prevents `xcodebuild` from bumping
# the build number when extracting an archive into an IPA file. We want to
# use the build number we set!
COMMON_EXPORT_OPTIONS = { manageAppVersionAndBuildNumber: false }.freeze
TEST_SCHEME = 'WooCommerce'
CONCURRENT_SIMULATORS = 2
# List of `.strings` files manually maintained by developers (as opposed to being automatically extracted from the code)
# which we will merge into the main `Localizable.strings` file imported by GlotPress, then extract back once we download the translations.
#
# Each `.strings` file to be merged/extracted is associated with a prefix to add to the keys, used to avoid conflicts and differentiate the source of the copies.
#
# See calls to `ios_merge_strings_files` and `ios_extract_keys_from_strings_files` for usage.
#
# Note that, yes, we currently have only one file, but it's still worth defining this constant because it's used across more than one lane, as described above.
#
MANUALLY_MAINTAINED_STRINGS_FILES = {
File.join(RESOURCES_FOLDER, 'en.lproj', 'InfoPlist.strings') => 'infoplist.'
}.freeze
# URL of the GlotPress project containing the strings used in the app
GLOTPRESS_APP_STRINGS_PROJECT_URL = 'https://translate.wordpress.com/projects/woocommerce/woocommerce-ios/'
# URL of the GlotPress project containing App Store Connect metadata
GLOTPRESS_APP_STORE_METADATA_PROJECT_URL = 'https://translate.wordpress.com/projects/woocommerce/woocommerce-ios/release-notes/'
# List of locales used for the app strings (GlotPress code => `*.lproj` folder name`)
#
# TODO: Replace with `LocaleHelper` once provided by release toolkit (https://github.com/wordpress-mobile/release-toolkit/pull/296)
GLOTPRESS_TO_LPROJ_APP_LOCALE_CODES = {
'ar' => 'ar', # Arabic
'de' => 'de', # German
'es' => 'es', # Spanish
'fr' => 'fr', # French
'he' => 'he', # Hebrew
'id' => 'id', # Indonesian
'it' => 'it', # Italian
'ja' => 'ja', # Japanese
'ko' => 'ko', # Korean
'nl' => 'nl', # Dutch
'pt-br' => 'pt-BR', # Portuguese (Brazil)
'ru' => 'ru', # Russian
'sv' => 'sv', # Swedish
'tr' => 'tr', # Turkish
'zh-cn' => 'zh-Hans', # Chinese (China)
'zh-tw' => 'zh-Hant' # Chinese (Taiwan)
}.freeze
# Mapping of all locales which can be used for AppStore metadata (Glotpress code => AppStore Connect code)
#
# TODO: Replace with `LocaleHelper` once provided by release toolkit (https://github.com/wordpress-mobile/release-toolkit/pull/296)
GLOTPRESS_TO_ASC_METADATA_LOCALE_CODES = {
'ar' => 'ar-SA',
'de' => 'de-DE',
'es' => 'es-ES',
'fr' => 'fr-FR',
'he' => 'he',
'id' => 'id',
'it' => 'it',
'ja' => 'ja',
'ko' => 'ko',
'nl' => 'nl-NL',
'pt-br' => 'pt-BR',
'ru' => 'ru',
'sv' => 'sv',
'tr' => 'tr',
'zh-cn' => 'zh-Hans',
'zh-tw' => 'zh-Hant'
}.freeze
ASC_KEY_PATH = File.join(SECRETS_DIR, 'app_store_connect_fastlane_api_key.json')
# Use this instead of getting values from ENV directly
# It will throw an error if the requested value is missing
def get_required_env(key)
UI.user_error!("Environment variable '#{key}' is not set. Have you setup #{USER_ENV_FILE_PATH} correctly?") unless ENV.key?(key)
ENV.fetch(key)
end
before_all do |lane|
# Skip these checks/steps for test lane (not needed for testing)
next if lane == :test_without_building
# Check for Release Toolkit updates
check_for_toolkit_updates unless is_ci || ENV['FASTLANE_SKIP_TOOLKIT_UPDATE_CHECK']
# Check that the env files exist
UI.user_error!("~/.wcios-env.default not found: Please copy env/user.env-example to #{USER_ENV_FILE_PATH} and fill in the values") unless is_ci || File.file?(USER_ENV_FILE_PATH)
UI.user_error!('project.env not found: Make sure your configuration is up to date with `rake dependencies`') unless File.file?(PROJECT_ENV_FILE_PATH)
setup_ci
end
platform :ios do
########################################################################
# Environment
########################################################################
Dotenv.load(USER_ENV_FILE_PATH)
Dotenv.load(PROJECT_ENV_FILE_PATH)
########################################################################
# Release Lanes
########################################################################
# This lane executes the steps planned on code freeze, creating a new release branch from the current trunk
#
# @param [Boolean] skip_confirm (default: false) If set, will skip the confirmation prompt before running the rest of the lane
#
# @example Running the lane
# bundle exec fastlane start_code_freeze skip_confirm:true
#
lane :start_code_freeze do |skip_confirm: false|
ensure_git_status_clean
# Check out the up-to-date default branch, the designated starting point for the code freeze
Fastlane::Helper::GitHelper.checkout_and_pull(DEFAULT_BRANCH)
# Checks if internal dependencies are on a stable version
check_pods_references
UI.important <<-MESSAGE
Code Freeze:
• New release branch from #{DEFAULT_BRANCH}: release/#{release_version_next}
• Current release version and build code: #{release_version_current} (#{build_code_current}).
• New release version and build code: #{release_version_next} (#{build_code_code_freeze}).
MESSAGE
UI.user_error!("Terminating as requested. Don't forget to run the remainder of this automation manually.") unless skip_confirm || UI.confirm('Do you want to continue?')
# Create the release branch
new_release_branch = "release/#{release_version_next}"
ensure_branch_does_not_exist!(new_release_branch)
UI.message('Creating release branch...')
Fastlane::Helper::GitHelper.create_branch(new_release_branch, from: DEFAULT_BRANCH)
UI.success("Done! New release branch is: #{git_branch}")
# Bump the release version and build code and write it to the `xcconfig` file
UI.message('Bumping release version and build code...')
VERSION_FILE.write(
version_short: release_version_next,
version_long: build_code_code_freeze
)
commit_version_bump
UI.success("Done! New Release Version: #{release_version_current}. New Build Code: #{build_code_current}")
new_version = release_version_current
extract_release_notes_for_version(
version: new_version,
release_notes_file_path: RELEASE_NOTES_SOURCE_PATH,
extracted_notes_file_path: RELEASE_NOTES_PATH
)
ios_update_release_notes(
new_version: new_version,
release_notes_file_path: RELEASE_NOTES_SOURCE_PATH
)
UI.important('Pushing changes to remote and configuring the release on GitHub')
UI.user_error!("Terminating as requested. Don't forget to run the remainder of this automation manually.") unless skip_confirm || UI.confirm('Do you want to continue?')
push_to_git_remote(tags: false)
# Protect release/* branch
copy_branch_protection(
repository: GITHUB_REPO,
from_branch: DEFAULT_BRANCH,
to_branch: "release/#{new_version}"
)
begin
# Move PRs to next milestone
moved_prs = update_assigned_milestone(
repository: GITHUB_REPO,
from_milestone: new_version,
to_milestone: release_version_next,
comment: "Version `#{new_version}` has now entered code-freeze, so the milestone of this PR has been updated to `#{release_version_next}`."
)
# Add ❄️ marker to milestone title to indicate we entered code-freeze
set_milestone_frozen_marker(
repository: GITHUB_REPO,
milestone: new_version
)
rescue StandardError => e
moved_prs = []
report_milestone_error(error_title: "Error freezing milestone `#{new_version}`: #{e.message}")
end
UI.message("Moved the following PRs to milestone #{release_version_next}: #{moved_prs.join(', ')}")
# Annotate the build with the moved PRs
moved_prs_info = if moved_prs.empty?
"👍 No open PR were targeting `#{new_version}` at the time of code-freeze"
else
"#{moved_prs.count} PRs targeting `#{new_version}` were still open and thus moved to `#{release_version_next}`:\n" \
+ moved_prs.map { |pr_num| "[##{pr_num}](https://github.com/#{GITHUB_REPO}/pull/#{pr_num})" }.join(', ')
end
buildkite_annotate(style: moved_prs.empty? ? 'success' : 'warning', context: 'start-code-freeze', message: moved_prs_info) if is_ci
end
#####################################################################################
# complete_code_freeze
# -----------------------------------------------------------------------------------
# This lane executes the initial 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|
ensure_git_status_clean
ensure_git_branch_is_release_branch!
UI.important("Completing code freeze for: #{release_version_current}")
unless options[:skip_confirm] || UI.confirm('Do you want to continue?')
UI.user_error!("Terminating as requested. Don't forget to run the remainder of this automation manually.")
end
update_app_store_strings
generate_strings_file_for_glotpress
push_to_git_remote(tags: false)
trigger_beta_build(branch_to_build: "release/#{release_version_current}")
create_backmerge_pr
end
# Updates the `AppStoreStrings.pot` file with the latest content from the `release_notes.txt` files and the other text sources.
#
# @option [String] version The current `x.y[.z]` version of the app. Optional. Used to derive the `vx.y[.z]-whats-new` key to use in the `.pot` file.
#
desc 'Updates the AppStoreStrings.pot file with the latest data'
lane :update_app_store_strings do |options|
source_metadata_folder = File.join(FASTLANE_DIR, 'appstoreres', 'metadata', 'source')
files = {
whats_new: RELEASE_NOTES_PATH,
app_store_subtitle: File.join(source_metadata_folder, 'subtitle.txt'),
app_store_desc: File.join(source_metadata_folder, 'description.txt'),
app_store_keywords: File.join(source_metadata_folder, 'keywords.txt'),
'app_store_promo_text' => File.join(source_metadata_folder, 'app_store_promo_text.txt'),
'app_store_screenshot-1' => File.join(source_metadata_folder, 'promo_screenshot_1.txt'),
'app_store_screenshot-2' => File.join(source_metadata_folder, 'promo_screenshot_2.txt'),
'app_store_screenshot-3' => File.join(source_metadata_folder, 'promo_screenshot_3.txt'),
'app_store_screenshot-4' => File.join(source_metadata_folder, 'promo_screenshot_4.txt'),
'app_store_screenshot-5' => File.join(source_metadata_folder, 'promo_screenshot_5.txt')
}
ios_update_metadata_source(
po_file_path: File.join(RESOURCES_FOLDER, 'AppStoreStrings.pot'),
source_files: files,
release_version: options.fetch(:version, release_version_current)
)
end
#####################################################################################
# new_beta_release
# -----------------------------------------------------------------------------------
# This lane updates the release branch for a new beta release. It will update the
# current release branch by default.
# -----------------------------------------------------------------------------------
# Usage:
# bundle exec fastlane new_beta_release [skip_confirm:<skip confirm>]
#
# Example:
# bundle exec fastlane new_beta_release
# bundle exec fastlane new_beta_release skip_confirm:true
#####################################################################################
desc 'Updates a release branch for a new beta release'
lane :new_beta_release do |options|
ensure_git_status_clean
ensure_git_branch_is_release_branch!
UI.important <<-MESSAGE
Current build code: #{build_code_current}
New build code: #{build_code_next}
MESSAGE
unless options[:skip_confirm] || UI.confirm('Do you want to continue?')
UI.user_error!("Terminating as requested. Don't forget to run the remainder of this automation manually.")
end
# Download the latest translations from GlotPress
download_localized_strings_and_metadata_from_glotpress
lint_localizations
# Bump the build code
UI.message('Bumping build code...')
ensure_git_branch_is_release_branch!
VERSION_FILE.write(version_long: build_code_next)
commit_version_bump
UI.success("Done! New Build Code: #{build_code_current}")
UI.important('Pushing changes to remote and triggering the beta build')
unless options[:skip_confirm] || UI.confirm('Do you want to continue?')
UI.user_error!("Terminating as requested. Don't forget to run the remainder of this automation manually.")
end
push_to_git_remote(tags: false)
trigger_beta_build(branch_to_build: "release/#{release_version_current}")
create_backmerge_pr
end
#####################################################################################
# new_hotfix_release
# -----------------------------------------------------------------------------------
# This lane creates the release branch for a new hotfix release.
# -----------------------------------------------------------------------------------
# Usage:
# bundle exec fastlane new_hotfix_release [skip_confirm:<skip confirm>] [version:<version>]
#
# Example:
# bundle exec fastlane new_hotfix_release version:10.6.1
# bundle exec fastlane new_hotfix_release skip_confirm:true version:10.6.1
#####################################################################################
desc 'Creates a new hotfix branch for the given version:x.y.z. The branch will be cut from the tag x.y of the previous release'
lane :new_hotfix_release do |options|
# Verify that there's nothing in progress in the working copy
ensure_git_status_clean
new_version = options[:version] || UI.input('Version number for the new hotfix?')
# Parse the provided version into an AppVersion object
parsed_version = VERSION_FORMATTER.parse(new_version)
build_code_hotfix = BUILD_CODE_FORMATTER.build_code(version: parsed_version)
previous_version = VERSION_FORMATTER.release_version(VERSION_CALCULATOR.previous_patch_version(version: parsed_version))
# Check versions
UI.important <<-MESSAGE
New hotfix version: #{new_version}
New build code: #{build_code_hotfix}
Branching from tag: #{previous_version}
MESSAGE
unless options[:skip_confirm] || UI.confirm('Do you want to continue?')
UI.user_error!("Terminating as requested. Don't forget to run the remainder of this automation manually.")
end
# Check tags
UI.user_error!("Version #{new_version} already exists! Abort!") if git_tag_exists(tag: new_version)
UI.user_error!("Version #{previous_version} is not tagged! A hotfix branch cannot be created.") unless git_tag_exists(tag: previous_version)
# Create the hotfix branch
UI.message('Creating hotfix branch...')
Fastlane::Helper::GitHelper.create_branch("release/#{new_version}", from: previous_version)
UI.success("Done! New hotfix branch is: #{git_branch}")
# Bump the hotfix version and build code and write it to the `xcconfig` file
UI.message('Bumping hotfix version and build code...')
VERSION_FILE.write(
version_short: new_version,
version_long: build_code_hotfix
)
commit_version_bump
# Push the newly created hotfix branch
push_to_git_remote(tags: false)
UI.success("Done! New Release Version: #{release_version_current}. New Build Code: #{build_code_current}")
end
# This lane finalizes the hotfix branch, triggering a release build.
#
# @param [Boolean] skip_confirm (default: false) If set, will skip the confirmation prompt before running the rest of the lane
#
# @example Running the lane
# bundle exec fastlane finalize_hotfix_release skip_confirm:true
#
lane :finalize_hotfix_release do |skip_confirm: false|
ensure_git_branch_is_release_branch!
ensure_git_status_clean
hotfix_version = release_version_current
UI.important("Triggering hotfix build for version: #{hotfix_version}")
UI.user_error!("Terminating as requested. Don't forget to run the remainder of this automation manually.") unless skip_confirm || UI.confirm('Do you want to continue?')
trigger_release_build(branch_to_build: "release/#{hotfix_version}")
create_backmerge_pr
# Close hotfix milestone
begin
close_milestone(
repository: GITHUB_REPO,
milestone: hotfix_version
)
rescue StandardError => e
report_milestone_error(error_title: "Error closing milestone `#{hotfix_version}`: #{e.message}")
end
end
#####################################################################################
# finalize_release
# -----------------------------------------------------------------------------------
# This lane finalize a release: updates store metadata, bump final version number,
# remove branch protection and close milestone, then trigger the final release on CI
# -----------------------------------------------------------------------------------
# Usage:
# bundle exec fastlane finalize_release [skip_confirm:<skip confirm>] [version:<version>]
#
# Example:
# bundle exec fastlane finalize_release
# bundle exec fastlane finalize_release skip_confirm:true
#####################################################################################
desc 'Trigger the final release build on CI'
lane :finalize_release do |skip_confirm: false|
UI.user_error!('To finalize a hotfix, please use the `finalize_hotfix_release` lane instead') if release_is_hotfix?
ensure_git_status_clean
ensure_git_branch_is_release_branch!
UI.important("Finalizing release: #{release_version_current}")
UI.user_error!("Terminating as requested. Don't forget to run the remainder of this automation manually.") unless skip_confirm || UI.confirm('Do you want to continue?')
# Don't check translation coverage in CI
check_translation_progress_all unless is_ci
download_localized_strings_and_metadata_from_glotpress
lint_localizations
# Bump the build code
UI.message('Bumping build code...')
VERSION_FILE.write(version_long: build_code_next)
commit_version_bump
UI.success("Done! New Build Code: #{build_code_current}")
# Start the build
UI.important('Pushing changes to remote and triggering the release build')
UI.user_error!("Terminating as requested. Don't forget to run the remainder of this automation manually.") unless skip_confirm || UI.confirm('Do you want to continue?')
push_to_git_remote(tags: false)
version = release_version_current
trigger_release_build(branch_to_build: "release/#{version}")
create_backmerge_pr
remove_branch_protection(
repository: GITHUB_REPO,
branch: "release/#{version}"
)
# Close milestone
begin
set_milestone_frozen_marker(
repository: GITHUB_REPO,
milestone: version,
freeze: false
)
close_milestone(
repository: GITHUB_REPO,
milestone: version
)
rescue StandardError => e
report_milestone_error(error_title: "Error closing milestone `#{version}`: #{e.message}")
end
end
lane :check_translation_progress_all do
check_translation_progress_strings
check_translation_progress_release_notes
end
lane :check_translation_progress_strings do
UI.message('Checking app strings translation status...')
check_translation_progress(
glotpress_url: GLOTPRESS_APP_STRINGS_PROJECT_URL,
abort_on_violations: false
)
end
lane :check_translation_progress_release_notes do
UI.message('Checking release notes strings translation status...')
check_translation_progress(
glotpress_url: GLOTPRESS_APP_STORE_METADATA_PROJECT_URL,
abort_on_violations: false
)
end
# This lane triggers a beta build on CI.
#
# @param [String] branch_to_build The git branch the CI build should run on.
#
# @example Running the lane
# bundle exec fastlane trigger_beta_build branch_to_build:main
#
lane :trigger_beta_build do |branch_to_build:|
trigger_buildkite_release_build(
branch: branch_to_build,
beta: true
)
end
# This lane triggers a stable release build on CI.
#
# @param [String] branch_to_build The git branch the CI build should run on.
#
# @example Running the lane
# bundle exec fastlane trigger_release_build branch_to_build:main
#
lane :trigger_release_build do |branch_to_build:|
trigger_buildkite_release_build(
branch: branch_to_build,
beta: false
)
end
#####################################################################################
# build_and_upload_to_app_store_connect
# -----------------------------------------------------------------------------------
# This lane builds the app and upload it for external distribution
# -----------------------------------------------------------------------------------
# Usage:
# bundle exec fastlane build_and_upload_to_app_store_connect [skip_confirm:<skip confirm>] [beta_release:<intermediate beta?>]
#
# Example:
# bundle exec fastlane build_and_upload_to_app_store_connect
# bundle exec fastlane build_and_upload_to_app_store_connect skip_confirm:true
# bundle exec fastlane build_and_upload_to_app_store_connect beta_release:true
#####################################################################################
desc 'Builds and uploads for distribution to the App Store'
lane :build_and_upload_to_app_store_connect do |options|
unless options[:skip_prechecks]
# Verify that there's nothing in progress in the working copy
ensure_git_status_clean unless is_ci
ios_build_preflight(derived_data_path: DERIVED_DATA_DIR)
xcversion # Ensure we're using the right version of Xcode, defined in `.xcode-version` file
end
ensure_sentry_installed
UI.important("Building version #{release_version_current} (#{build_code_current}) and uploading to TestFlight")
unless options[:skip_confirm] || UI.confirm('Do you want to continue?')
UI.user_error!("Terminating as requested. Don't forget to run the remainder of this automation manually.")
end
build_for_app_store_connect
sentry_upload_dsym(
auth_token: get_required_env('SENTRY_AUTH_TOKEN'),
org_slug: 'a8c',
project_slug: 'woocommerce-ios',
dsym_path: File.join(PROJECT_ROOT_FOLDER, 'WooCommerce.app.dSYM.zip')
)
sh('cd .. && rm WooCommerce.app.dSYM.zip')
archive_zip_path = File.join(File.dirname(Dir.pwd), 'WooCommerce.xarchive.zip')
zip(path: lane_context[SharedValues::XCODEBUILD_ARCHIVE], output_path: archive_zip_path)
version = options[:beta_release] ? build_code_current : release_version_current
create_release(
repository: GITHUB_REPO,
version: version,
release_notes_file_path: RELEASE_NOTES_PATH,
release_assets: archive_zip_path.to_s,
prerelease: options[:beta_release]
)
sh("rm #{archive_zip_path}")
upload_to_testflight(
api_key_path: ASC_KEY_PATH,
# Wait 2 hours for the build to process then time out
wait_processing_timeout_duration: 7200,
changelog: File.read(RELEASE_NOTES_PATH),
distribute_external: true,
# If there is a build waiting for beta review, we want to reject that so the new build can be submitted instead
reject_build_waiting_for_review: true,
groups: ['Internal a8c beta testers', 'Public Beta Testers']
)
sh('cd .. && rm WooCommerce.ipa')
end
desc 'Builds for distribution to the App Store'
lane :build_for_app_store_connect do
appstore_code_signing
gym(
scheme: 'WooCommerce',
workspace: WORKSPACE_PATH,
clean: true,
export_team_id: get_required_env('EXT_EXPORT_TEAM_ID'),
export_options: { **COMMON_EXPORT_OPTIONS, method: 'app-store' }
)
end
#####################################################################################
# build_and_upload_prototype_build
# -----------------------------------------------------------------------------------
# This lane builds the app and upload it for adhoc testing
# -----------------------------------------------------------------------------------
# Usage:
# bundle exec fastlane build_and_upload_prototype_build [version_long:<version_long>]
#
# Example:
# bundle exec fastlane build_and_upload_prototype_build
# bundle exec fastlane build_and_upload_prototype_build build_number:123
#####################################################################################
desc 'Builds and uploads a prototype build (Enterprise distribution)'
lane :build_and_upload_prototype_build do
ensure_sentry_installed
xcversion # Ensure we're using the right version of Xcode, defined in `.xcode-version` file
build_for_prototype_build
appcenter_upload(
api_token: get_required_env('APPCENTER_API_TOKEN'),
owner_name: 'automattic',
owner_type: 'organization',
app_name: 'WooCommerce-Installable-Builds',
destinations: 'Collaborators',
notify_testers: false
)
sentry_upload_dsym(
auth_token: get_required_env('SENTRY_AUTH_TOKEN'),
org_slug: 'a8c',
project_slug: 'woocommerce-ios',
dsym_path: './build/WooCommerce.app.dSYM.zip'
)
# The build code used in the Enterprise build has a different format that the App Store one.
# We cannot use the standard build_code_current method but have to read it directly.
build_code = Xcodeproj::Config.new(File.new(PUBLIC_CONFIG_FILE)).to_hash[BUILD_CODE_KEY]
UI.message("Successfully built and uploaded prototype build `#{build_code}` to App Center.")
return if ENV['BUILDKITE_PULL_REQUEST'].nil?
# PR Comment
comment_body = prototype_build_details_comment(
app_display_name: 'WooCommerce iOS',
app_center_org_name: 'automattic'
)
comment_on_pr(
project: GITHUB_REPO,
pr_number: Integer(ENV.fetch('BUILDKITE_PULL_REQUEST')),
reuse_identifier: 'prototype-build-link',
body: comment_body
)
end
desc 'Builds a prototype build (Enterprise build)'
lane :build_for_prototype_build do
alpha_code_signing
# Get the current build version, and update it if needed
versions = Xcodeproj::Config.new(File.new(PUBLIC_CONFIG_FILE)).to_hash
build_number = generate_prototype_build_number
UI.message("Updating build version to #{build_number}")
versions[BUILD_CODE_KEY] = build_number
new_config = Xcodeproj::Config.new(versions)
new_config.save_as(Pathname.new(PUBLIC_CONFIG_FILE))
gym(
scheme: 'WooCommerce Alpha',
workspace: WORKSPACE_PATH,
export_method: 'enterprise',
clean: true,
output_directory: 'build',
export_team_id: get_required_env('INT_EXPORT_TEAM_ID'),
export_options: {
**COMMON_EXPORT_OPTIONS,
method: 'enterprise',
iCloudContainerEnvironment: 'Production'
}
)
end
#####################################################################################
# build_for_testing
# -----------------------------------------------------------------------------------
# This lane builds the app for testing
# -----------------------------------------------------------------------------------
# Usage:
# bundle exec fastlane build_for_testing
#####################################################################################
desc 'Build for Testing'
lane :build_for_testing do |options|
xcversion # Ensure we're using the right version of Xcode, defined in `.xcode-version` file
run_tests(
workspace: WORKSPACE_PATH,
scheme: TEST_SCHEME,
derived_data_path: 'DerivedData',
build_for_testing: true,
device: options[:device],
deployment_target_version: options[:ios_version]
)
end
# Upload the localized metadata (from `fastlane/metadata/`) to App Store Connect
#
# @option [Boolean] with_screenshots (default: false) If true, will also upload the latest screenshot files to ASC
# @option [Boolean] skip_confirm If true, the HTML preview will be bypassed
#
desc 'Upload the localized metadata to App Store Connect, optionally including screenshots.'
lane :update_metadata_on_app_store_connect do |options|
# Skip screenshots by default. The naming is "with" to make it clear that
# callers need to opt-in to adding screenshots. The naming of the deliver
# (upload_to_app_store) parameter, on the other hand, uses the skip verb.
with_screenshots = options.fetch(:with_screenshots, false)
skip_screenshots = !with_screenshots
upload_to_app_store(
app_identifier: APP_STORE_VERSION_BUNDLE_IDENTIFIER,
app_version: release_version_current,
team_id: '299112',
skip_binary_upload: true,
screenshots_path: File.join(FASTLANE_DIR, 'promo_screenshots'),
skip_screenshots: skip_screenshots,
overwrite_screenshots: true, # won't have effect if `skip_screenshots` is true
phased_release: true,
precheck_include_in_app_purchases: false,
api_key_path: ASC_KEY_PATH,
force: options[:skip_confirm]
)
end
########################################################################
# Screenshot Lanes
########################################################################
desc 'Build Screenshots'
lane :build_screenshots do
# Ensure we're using the latest Pods
cocoapods(verbose: true)
# Ensure we're using the right version of Xcode, defined in `.xcode-version` file
xcversion
scan(
workspace: WORKSPACE_PATH,
scheme: SCREENSHOTS_SCHEME,
build_for_testing: true,
derived_data_path: DERIVED_DATA_DIR
)
end
desc 'Take Screenshots'
lane :take_screenshots do |options|
# Ensure we're using the right version of Xcode, defined in `.xcode-version` file
xcversion
# By default, clear previous screenshots
languages = IOS_LOCALES
languages &= options[:languages].split(',') unless options[:languages].nil?
devices = SCREENSHOT_DEVICES
devices &= options[:devices].split(',') unless options[:devices].nil?
UI.user_error!("Unable to run on devices: \"#{devices}\"") if devices.empty?
puts "Creating screenshots for #{languages} on #{devices}"
# Erase the simulator between runs in order to get everything back to a default state
rebuild_screenshot_devices
capture_ios_screenshots(
scheme: SCREENSHOTS_SCHEME,
localize_simulator: true,
languages: languages,
devices: devices,
# Don't rebuild the app for every new locale / device type, and specify where to find the binaries
test_without_building: true,
derived_data_path: DERIVED_DATA_DIR,
# Where should the screenshots go, and should we delete them before starting?
output_directory: SCREENSHOTS_DIR,
# Output the simulator logs for debugging
buildlog_path: File.join(FASTLANE_DIR, 'logs'),
output_simulator_logs: true,
result_bundle: true,
namespace_log_files: true,
concurrent_simulators: true,
# Explicitly set the iOS version to ensure we match the created simulators
ios_version: SIMULATOR_VERSION,
# Erase the simulator prior to booting the app
erase_simulator: true,
# Retry a few times if something is a little flaky
number_of_retries: 3,
# But fail completely after those 3 retries
stop_after_first_error: true,
# Allow the caller to invoke dark mode
dark_mode: options[:mode].to_s.downcase == 'dark',
# Make the status bar pretty
override_status_bar: true
)
end
desc 'Create Screenshots Locally'
lane :screenshots do |options|
FileUtils.rm_f(SCREENSHOTS_DIR)
build_screenshots(options)
take_screenshots(options.merge({ mode: 'light' }))
take_screenshots(options.merge({ mode: 'dark' }))
end
desc 'Rebuild Screenshot Devices'
lane :rebuild_screenshot_devices do
require 'simctl'
SimCtl.list_devices.each do |device|
next unless SCREENSHOT_DEVICES.include? device.name
puts "Deleting #{device.name} because it already exists."
device.delete
end
SCREENSHOT_DEVICES.each do |device|
runtime = SimCtl.runtime(name: "iOS #{SIMULATOR_VERSION}")
devicetype = SimCtl.devicetype(name: device)
SimCtl.create_device(device, devicetype, runtime)
end
end
desc 'Create Screenshot Summary'
lane :create_screenshot_summary do
fastlane_require 'snapshot'
# Provide enough information to bootstrap the configuration and generate the HTML report
Snapshot.config = FastlaneCore::Configuration.create(
Snapshot::Options.available_options,
{
workspace: WORKSPACE_PATH,
scheme: SCREENSHOTS_SCHEME
}
)
Snapshot::ReportsGenerator.new.generate
end
desc 'Downloads localized strings and App Store Connect metadata from GlotPress'
lane :download_localized_strings_and_metadata_from_glotpress do
download_localized_strings_from_glotpress
download_localized_metadata_from_glotpress
end
desc 'Downloads localized `.strings` from GlotPress'
lane :download_localized_strings_from_glotpress do
ios_download_strings_files_from_glotpress(
project_url: GLOTPRESS_APP_STRINGS_PROJECT_URL,
locales: GLOTPRESS_TO_LPROJ_APP_LOCALE_CODES,
download_dir: RESOURCES_FOLDER
)
git_commit(
path: File.join(RESOURCES_FOLDER, '*.lproj', 'Localizable.strings'),
message: 'Update app translations – `Localizable.strings`',
allow_nothing_to_commit: true
)
# Redispatch the appropriate subset of translations back to the manually-maintained `.strings`
# files that we merged at the `complete_code_freeze` time via `ios_merge_strings_files`
modified_files = ios_extract_keys_from_strings_files(
source_parent_dir: RESOURCES_FOLDER,
target_original_files: MANUALLY_MAINTAINED_STRINGS_FILES
)
git_commit(
path: modified_files,
message: 'Update app translations – Other `.strings`',
allow_nothing_to_commit: true
)
end
desc 'Downloads localized metadata for App Store Connect from GlotPress'
lane :download_localized_metadata_from_glotpress do
metadata_directory = FASTLANE_METADATA_FOLDER
# FIXME: We should make the `fastlane/metadata/default/release_notes.txt` path be the source of truth for the original copies in the future.
# (will require changes in the `update_app_store_strings` lane, the Release Scenario, the MC tool to generate the announcement post…)
#
# In the meantime, just copy the file to the right place for `deliver` to find, i.e. to the `default` pseudo-locale which is used as fallback
FileUtils.cp(RELEASE_NOTES_PATH, File.join(metadata_directory, 'default', 'release_notes.txt'))
# FIXME: Replace this with a call to the future replacement of `gp_downloadmetadata` once it's implemented in the release-toolkit (see paaHJt-31O-p2).
locales_map = GLOTPRESS_TO_ASC_METADATA_LOCALE_CODES
target_files = {
"v#{release_version_current}-whats-new": { desc: 'release_notes.txt', max_size: 4000 },
app_store_name: { desc: 'name.txt', max_size: 30 },
app_store_subtitle: { desc: 'subtitle.txt', max_size: 30 },
app_store_desc: { desc: 'description.txt', max_size: 4000 },
app_store_keywords: { desc: 'keywords.txt', max_size: 100 }
}
gp_downloadmetadata(
project_url: GLOTPRESS_APP_STORE_METADATA_PROJECT_URL,
target_files: target_files,
locales: locales_map,
download_path: metadata_directory
)
files_to_commit = [File.join(metadata_directory, '**', '*.txt')]
# Ensure that none of the `.txt` files in `en-US` would accidentally override our originals in `default`
target_files.values.map { |h| h[:desc] }.each do |file|
en_file_path = File.join(metadata_directory, 'en-US', file)
if File.exist?(en_file_path)
UI.user_error!("File `#{en_file_path}` would override the same one in `#{metadata_directory}/default`, but `default/` is the source of truth. " \
+ "Delete the `#{en_file_path}` file, ensure the `default/` one has the expected original copy, and try again.")
end
end
# Ensure even empty locale folders have an empty `.gitkeep` file (in case we don't have any translation at all ready for some locales)
locales_map.each_value do |locale|
gitkeep = File.join(metadata_directory, locale, '.gitkeep')
next if File.exist?(gitkeep)
FileUtils.mkdir_p(File.dirname(gitkeep))
FileUtils.touch(gitkeep)
files_to_commit.append(gitkeep)
end