Skip to content

Commit 1b4d20f

Browse files
committed
Add download_localized_metadata_from_glotpress lane
1 parent 8cb10b6 commit 1b4d20f

File tree

1 file changed

+106
-2
lines changed

1 file changed

+106
-2
lines changed

fastlane/Fastfile

Lines changed: 106 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ UI.user_error!('Please run fastlane via `bundle exec`') unless FastlaneCore::Hel
99
# Constants
1010
USER_ENV_FILE_PATH = File.join(Dir.home, '.simplenotemacos-env.default')
1111
PROJECT_FOLDER = Pathname.new(File.join(Dir.pwd, '..')).expand_path.to_s
12+
PROJECT_ROOT_FOLDER = PROJECT_FOLDER
1213
WORKSPACE = 'Simplenote.xcworkspace'
1314
INTERNAL_SCHEME = 'Simplenote'
1415
APP_STORE_SCHEME = 'Simplenote'
@@ -20,6 +21,38 @@ DEFAULT_BRANCH = 'trunk'
2021
GITHUB_REPO = 'Automattic/simplenote-macos'
2122
APPLE_TEAM_ID = 'PZYM8XX95Q'
2223

24+
APP_RESOURCES_DIR = File.join(PROJECT_ROOT_FOLDER, 'Simplenote', 'Resources')
25+
RELEASE_NOTES_SOURCE_PATH = File.join(APP_RESOURCES_DIR, 'release_notes.txt')
26+
STORE_METADATA_FOLDER = File.join(PROJECT_ROOT_FOLDER, 'fastlane', 'metadata')
27+
28+
GLOTPRESS_BASE_URL = 'https://translate.wordpress.com/projects'
29+
# Notice the trailing / is required.
30+
# Without it, GlotPress will redirect to the version with /
31+
GLOTPRESS_APP_STRINGS_PROJECT_URL = "#{GLOTPRESS_BASE_URL}/simplenote/macos/".freeze
32+
GLOTPRESS_STORE_METADATA_PROJECT_URL = "#{GLOTPRESS_APP_STRINGS_PROJECT_URL}release-notes/".freeze
33+
34+
# Mapping of all locales which can be used for AppStore metadata (Glotpress code => AppStore Connect code)
35+
#
36+
# TODO: Replace with `LocaleHelper` once provided by release toolkit (https://github.com/wordpress-mobile/release-toolkit/pull/296)
37+
GLOTPRESS_TO_ASC_METADATA_LOCALE_CODES = {
38+
'ar' => 'ar-SA',
39+
'de' => 'de-DE',
40+
'es' => 'es-ES',
41+
'fr' => 'fr-FR',
42+
'he' => 'he',
43+
'id' => 'id',
44+
'it' => 'it',
45+
'ja' => 'ja',
46+
'ko' => 'ko',
47+
'nl' => 'nl-NL',
48+
'pt-br' => 'pt-BR',
49+
'ru' => 'ru',
50+
'sv' => 'sv',
51+
'tr' => 'tr',
52+
'zh-cn' => 'zh-Hans',
53+
'zh-tw' => 'zh-Hant'
54+
}.freeze
55+
2356
########################################################################
2457
# Environment
2558
########################################################################
@@ -318,11 +351,10 @@ end
318351
# @option [Boolean] with_screenshots (default: false) If true, will also upload the latest screenshot files to ASC
319352
#
320353
desc 'Upload the localized metadata to App Store Connect, optionally including screenshots.'
321-
lane :update_metadata_on_app_store_connect do |options|
354+
lane :update_metadata_on_app_store_connect do |with_screenshots: false|
322355
# Skip screenshots by default. The naming is "with" to make it clear that
323356
# callers need to opt-in to adding screenshots. The naming of the deliver
324357
# (upload_to_app_store) parameter, on the other hand, uses the skip verb.
325-
with_screenshots = options.fetch(:with_screenshots, false)
326358
skip_screenshots = !with_screenshots
327359

328360
upload_to_app_store(
@@ -527,3 +559,75 @@ def configure_code_signing(type:, readonly: true)
527559
api_key: app_store_connect_api_key
528560
)
529561
end
562+
563+
lane :download_localized_metadata_from_glotpress do
564+
# FIXME: We should make the `fastlane/metadata/default/release_notes.txt` path be the source of truth for the original copies in the future.
565+
# (will require changes in the `update_appstore_strings` lane, the Release Scenario, the MC tool to generate the announcement post…)
566+
#
567+
# In the meantime, just copy the file to the right place for `deliver` to find, for the `default` pseudo-locale which is used as fallback
568+
FileUtils.cp(RELEASE_NOTES_SOURCE_PATH, File.join(STORE_METADATA_FOLDER, 'default', 'release_notes.txt'))
569+
570+
# 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).
571+
target_files = {
572+
"v#{release_version_current}-whats-new": { desc: 'release_notes.txt', max_size: 4000 },
573+
app_store_name: { desc: 'name.txt', max_size: 30 },
574+
app_store_subtitle: { desc: 'subtitle.txt', max_size: 30 },
575+
app_store_desc: { desc: 'description.txt', max_size: 4000 },
576+
app_store_keywords: { desc: 'keywords.txt', max_size: 100 }
577+
}
578+
gp_downloadmetadata(
579+
project_url: GLOTPRESS_STORE_METADATA_PROJECT_URL,
580+
target_files: target_files,
581+
locales: GLOTPRESS_TO_ASC_METADATA_LOCALE_CODES,
582+
download_path: STORE_METADATA_FOLDER
583+
)
584+
585+
files_to_commit = [File.join(STORE_METADATA_FOLDER, '**', '*.txt')]
586+
587+
ensure_default_metadata_are_not_overridden(metadata_files_hash: target_files)
588+
589+
files_to_commit.append(*generate_gitkeep_for_empty_locale_folders)
590+
591+
git_add(path: files_to_commit, shell_escape: false)
592+
git_commit(
593+
path: files_to_commit,
594+
message: 'Update App Store metadata translations',
595+
allow_nothing_to_commit: true
596+
)
597+
end
598+
599+
# FIXME: Defined this way to ease transition to Versioning module while copying code ported from repos already using it
600+
def release_version_current
601+
ios_get_app_version(public_version_xcconfig_file: VERSION_FILE_PATH)
602+
end
603+
604+
# Ensure that none of the `.txt` files in `en-US` would accidentally override our originals in `default`
605+
def ensure_default_metadata_are_not_overridden(metadata_files_hash:)
606+
metadata_files_hash.values.map { |t| t[:desc] }.each do |file|
607+
en_file_path = File.join(STORE_METADATA_FOLDER, 'en-US', file)
608+
609+
override_not_allowed_message = <<~MSG
610+
File `#{en_file_path}` would override the same one in `#{STORE_METADATA_FOLDER}/default`.
611+
`default/` is the source of truth and we cannot allow it to change unintentionally.
612+
Delete `#{en_file_path}`, ensure the version in `default/` has the expected original copy, and try again.
613+
MSG
614+
UI.user_error!(override_not_allowed_message) if File.exist?(en_file_path)
615+
end
616+
end
617+
618+
# Ensure even empty locale folders have an empty `.gitkeep` file.
619+
# This way, if we don't have any translation ready for those locales, we'll still have the folders in Git for clarity.
620+
def generate_gitkeep_for_empty_locale_folders
621+
gitkeeps = []
622+
623+
GLOTPRESS_TO_ASC_METADATA_LOCALE_CODES.each_value do |locale|
624+
gitkeep = File.join(STORE_METADATA_FOLDER, locale, '.gitkeep')
625+
next if File.exist?(gitkeep)
626+
627+
FileUtils.mkdir_p(File.dirname(gitkeep))
628+
FileUtils.touch(gitkeep)
629+
gitkeeps.append(gitkeep)
630+
end
631+
632+
gitkeeps
633+
end

0 commit comments

Comments
 (0)