Skip to content

Commit

Permalink
Merge pull request wordpress-mobile#21058 from wordpress-mobile/iangm…
Browse files Browse the repository at this point in the history
…aia/extract-gradle-task-from-release-task

[Tooling] Move locales validation to the main lint task
  • Loading branch information
iangmaia authored Jul 17, 2024
2 parents 314098f + 7a0868b commit 3bb4ba4
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .buildkite/beta-builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ steps:
- label: "🕵️ Lint WordPress"
key: wplint
command: ".buildkite/commands/lint.sh wordpress"
plugins: [$CI_TOOLKIT]
artifact_paths:
- "**/build/reports/lint-results*.*"

- label: "🕵️ Lint Jetpack"
key: jplint
command: ".buildkite/commands/lint.sh jetpack"
plugins: [$CI_TOOLKIT]
artifact_paths:
- "**/build/reports/lint-results*.*"

Expand Down
10 changes: 9 additions & 1 deletion .buildkite/commands/lint.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
#!/bin/bash -eu

echo "--- :microscope: Linting"
echo "--- :rubygems: Setting up Gems"
install_gems

echo "--- :clipboard: Copying gradle.properties"
cp gradle.properties-example gradle.properties

echo "--- :globe_with_meridians: Check Locales Declaration Consistency"
bundle exec fastlane check_declared_locales_consistency app:"$1"

echo "--- :microscope: Linting"

if [ "$1" = "wordpress" ]; then
./gradlew lintWordpressVanillaRelease
exit 0
Expand Down
2 changes: 2 additions & 0 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ steps:

- label: "🕵️ Lint WordPress"
command: ".buildkite/commands/lint.sh wordpress"
plugins: [$CI_TOOLKIT]
artifact_paths:
- "**/build/reports/lint-results*.*"

- label: "🕵️ Lint Jetpack"
command: ".buildkite/commands/lint.sh jetpack"
plugins: [$CI_TOOLKIT]
artifact_paths:
- "**/build/reports/lint-results*.*"

Expand Down
6 changes: 4 additions & 2 deletions .buildkite/release-builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,22 @@ steps:
key: wplint
command: ".buildkite/commands/lint.sh wordpress"
priority: 1
plugins: [$CI_TOOLKIT]
artifact_paths:
- "**/build/reports/lint-results*.*"

- label: "🕵️ Lint Jetpack"
key: jplint
command: ".buildkite/commands/lint.sh jetpack"
priority: 1
plugins: [$CI_TOOLKIT]
artifact_paths:
- "**/build/reports/lint-results*.*"

#################
# Beta Builds
# Release Builds
#################
- group: "🚀 Beta Builds"
- group: "🚀 Release Builds"
steps:

- label: ":wordpress: :android: Release Build"
Expand Down
21 changes: 10 additions & 11 deletions fastlane/lanes/localization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -337,15 +337,13 @@
#####################################################################################
lane :download_translations do
# WordPress strings
check_declared_locales_consistency(app_flavor: 'wordpress', locales_list: WP_APP_LOCALES)
android_download_translations(
res_dir: File.join('WordPress', 'src', 'main', 'res'),
glotpress_url: APP_SPECIFIC_VALUES[:wordpress][:glotpress_appstrings_project],
locales: WP_APP_LOCALES
)

# Jetpack strings
check_declared_locales_consistency(app_flavor: 'jetpack', locales_list: JP_APP_LOCALES)
android_download_translations(
res_dir: File.join('WordPress', 'src', 'jetpack', 'res'),
glotpress_url: APP_SPECIFIC_VALUES[:jetpack][:glotpress_appstrings_project],
Expand All @@ -372,28 +370,29 @@ def update_po_file_for_metadata_localization(po_path:, sources:, release_version
# Compares the list of locales declared in the `resourceConfigurations` field of `build.gradle` for a given flavor
# with the hardcoded list of locales we use in our Fastlane lanes, to ensure they match and we are consistent.
#
# @param [String] app_flavor `"wordpress"` or `"jetpack"` — The `productFlavor` to read from in the build.gradle
# @param [Array<Hash>] locales_list The list of Hash defining the locales to compare that list to.
# Typically one of the `WP_APP_LOCALES` or `JP_APP_LOCALES` constants
def check_declared_locales_consistency(app_flavor:, locales_list:)
# @param [String] app `"wordpress"` or `"jetpack"` — The `productFlavor` to read from in the build.gradle
lane :check_declared_locales_consistency do |app:|
validate_app_name!(app)

output = gradle(task: 'printResourceConfigurations', flags: '--quiet')
resource_configs = output.match(/^#{app_flavor}: \[(.*)\]$/)&.captures&.first&.gsub(' ', '')&.split(',')&.sort
resource_configs = output.match(/^#{app}: \[(.*)\]$/)&.captures&.first&.gsub(' ', '')&.split(',')&.sort
if resource_configs.nil? || resource_configs.empty?
UI.message("No `resourceConfigurations` field set in `build.gradle` for the `#{app_flavor}` flavor. Nothing to check.")
return
UI.message("No `resourceConfigurations` field set in `build.gradle` for the `#{app}` flavor. Nothing to check.")
next
end

locales_list = { 'wordpress' => WP_APP_LOCALES, 'jetpack' => JP_APP_LOCALES }.fetch(app, nil)
expected_locales = locales_list.map { |l| l[:android] }
# Support for legacy locale codes
expected_locales << 'in' if expected_locales.include?('id')
expected_locales << 'iw' if expected_locales.include?('he')
expected_locales.sort!

if resource_configs == expected_locales
UI.message("The `resourceConfigurations` field set in `build.gradle` for the `#{app_flavor}` flavor matches what is set in our Fastfile. All is good!")
UI.message("The `resourceConfigurations` field set in `build.gradle` for the `#{app}` flavor matches what is set in our Fastfile. All is good!")
else
UI.user_error! <<~ERROR
The list of `resourceConfigurations` declared in your `build.gradle` for the `#{app_flavor}` flavor
The list of `resourceConfigurations` declared in your `build.gradle` for the `#{app}` flavor
does not match the list of locales we hardcoded in the `fastlane/lanes/localization.rb` for this app.
If you recently updated the hardcoded list of locales to include for this app, be sure to apply those
Expand Down
6 changes: 5 additions & 1 deletion fastlane/lanes/release.rb
Original file line number Diff line number Diff line change
Expand Up @@ -482,9 +482,13 @@
#####################################################################################
def get_app_name_option!(options)
app = options[:app]&.downcase
validate_app_name!(app)
app
end

def validate_app_name!(app)
UI.user_error!("Missing 'app' parameter. Expected 'app:wordpress' or 'app:jetpack'") if app.nil?
UI.user_error!("Invalid 'app' parameter #{app.inspect}. Expected 'wordpress' or 'jetpack'") unless %i[wordpress jetpack].include?(app.to_sym)
app
end

def release_notes_path(app)
Expand Down

0 comments on commit 3bb4ba4

Please sign in to comment.