Skip to content

Commit adbb17e

Browse files
authored
Run genstrings in CI to validate *LocalizedString usages (#19553)
2 parents b1dd374 + 448d398 commit adbb17e

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash -eu
2+
3+
echo "--- :rubygems: Setting up Gems"
4+
install_gems
5+
6+
echo "--- :cocoapods: Setting up Pods"
7+
install_cocoapods
8+
9+
echo "--- :writing_hand: Copy Files"
10+
mkdir -pv ~/.configure/wordpress-ios/secrets
11+
cp -v fastlane/env/project.env-example ~/.configure/wordpress-ios/secrets/project.env
12+
13+
echo "--- Lint Localized Strings Format"
14+
LOGS=logs.txt
15+
set +e
16+
set -o pipefail
17+
bundle exec fastlane generate_strings_file_for_glotpress skip_commit:true | tee $LOGS
18+
EXIT_CODE=$?
19+
set -e
20+
21+
echo $EXIT_CODE
22+
23+
if [[ $EXIT_CODE -ne 0 ]]; then
24+
# Strings generation finished with errors, extract the errors in an easy-to-find section
25+
echo "--- Report genstrings errors"
26+
ERRORS=errors.txt
27+
echo "Found errors when trying to run \`genstrings\` to generate the \`.strings\` files from \`*LocalizedStrings\` calls:" | tee $ERRORS
28+
echo '' >> $ERRORS
29+
# Print the errors inline.
30+
#
31+
# Notice the second `sed` call that removes the ANSI escape sequences that
32+
# Fastlane uses to color the output.
33+
grep -e "\[.*\].*genstrings:" $LOGS \
34+
| sed -e 's/\[.*\].*genstrings: error: /- /' \
35+
| sed -e $'s/\x1b\[[0-9;]*m//g' \
36+
| sort \
37+
| uniq \
38+
| tee -a $ERRORS
39+
# Annotate the build with the errors
40+
cat $ERRORS | buildkite-agent annotate --style error --context genstrings
41+
fi
42+
43+
exit $EXIT_CODE

.buildkite/pipeline.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,10 @@ steps:
123123
plugins: *common_plugins
124124
agents:
125125
queue: "android"
126+
# Runs the `.strings` generation automation to ensure all the
127+
# `LocalizedString` calls in the code can be correctly parsed by Apple's
128+
# `genstrings`.
129+
- label: "Lint Localized Strings Format"
130+
command: .buildkite/commands/lint-localized-strings-format.sh
131+
plugins: *common_plugins
132+
env: *common_env

fastlane/lanes/localization.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
#
124124
# @called_by complete_code_freeze
125125
#
126-
lane :generate_strings_file_for_glotpress do
126+
lane :generate_strings_file_for_glotpress do |options|
127127
cocoapods
128128

129129
wordpress_en_lproj = File.join('WordPress', 'Resources', 'en.lproj')
@@ -141,7 +141,7 @@
141141
destination: File.join(wordpress_en_lproj, 'Localizable.strings')
142142
)
143143

144-
git_commit(path: [wordpress_en_lproj], message: 'Update strings for localization', allow_nothing_to_commit: true)
144+
git_commit(path: [wordpress_en_lproj], message: 'Update strings for localization', allow_nothing_to_commit: true) unless options[:skip_commit]
145145
end
146146

147147

0 commit comments

Comments
 (0)