diff --git a/fastlane/Fastfile b/fastlane/Fastfile index 32c80f13630a..9d047db31fd9 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -2,6 +2,7 @@ UI.user_error!('Please run fastlane via `bundle exec`') unless FastlaneCore::Hel APP_SPECIFIC_VALUES = { wordpress: { + display_name: 'WordPress', metadata_dir: 'metadata', glotpress_appstrings_project: 'https://translate.wordpress.org/projects/apps/android/dev/', glotpress_metadata_project: 'https://translate.wordpress.org/projects/apps/android/release-notes/', @@ -9,6 +10,7 @@ APP_SPECIFIC_VALUES = { bundle_name_prefix: 'wpandroid' }, jetpack: { + display_name: 'Jetpack', metadata_dir: 'jetpack_metadata', glotpress_appstrings_project: 'https://translate.wordpress.com/projects/jetpack/apps/android/', glotpress_metadata_project: 'https://translate.wordpress.com/projects/jetpack/apps/android/release-notes/', diff --git a/fastlane/lanes/localization.rb b/fastlane/lanes/localization.rb index d06f28594705..d57d406475c3 100644 --- a/fastlane/lanes/localization.rb +++ b/fastlane/lanes/localization.rb @@ -11,7 +11,6 @@ # First are the locales which are used for *both* downloading the `strings.xml` files from GlotPress *and* for generating the release notes XML files. { glotpress: 'ar', android: 'ar', google_play: 'ar', promo_config: {} }, { glotpress: 'de', android: 'de', google_play: 'de-DE', promo_config: {} }, - { glotpress: 'en-gb', android: 'en-rGB', google_play: 'en-US', promo_config: {} }, { glotpress: 'es', android: 'es', google_play: 'es-ES', promo_config: {} }, { glotpress: 'fr', android: 'fr-rCA', google_play: 'fr-CA', promo_config: false }, { glotpress: 'fr', android: 'fr', google_play: 'fr-FR', promo_config: {} }, @@ -95,78 +94,36 @@ ##################################################################################### desc 'Updates the PlayStoreStrings.po files for WP + JP' lane :update_appstore_strings do |options| - update_wordpress_appstore_strings(options) - update_jetpack_appstore_strings(options) - end - - ##################################################################################### - # update_wordpress_appstore_strings - # ----------------------------------------------------------------------------------- - # This lane gets the data from the txt files in the `WordPress/metadata/` folder - # and updates the `.po` file that is then picked by GlotPress for translations. - # ----------------------------------------------------------------------------------- - # Usage: - # fastlane update_wordpress_appstore_strings [version:] - # - # Example: - # fastlane update_wordpress_appstore_strings version:10.3 - ##################################################################################### - desc 'Updates the PlayStoreStrings.po file for WordPress' - lane :update_wordpress_appstore_strings do |options| - metadata_folder = File.join(Dir.pwd, '..', 'WordPress', 'metadata') - version = options.fetch(:version, android_get_app_version) - - # => - files = { - release_note: File.join(metadata_folder, 'release_notes.txt'), - release_note_short: File.join(metadata_folder, 'release_notes_short.txt'), - play_store_app_title: File.join(metadata_folder, 'title.txt'), - play_store_promo: File.join(metadata_folder, 'short_description.txt'), - play_store_desc: File.join(metadata_folder, 'full_description.txt') - } - files.merge!((1..9).map do |n| - [:"play_store_screenshot_#{n}", File.join(metadata_folder, "screenshot_#{n}.txt")] - end.to_h) - - update_po_file_for_metadata_localization( - po_path: File.join(metadata_folder, 'PlayStoreStrings.po'), - sources: files, - release_version: version, - commit_message: "Update WordPress `PlayStoreStrings.po` for version #{version}" - ) - end - - ##################################################################################### - # update_jetpack_appstore_strings - # ----------------------------------------------------------------------------------- - # This lane gets the data from the txt files in the `WordPress/jetpack_metadata/` folder - # and updates the `.po` file that is then picked by GlotPress for translations. - # ----------------------------------------------------------------------------------- - # Usage: - # fastlane update_jetpack_appstore_strings [version:] - # - # Example: - # fastlane update_jetpack_appstore_strings version:10.3 - ##################################################################################### - desc 'Updates the PlayStoreStrings.po file for Jetpack' - lane :update_jetpack_appstore_strings do |options| - metadata_folder = File.join(Dir.pwd, '..', 'WordPress', 'jetpack_metadata') - version = options.fetch(:version, android_get_app_version) + # If no `app:` is specified, call this for both WordPress and Jetpack + apps = options[:app].nil? ? %i[wordpress jetpack] : Array(options[:app]&.downcase&.to_sym) + + apps.each do |app| + app_values = APP_SPECIFIC_VALUES[app] + + metadata_folder = File.join(PROJECT_ROOT_FOLDER, 'WordPress', app_values[:metadata_dir]) + version = options.fetch(:version, android_get_app_version) + + # => + files = { + release_note: File.join(metadata_folder, 'release_notes.txt'), + release_note_short: File.join(metadata_folder, 'release_notes_short.txt'), + play_store_app_title: File.join(metadata_folder, 'title.txt'), + play_store_promo: File.join(metadata_folder, 'short_description.txt'), + play_store_desc: File.join(metadata_folder, 'full_description.txt') + } + # Add entries for `screenshot_*.txt` files as well + Dir.glob('screenshot_*.txt', base: metadata_folder).sort.each do |screenshot_file| + key = "play_store_#{File.basename(screenshot_file, '.txt')}".to_sym + files[key] = File.join(metadata_folder, screenshot_file) + end - files = { - release_note: File.join(metadata_folder, 'release_notes.txt'), - release_note_short: File.join(metadata_folder, 'release_notes_short.txt'), - play_store_app_title: File.join(metadata_folder, 'title.txt'), - play_store_promo: File.join(metadata_folder, 'short_description.txt'), - play_store_desc: File.join(metadata_folder, 'full_description.txt') - } - - update_po_file_for_metadata_localization( - po_path: File.join(metadata_folder, 'PlayStoreStrings.po'), - sources: files, - release_version: version, - commit_message: "Update Jetpack `PlayStoreStrings.po` for version #{version}" - ) + update_po_file_for_metadata_localization( + po_path: File.join(metadata_folder, 'PlayStoreStrings.po'), + sources: files, + release_version: version, + commit_message: "Update #{app_values[:display_name]} `PlayStoreStrings.po` for version #{version}" + ) + end end # Updates the metadata in the Play Store (Main store listing) from the content of `fastlane/{metadata|jetpack_metadata}/android/*/*.txt` files @@ -209,70 +166,47 @@ ##################################################################################### desc 'Downloads translated metadata from GlotPress' lane :download_metadata_strings do |options| - download_wordpress_metadata_strings(options) - download_jetpack_metadata_strings(options) - end - - desc "Downloads WordPress's translated metadata from GlotPress" - lane :download_wordpress_metadata_strings do |options| - app_values = APP_SPECIFIC_VALUES[:wordpress] - values = options[:version].split('.') - files = { - "release_note_#{values[0]}#{values[1]}" => { desc: "changelogs/#{options[:build_number]}.txt", max_size: 500, alternate_key: "release_note_short_#{values[0]}#{values[1]}" }, - play_store_app_title: { desc: 'title.txt', max_size: 30 }, - play_store_promo: { desc: 'short_description.txt', max_size: 80 }, - play_store_desc: { desc: 'full_description.txt', max_size: 4000 } - } - - delete_old_changelogs(app: 'wordpress', build: options[:build_number]) - download_path = File.join(Dir.pwd, app_values[:metadata_dir], 'android') - # The case for the source locale (en-US) is pulled in a hacky way, by having an {en-gb => en-US} mapping as part of the WP_RELEASE_NOTES_LOCALES, - # which is then treated in a special way by gp_downloadmetadata by specifying a `source_locale: 'en-US'` to process it differently from the rest. - gp_downloadmetadata( - project_url: app_values[:glotpress_metadata_project], - target_files: files, - locales: WP_RELEASE_NOTES_LOCALES, - source_locale: 'en-US', - download_path: download_path - ) - - git_add(path: download_path) - git_commit(path: download_path, message: "Update WordPress metadata translations for #{options[:version]}", allow_nothing_to_commit: true) - push_to_git_remote - end - - desc "Downloads Jetpack's translated metadata from GlotPress" - lane :download_jetpack_metadata_strings do |options| - UI.message('Hey') - app_values = APP_SPECIFIC_VALUES[:jetpack] - values = options[:version].split('.') - files = { - "release_note_#{values[0]}#{values[1]}" => { desc: "changelogs/#{options[:build_number]}.txt", max_size: 500, alternate_key: "release_note_short_#{values[0]}#{values[1]}" }, - play_store_app_title: { desc: 'title.txt', max_size: 30 }, - play_store_promo: { desc: 'short_description.txt', max_size: 80 }, - play_store_desc: { desc: 'full_description.txt', max_size: 4000 } - } - - delete_old_changelogs(app: 'jetpack', build: options[:build_number]) - download_path = File.join(Dir.pwd, app_values[:metadata_dir], 'android') - gp_downloadmetadata( - project_url: app_values[:glotpress_metadata_project], - target_files: files, - locales: JP_RELEASE_NOTES_LOCALES, - download_path: download_path - ) - - # For WordPress, the en-US release notes come from using the source keys (instead of translations) downloaded from GlotPress' en-gb locale (which is unused otherwise). - # But for Jetpack, we don't have an unused locale like en-gb in the GP release notes project, so copy from source instead as a fallback - metadata_source_dir = File.join(Dir.pwd, '..', 'WordPress', 'jetpack_metadata') - FileUtils.cp(File.join(metadata_source_dir, 'release_notes.txt'), File.join(download_path, 'en-US', 'changelogs', "#{options[:build_number]}.txt")) - FileUtils.cp( - ['title.txt', 'short_description.txt', 'full_description.txt'].map { |f| File.join(metadata_source_dir, f) }, - File.join(download_path, 'en-US') - ) + version = options.fetch(:version, android_get_app_version) + build_number = options.fetch(:build_number, android_get_release_version['code']) + + # If no `app:` is specified, call this for both WordPress and Jetpack + apps = options[:app].nil? ? %i[wordpress jetpack] : Array(options[:app]&.downcase&.to_sym) + + apps.each do |app| + app_values = APP_SPECIFIC_VALUES[app] + + version_suffix = version.split('.').join + files = { + "release_note_#{version_suffix}" => { desc: "changelogs/#{build_number}.txt", max_size: 500, alternate_key: "release_note_short_#{version_suffix}" }, + play_store_app_title: { desc: 'title.txt', max_size: 30 }, + play_store_promo: { desc: 'short_description.txt', max_size: 80 }, + play_store_desc: { desc: 'full_description.txt', max_size: 4000 } + } + + delete_old_changelogs(app: app, build: build_number) + + download_path = File.join(Dir.pwd, app_values[:metadata_dir], 'android') + locales = { wordpress: WP_RELEASE_NOTES_LOCALES, jetpack: JP_RELEASE_NOTES_LOCALES }[app] + UI.header("Downloading metadata translations for #{app_values[:display_name]}") + gp_downloadmetadata( + project_url: app_values[:glotpress_metadata_project], + target_files: files, + locales: locales, + download_path: download_path + ) - git_add(path: download_path) - git_commit(path: download_path, message: "Update Jetpack metadata translations for #{options[:version]}", allow_nothing_to_commit: true) + # Copy the source `.txt` files (used as source of truth when we generated the `.po`) to the `fastlane/*metadata/android/en-US` dir, + # as `en-US` is the source language, and isn't exported from GlotPress during `gp_downloadmetadata` + metadata_source_dir = File.join(PROJECT_ROOT_FOLDER, 'WordPress', app_values[:metadata_dir]) + FileUtils.cp(File.join(metadata_source_dir, 'release_notes.txt'), File.join(download_path, 'en-US', 'changelogs', "#{build_number}.txt")) + FileUtils.cp( + ['title.txt', 'short_description.txt', 'full_description.txt'].map { |f| File.join(metadata_source_dir, f) }, + File.join(download_path, 'en-US') + ) + + git_add(path: download_path) + git_commit(path: download_path, message: "Update #{app_values[:display_name]} metadata translations for #{version}", allow_nothing_to_commit: true) + end push_to_git_remote end diff --git a/fastlane/lanes/release.rb b/fastlane/lanes/release.rb index 5d80a52557de..0c436955b952 100644 --- a/fastlane/lanes/release.rb +++ b/fastlane/lanes/release.rb @@ -314,7 +314,7 @@ def get_app_name_option!(options) app = options[:app]&.downcase UI.user_error!("Missing 'app' parameter. Expected 'app:wordpress' or 'app:jetpack'") if app.nil? - unless ['wordpress', 'jetpack'].include?(app) + unless %i[wordpress jetpack].include?(app.to_sym) UI.user_error!("Invalid 'app' parameter #{app.inspect}. Expected 'wordpress' or 'jetpack'") end return app