From 5b7b0717cdc97a5ece8c08a0f56d1b522517ed35 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Tue, 1 Nov 2022 20:48:57 +1100 Subject: [PATCH 1/3] Add `skip_commit` option to `generate_strings_file_for_glotpress` lane This will allow us to run the lane in CI without changing the repo state, even though that's something that wouldn't be pushed. --- fastlane/lanes/localization.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fastlane/lanes/localization.rb b/fastlane/lanes/localization.rb index a1e7ef8d737a..ba556a3ac7b0 100644 --- a/fastlane/lanes/localization.rb +++ b/fastlane/lanes/localization.rb @@ -123,7 +123,7 @@ # # @called_by complete_code_freeze # - lane :generate_strings_file_for_glotpress do + lane :generate_strings_file_for_glotpress do |options| cocoapods wordpress_en_lproj = File.join('WordPress', 'Resources', 'en.lproj') @@ -141,7 +141,7 @@ destination: File.join(wordpress_en_lproj, 'Localizable.strings') ) - git_commit(path: [wordpress_en_lproj], message: 'Update strings for localization', allow_nothing_to_commit: true) + git_commit(path: [wordpress_en_lproj], message: 'Update strings for localization', allow_nothing_to_commit: true) unless options[:skip_commit] end From 66d881811ff6c84c6be149f6b5e28b6bea51cfe8 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Tue, 1 Nov 2022 20:52:43 +1100 Subject: [PATCH 2/3] Add CI step to run `.strings` generation --- .../commands/lint-localized-strings-format.sh | 14 ++++++++++++++ .buildkite/pipeline.yml | 7 +++++++ 2 files changed, 21 insertions(+) create mode 100644 .buildkite/commands/lint-localized-strings-format.sh diff --git a/.buildkite/commands/lint-localized-strings-format.sh b/.buildkite/commands/lint-localized-strings-format.sh new file mode 100644 index 000000000000..e6b4949190cc --- /dev/null +++ b/.buildkite/commands/lint-localized-strings-format.sh @@ -0,0 +1,14 @@ +#!/bin/bash -eu + +echo "--- :rubygems: Setting up Gems" +install_gems + +echo "--- :cocoapods: Setting up Pods" +install_cocoapods + +echo "--- :writing_hand: Copy Files" +mkdir -pv ~/.configure/wordpress-ios/secrets +cp -v fastlane/env/project.env-example ~/.configure/wordpress-ios/secrets/project.env + +echo "--- Lint Localized Strings Format" +bundle exec fastlane generate_strings_file_for_glotpress skip_commit:true diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index 5953dbf28c42..71e9b76c9350 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -123,3 +123,10 @@ steps: plugins: *common_plugins agents: queue: "android" + # Runs the `.strings` generation automation to ensure all the + # `LocalizedString` calls in the code can be correctly parsed by Apple's + # `genstrings`. + - label: "Lint Localized Strings Format" + command: .buildkite/commands/lint-localized-strings-format.sh + plugins: *common_plugins + env: *common_env From 448d3985c649c963ee8a8758c380d5a42b5b0fa0 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Tue, 8 Nov 2022 13:16:51 +0100 Subject: [PATCH 3/3] Annotate build with failed `genestrings` messages --- .../commands/lint-localized-strings-format.sh | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/.buildkite/commands/lint-localized-strings-format.sh b/.buildkite/commands/lint-localized-strings-format.sh index e6b4949190cc..772d439f3ed5 100644 --- a/.buildkite/commands/lint-localized-strings-format.sh +++ b/.buildkite/commands/lint-localized-strings-format.sh @@ -11,4 +11,33 @@ mkdir -pv ~/.configure/wordpress-ios/secrets cp -v fastlane/env/project.env-example ~/.configure/wordpress-ios/secrets/project.env echo "--- Lint Localized Strings Format" -bundle exec fastlane generate_strings_file_for_glotpress skip_commit:true +LOGS=logs.txt +set +e +set -o pipefail +bundle exec fastlane generate_strings_file_for_glotpress skip_commit:true | tee $LOGS +EXIT_CODE=$? +set -e + +echo $EXIT_CODE + +if [[ $EXIT_CODE -ne 0 ]]; then + # Strings generation finished with errors, extract the errors in an easy-to-find section + echo "--- Report genstrings errors" + ERRORS=errors.txt + echo "Found errors when trying to run \`genstrings\` to generate the \`.strings\` files from \`*LocalizedStrings\` calls:" | tee $ERRORS + echo '' >> $ERRORS + # Print the errors inline. + # + # Notice the second `sed` call that removes the ANSI escape sequences that + # Fastlane uses to color the output. + grep -e "\[.*\].*genstrings:" $LOGS \ + | sed -e 's/\[.*\].*genstrings: error: /- /' \ + | sed -e $'s/\x1b\[[0-9;]*m//g' \ + | sort \ + | uniq \ + | tee -a $ERRORS + # Annotate the build with the errors + cat $ERRORS | buildkite-agent annotate --style error --context genstrings +fi + +exit $EXIT_CODE