From cfb37f33e7b5c40786813c7bfdc6fd24bc676879 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Fri, 4 Feb 2022 13:32:55 +0100 Subject: [PATCH 01/13] Bumped to version 3.0.0 --- CHANGELOG.md | 22 +++++++++++++++---- Gemfile.lock | 6 ++--- .../plugin/wpmreleasetoolkit/version.rb | 2 +- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5865791db..155371180 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,13 +6,11 @@ ### Breaking Changes -* Removes the `drawText` binary from the gem (instead depending on it being installed via `brew`). Because this update can not be safely applied with no side effects, it's considered a breaking change. +_None_ ### New Features -* Introduce new `ios_merge_strings_files` action. [#329] -* Introduce new `buildkite_trigger_build` action. [#333] -* Introduce new `ios_download_strings_files_from_glotpress` action. [#331] +_None_ ### Bug Fixes @@ -20,6 +18,22 @@ _None_ ### Internal Changes +_None_ + +## 3.0.0 + +### Breaking Changes + +* Removes the `drawText` binary from the gem (instead depending on it being installed via `brew`). Because this update can not be safely applied with no side effects, it's considered a breaking change. + +### New Features + +* Introduce new `ios_merge_strings_files` action. [#329] +* Introduce new `buildkite_trigger_build` action. [#333] +* Introduce new `ios_download_strings_files_from_glotpress` action. [#331] + +### Internal Changes + * Ensure that the `gem push` step only runs on CI if lint, test and danger steps passed before it. [#325] * Rename internal `Ios::L10nHelper` to `Ios::L10nLinterHelper`. [#328] * Provide new `run_described_fastlane_action` to run Fastlane actions more thoroughly in unit tests [#330] diff --git a/Gemfile.lock b/Gemfile.lock index de48c7b22..5c56d12be 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - fastlane-plugin-wpmreleasetoolkit (2.3.0) + fastlane-plugin-wpmreleasetoolkit (3.0.0) activesupport (~> 5) bigdecimal (~> 1.4) buildkit (~> 1.4) @@ -270,7 +270,6 @@ GEM method_source (0.9.2) mini_magick (4.11.0) mini_mime (1.1.2) - mini_portile2 (2.6.1) minitest (5.14.4) molinillo (0.8.0) multi_json (1.15.0) @@ -280,8 +279,7 @@ GEM naturally (2.2.1) netrc (0.11.0) no_proxy_fix (0.1.2) - nokogiri (1.12.5) - mini_portile2 (~> 2.6.1) + nokogiri (1.12.5-x86_64-darwin) racc (~> 1.4) octokit (4.21.0) faraday (>= 0.9) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/version.rb b/lib/fastlane/plugin/wpmreleasetoolkit/version.rb index 9a0e67036..6604dad5a 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/version.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/version.rb @@ -1,5 +1,5 @@ module Fastlane module Wpmreleasetoolkit - VERSION = '2.3.0' + VERSION = '3.0.0' end end From ef0757827c4f569708ac7c5012f78a205e5719b5 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Fri, 4 Feb 2022 13:35:21 +0100 Subject: [PATCH 02/13] Add PR number for `drawText` removal changelog entry --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 155371180..be10617af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,7 +24,7 @@ _None_ ### Breaking Changes -* Removes the `drawText` binary from the gem (instead depending on it being installed via `brew`). Because this update can not be safely applied with no side effects, it's considered a breaking change. +* Removes the `drawText` binary from the gem (instead depending on it being installed via `brew`). Because this update can not be safely applied with no side effects, it's considered a breaking change. [#312] ### New Features From 8fa11ce6f53112489cada473462bd1089c082111 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Mon, 7 Feb 2022 08:43:27 +0100 Subject: [PATCH 03/13] Update `DEFAULT_GIT_BRANCH` from `develop` to `trunk` We're getting ready to ship a new major version, 3.0.0, which is the best time to introduce this breaking change, as the `TODO` comment suggested. See also: https://github.com/wordpress-mobile/release-toolkit/pull/334#issuecomment-1029969292 --- lib/fastlane/plugin/wpmreleasetoolkit/helper/git_helper.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/helper/git_helper.rb b/lib/fastlane/plugin/wpmreleasetoolkit/helper/git_helper.rb index 840b14bfc..662f16d8d 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/helper/git_helper.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/helper/git_helper.rb @@ -5,10 +5,8 @@ module Helper # Helper methods to execute git-related operations # module GitHelper - # Fallback default branch of the client repository. It's currently set to 'develop' for - # backwards compatibility. - # TODO: Set to 'trunk' for the next major release. - DEFAULT_GIT_BRANCH = 'develop'.freeze + # Fallback default branch of the client repository. + DEFAULT_GIT_BRANCH = 'trunk'.freeze # Checks if the given path, or current directory if no path is given, is # inside a Git repository From a748da6a247d3c63af3314ae743b1673c4e73fd9 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Mon, 7 Feb 2022 08:53:31 +0100 Subject: [PATCH 04/13] Remove custom check for CI in favor of using Fastlane's one --- .../plugin/wpmreleasetoolkit/models/file_reference.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/models/file_reference.rb b/lib/fastlane/plugin/wpmreleasetoolkit/models/file_reference.rb index 243517c33..ed23e3ffd 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/models/file_reference.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/models/file_reference.rb @@ -10,10 +10,7 @@ def initialize(params = {}) end def source_contents - # TODO: This works only on CircleCI. I chose this variable because it's the one checked by Fastlane::is_ci. - # Fastlane::is_ci doesn't work here, so reimplementing the code has been necessary. - # (This should be updated if we change CI or if fastlane is updated.) - return File.read(secrets_repository_file_path) unless self.encrypt || ENV.key?('CIRCLECI') + return File.read(secrets_repository_file_path) unless self.encrypt || FastlaneCore::Helper.is_ci? return nil unless File.file?(encrypted_file_path) encrypted = File.read(encrypted_file_path) From 8e535bdf276ea23955048c9b2c0a69b214cb3b80 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Mon, 7 Feb 2022 09:24:21 +0100 Subject: [PATCH 05/13] Add changelog entry for #335 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index be10617af..e221a6361 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ _None_ ### Breaking Changes * Removes the `drawText` binary from the gem (instead depending on it being installed via `brew`). Because this update can not be safely applied with no side effects, it's considered a breaking change. [#312] +* When doing Git operations, if no branch is provided, we'll use `trunk` as a default instead of `develop` [#335] ### New Features From 8702a9626a1fe994fdd02d4b8610f17b21e45c34 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Mon, 7 Feb 2022 09:33:07 +0100 Subject: [PATCH 06/13] Remove deprecated `android_merge_translators_strings` action I also verified that this wasn't used in WordPress, WooCommerce, or Simplenote. --- .../android_merge_translators_strings.rb | 106 ------------------ .../android_merge_translators_strings_spec.rb | 85 -------------- ...-merge-android-merge-overwrite-double.json | 21 ---- ...t-merge-android-merge-overwrite-fuzzy.json | 26 ----- .../test-merge-android-merge-overwrite.json | 21 ---- .../test-merge-android-merge-simple.json | 21 ---- .../test-merge-android-nomerge.json | 16 --- 7 files changed, 296 deletions(-) delete mode 100644 lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_merge_translators_strings.rb delete mode 100644 spec/android_merge_translators_strings_spec.rb delete mode 100644 spec/test-data/translations/test-merge-android-merge-overwrite-double.json delete mode 100644 spec/test-data/translations/test-merge-android-merge-overwrite-fuzzy.json delete mode 100644 spec/test-data/translations/test-merge-android-merge-overwrite.json delete mode 100644 spec/test-data/translations/test-merge-android-merge-simple.json delete mode 100644 spec/test-data/translations/test-merge-android-nomerge.json diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_merge_translators_strings.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_merge_translators_strings.rb deleted file mode 100644 index 06e3fb542..000000000 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_merge_translators_strings.rb +++ /dev/null @@ -1,106 +0,0 @@ -require 'fastlane/action' -require 'date' -require_relative '../../helper/github_helper' -require_relative '../../helper/ios/ios_version_helper' -require_relative '../../helper/android/android_version_helper' -module Fastlane - module Actions - class AndroidMergeTranslatorsStringsAction < Action - def self.run(params) - folder_path = File.expand_path(params[:strings_folder]) - - subfolders = Dir.entries(folder_path) - subfolders.each do |strings_folder| - merge_folder(File.join(folder_path, strings_folder)) if strings_folder.start_with?('values') - end - end - - def self.merge_folder(strings_folder) - main_file = File.join(strings_folder, 'strings.xml') - return unless File.exist?(main_file) - - UI.message("Merging in: #{strings_folder}") - - tmp_main_file = "#{main_file}.tmp" - FileUtils.cp(main_file, tmp_main_file) - - join_files = Dir.glob(File.join(strings_folder, 'strings-*.xml')) - extra_strings = [] - extra_keys = [] - join_files.each do |join_strings| - my_strings = File.read(join_strings).split("\n") - my_strings.each do |string| - if string.include?('').first - unless extra_keys.include?(string_key) - extra_strings << string - extra_keys << string_key - end - end - end - - File.delete(join_strings) - end - - File.open(main_file, 'w') do |f| - File.open(tmp_main_file).each do |line| - f.puts(extra_strings) if line.strip == '' - f.puts(check_line(line, extra_strings)) - end - end - - File.delete(tmp_main_file) - end - - def self.check_line(line, extra_strings) - return line unless line.include?('').first - extra_strings.each do |overwrite_string| - return '' if overwrite_string.strip.split('>').first == test_line - end - - return line - end - - def self.description - 'Merge strings for translators' - end - - def self.authors - ['Lorenzo Mattei'] - end - - def self.return_value - # If your method provides a return value, you can describe here what it does - end - - def self.details - # Optional: - 'Merges waiting and fuzzy strings into the main file for translators. This action is deprecated in favor of `android_download_translations`' - end - - def self.available_options - [ - FastlaneCore::ConfigItem.new(key: :strings_folder, - env_name: 'AMTS_STRING_FOLDER', - description: 'The folder that contains all the translations', - optional: false, - type: String), - ] - end - - def self.is_supported?(platform) - true - end - - def self.category - :deprecated - end - - def self.deprecated_notes - 'This action is deprecated in favor of `android_download_translations` (using an array for the status_filter parameter)' - end - end - end -end diff --git a/spec/android_merge_translators_strings_spec.rb b/spec/android_merge_translators_strings_spec.rb deleted file mode 100644 index e7695b7ae..000000000 --- a/spec/android_merge_translators_strings_spec.rb +++ /dev/null @@ -1,85 +0,0 @@ -require 'spec_helper' -require 'tmpdir' - -describe Fastlane::Actions::AndroidMergeTranslatorsStringsAction do - before do - @amtsTestUtils = AMTSTestUtils.new - @amtsTestUtils.create_test_folder - end - - it 'checks no merge' do - amts_run_test('test-merge-android-nomerge.json') - end - - it 'checks merge simple' do - amts_run_test('test-merge-android-merge-simple.json') - end - - it 'checks merge overwrite' do - amts_run_test('test-merge-android-merge-overwrite.json') - end - - it 'checks merge overwrite with double key in pending file' do - amts_run_test('test-merge-android-merge-overwrite-double.json') - end - - it 'checks merge overwrite with fuzzy strings' do - amts_run_test('test-merge-android-merge-overwrite-fuzzy.json') - end - - after do - @amtsTestUtils.delete_test_folder - end -end - -def amts_run_test(script) - test_script = @amtsTestUtils.get_test_from_file(script) - @amtsTestUtils.create_test_data(test_script) - run_described_fastlane_action(strings_folder: @amtsTestUtils.test_folder_path) - expect(@amtsTestUtils.read_result_data(test_script)).to eq(test_script['result']['content']) -end - -class AMTSTestUtils - attr_accessor :test_folder_path - - def initialize - @test_folder_path = File.join(Dir.tmpdir(), 'amts_tests') - end - - def create_test_folder - FileUtils.mkdir_p(@test_folder_path) - end - - def delete_test_folder - FileUtils.rm_rf(@test_folder_path) - end - - def get_test_from_file(filename) - filename = self.test_data_path_for("translations/#{filename}") - return JSON.parse(open(filename).read) - end - - def test_data_path_for(filename) - File.expand_path(File.join(File.dirname(__FILE__), 'test-data', filename)) - end - - def create_test_data(test_script) - test_script['test_data'].each do |test_file| - self.generate_test_file(test_file['file'], test_file['content']) - end - end - - def generate_test_file(filename, content) - file_path = File.join(@test_folder_path, filename) - - dir = File.dirname(file_path) - FileUtils.mkdir_p(dir) unless File.directory?(dir) - - File.open(file_path, 'w') { |f| f.write(content) } - end - - def read_result_data(test_script) - file_path = File.join(@test_folder_path, test_script['result']['file']) - return File.read(file_path) - end -end diff --git a/spec/test-data/translations/test-merge-android-merge-overwrite-double.json b/spec/test-data/translations/test-merge-android-merge-overwrite-double.json deleted file mode 100644 index 141109f78..000000000 --- a/spec/test-data/translations/test-merge-android-merge-overwrite-double.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "test_data": - [ - { - "file": "values/strings.xml", - "content": - "\n\n\tHello\n\tTest\n\tHi\n\n" - }, - { - "file": "values/strings-pending.xml", - "content": - "\n\n\tGoodbye\n\tTest_Overwrite\n\tTest_Overwrite2\n\n" - } - ], - "result": - { - "file": "values/strings.xml", - "content": - "\n\n\tHello\n\n\tHi\n\tGoodbye\n\tTest_Overwrite\n\n" - } -} \ No newline at end of file diff --git a/spec/test-data/translations/test-merge-android-merge-overwrite-fuzzy.json b/spec/test-data/translations/test-merge-android-merge-overwrite-fuzzy.json deleted file mode 100644 index dc39d7d89..000000000 --- a/spec/test-data/translations/test-merge-android-merge-overwrite-fuzzy.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "test_data": - [ - { - "file": "values/strings.xml", - "content": - "\n\n\tHello\n\tTest\n\tHi\n\n" - }, - { - "file": "values/strings-pending.xml", - "content": - "\n\n\tGoodbye\n\tTest_Overwrite\n\tTest_Overwrite2\n\n" - }, - { - "file": "values/strings-fuzzy.xml", - "content": - "\n\n\tHiFive\n\n" - } - ], - "result": - { - "file": "values/strings.xml", - "content": - "\n\n\tHello\n\n\tHi\n\tGoodbye\n\tTest_Overwrite\n\tHiFive\n\n" - } -} \ No newline at end of file diff --git a/spec/test-data/translations/test-merge-android-merge-overwrite.json b/spec/test-data/translations/test-merge-android-merge-overwrite.json deleted file mode 100644 index c889237b3..000000000 --- a/spec/test-data/translations/test-merge-android-merge-overwrite.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "test_data": - [ - { - "file": "values/strings.xml", - "content": - "\n\n\tHello\n\tTest\n\tHi\n\n" - }, - { - "file": "values/strings-pending.xml", - "content": - "\n\n\tGoodbye\n\tTest_Overwrite\n\n" - } - ], - "result": - { - "file": "values/strings.xml", - "content": - "\n\n\tHello\n\n\tHi\n\tGoodbye\n\tTest_Overwrite\n\n" - } -} \ No newline at end of file diff --git a/spec/test-data/translations/test-merge-android-merge-simple.json b/spec/test-data/translations/test-merge-android-merge-simple.json deleted file mode 100644 index 695ce9aac..000000000 --- a/spec/test-data/translations/test-merge-android-merge-simple.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "test_data": - [ - { - "file": "values/strings.xml", - "content": - "\n\n\tHello\n\tTest\n\tHi\n\n" - }, - { - "file": "values/strings-pending.xml", - "content": - "\n\n\tGoodbye\n\n" - } - ], - "result": - { - "file": "values/strings.xml", - "content": - "\n\n\tHello\n\tTest\n\tHi\n\tGoodbye\n\n" - } -} \ No newline at end of file diff --git a/spec/test-data/translations/test-merge-android-nomerge.json b/spec/test-data/translations/test-merge-android-nomerge.json deleted file mode 100644 index cc5b2a912..000000000 --- a/spec/test-data/translations/test-merge-android-nomerge.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "test_data": - [ - { - "file": "values/strings.xml", - "content": - "\n\n\tHello\n\tTest\n\tHi\n\n" - } - ], - "result": - { - "file": "values/strings.xml", - "content": - "\n\n\tHello\n\tTest\n\tHi\n\n" - } -} \ No newline at end of file From e75be80ac0cfc9f26e8ffb2ab258b0bc7df5e5ef Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Mon, 7 Feb 2022 09:40:25 +0100 Subject: [PATCH 07/13] Remove deprecated `ios_merge_translators_strings` action I verified that is not used in WordPress, WooCommerce, or Simplenote. Interestingly, neither is the suggested alternative, `ios_merge_strings_file`. --- .../ios/ios_merge_translators_strings.rb | 101 ------------------ spec/ios_merge_translators_strings_spec.rb | 85 --------------- ...test-merge-ios-merge-overwrite-double.json | 26 ----- .../test-merge-ios-merge-overwrite-fuzzy.json | 31 ------ .../test-merge-ios-merge-overwrite.json | 26 ----- .../test-merge-ios-merge-simple.json | 26 ----- .../translations/test-merge-ios-nomerge.json | 21 ---- 7 files changed, 316 deletions(-) delete mode 100644 lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_merge_translators_strings.rb delete mode 100644 spec/ios_merge_translators_strings_spec.rb delete mode 100644 spec/test-data/translations/test-merge-ios-merge-overwrite-double.json delete mode 100644 spec/test-data/translations/test-merge-ios-merge-overwrite-fuzzy.json delete mode 100644 spec/test-data/translations/test-merge-ios-merge-overwrite.json delete mode 100644 spec/test-data/translations/test-merge-ios-merge-simple.json delete mode 100644 spec/test-data/translations/test-merge-ios-nomerge.json diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_merge_translators_strings.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_merge_translators_strings.rb deleted file mode 100644 index c454857e0..000000000 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/ios/ios_merge_translators_strings.rb +++ /dev/null @@ -1,101 +0,0 @@ -require 'fastlane/action' -require 'date' -require_relative '../../helper/github_helper' -require_relative '../../helper/ios/ios_version_helper' -module Fastlane - module Actions - class IosMergeTranslatorsStringsAction < Action - def self.run(params) - folder_path = File.expand_path(params[:strings_folder]) - - subfolders = Dir.entries(folder_path) - subfolders.each do |strings_folder| - merge_folder(File.join(folder_path, strings_folder)) if strings_folder.ends_with?('.lproj') - end - end - - def self.merge_folder(strings_folder) - main_file = File.join(strings_folder, 'Localizable.strings') - tmp_main_file = File.join(strings_folder, 'Localizable_current.strings') - return unless File.exist?(main_file) && File.exist?(tmp_main_file) - - UI.message("Merging in: #{strings_folder}") - - join_files = Dir.glob(File.join(strings_folder, 'Localizable_*.strings')) - [tmp_main_file] - extra_strings = [] - extra_keys = [] - join_files.each do |join_strings| - my_strings = File.read(join_strings).split("\n") - my_strings.each do |string| - if string[/^"(.*)" = "(.*)";$/] - /^"(?.*)" = "/i =~ string - unless extra_keys.include?(string_key) - extra_strings << string - extra_keys << string_key - end - end - end - - File.delete(join_strings) - end - - File.open(main_file, 'w') do |f| - File.open(tmp_main_file).each do |line| - f.puts(check_line(line, extra_keys)) - end - f.puts(extra_strings) - end - - File.delete(tmp_main_file) - end - - def self.check_line(line, extra_keys) - return line unless line[/^"(.*)" = "(.*)";$/] - - /^"(?.*)" = "/i =~ line - return '' if extra_keys.include?(line_key) - - return line - end - - def self.description - 'Merge strings for translators' - end - - def self.authors - ['Lorenzo Mattei'] - end - - def self.return_value - # If your method provides a return value, you can describe here what it does - end - - def self.details - # Optional: - 'Merges waiting and fuzzy strings into the main file for translators' - end - - def self.available_options - [ - FastlaneCore::ConfigItem.new(key: :strings_folder, - env_name: 'IMTS_STRING_FOLDER', - description: 'The folder that contains all the translations', - optional: false, - type: String), - ] - end - - def self.category - :deprecated - end - - def self.deprecated_notes - 'This action is deprecated. For a similar feature, you might want to check `ios_merge_strings_file` instead' - end - - def self.is_supported?(platform) - :ios - end - end - end -end diff --git a/spec/ios_merge_translators_strings_spec.rb b/spec/ios_merge_translators_strings_spec.rb deleted file mode 100644 index 4ae829f8f..000000000 --- a/spec/ios_merge_translators_strings_spec.rb +++ /dev/null @@ -1,85 +0,0 @@ -require 'spec_helper' -require 'tmpdir' - -describe Fastlane::Actions::IosMergeTranslatorsStringsAction do - before do - @imtsTestUtils = IMTSTestUtils.new - @imtsTestUtils.create_test_folder - end - - it 'checks no merge' do - imts_run_test('test-merge-ios-nomerge.json') - end - - it 'checks merge simple' do - imts_run_test('test-merge-ios-merge-simple.json') - end - - it 'checks merge overwrite' do - imts_run_test('test-merge-ios-merge-overwrite.json') - end - - it 'checks merge overwrite with double key in pending file' do - imts_run_test('test-merge-ios-merge-overwrite-double.json') - end - - it 'checks merge overwrite with fuzzy strings' do - imts_run_test('test-merge-ios-merge-overwrite-fuzzy.json') - end - - after do - @imtsTestUtils.delete_test_folder - end -end - -def imts_run_test(script) - test_script = @imtsTestUtils.get_test_from_file(script) - @imtsTestUtils.create_test_data(test_script) - run_described_fastlane_action(strings_folder: @imtsTestUtils.test_folder_path) - expect(@imtsTestUtils.read_result_data(test_script)).to eq(test_script['result']['content']) -end - -class IMTSTestUtils - attr_accessor :test_folder_path - - def initialize - @test_folder_path = File.join(Dir.tmpdir(), 'imts_tests') - end - - def create_test_folder - FileUtils.mkdir_p(@test_folder_path) - end - - def delete_test_folder - FileUtils.rm_rf(@test_folder_path) - end - - def get_test_from_file(filename) - filename = self.test_data_path_for("translations/#{filename}") - return JSON.parse(open(filename).read) - end - - def test_data_path_for(filename) - File.expand_path(File.join(File.dirname(__FILE__), 'test-data', filename)) - end - - def create_test_data(test_script) - test_script['test_data'].each do |test_file| - self.generate_test_file(test_file['file'], test_file['content']) - end - end - - def generate_test_file(filename, content) - file_path = File.join(@test_folder_path, filename) - - dir = File.dirname(file_path) - FileUtils.mkdir_p(dir) unless File.directory?(dir) - - File.open(file_path, 'w') { |f| f.write(content) } - end - - def read_result_data(test_script) - file_path = File.join(@test_folder_path, test_script['result']['file']) - return File.read(file_path) - end -end diff --git a/spec/test-data/translations/test-merge-ios-merge-overwrite-double.json b/spec/test-data/translations/test-merge-ios-merge-overwrite-double.json deleted file mode 100644 index de5848e90..000000000 --- a/spec/test-data/translations/test-merge-ios-merge-overwrite-double.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "test_data": - [ - { - "file": "en.lproj/Localizable.strings", - "content": - "/* Translation-Revision-Date: Initial comment */\n" - }, - { - "file": "en.lproj/Localizable_current.strings", - "content": - "/* Translation-Revision-Date: Initial comment */\n\"string 1\" = \"String 1\";\n\"string 2\" = \"String 2\";\n\"string 3\" = \"String 3\";\n" - }, - { - "file": "en.lproj/Localizable_pending.strings", - "content": - "/* Translation-Revision-Date: Initial comment */\n\"string goodbye\" = \"String GoodBye\";\n\"string 2\" = \"Test\";\n\"string 2\" = \"Test Overwrite 2\";\n" - } - ], - "result": - { - "file": "en.lproj/Localizable.strings", - "content": - "/* Translation-Revision-Date: Initial comment */\n\"string 1\" = \"String 1\";\n\n\"string 3\" = \"String 3\";\n\"string goodbye\" = \"String GoodBye\";\n\"string 2\" = \"Test\";\n" - } -} \ No newline at end of file diff --git a/spec/test-data/translations/test-merge-ios-merge-overwrite-fuzzy.json b/spec/test-data/translations/test-merge-ios-merge-overwrite-fuzzy.json deleted file mode 100644 index 38afd5f92..000000000 --- a/spec/test-data/translations/test-merge-ios-merge-overwrite-fuzzy.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "test_data": - [ - { - "file": "en.lproj/Localizable.strings", - "content": - "/* Translation-Revision-Date: Initial comment */\n" - }, - { - "file": "en.lproj/Localizable_current.strings", - "content": - "/* Translation-Revision-Date: Initial comment */\n\"string 1\" = \"String 1\";\n\"string 2\" = \"String 2\";\n\"string 3\" = \"String 3\";\n" - }, - { - "file": "en.lproj/Localizable_pending.strings", - "content": - "/* Translation-Revision-Date: Initial comment */\n\"string goodbye\" = \"String GoodBye\";\n\"string 2\" = \"Test\";\n\"string 2\" = \"Test Overwrite 2\";\n" - }, - { - "file": "en.lproj/Localizable_fuzzy.strings", - "content": - "/* Translation-Revision-Date: Initial comment */\n\"string highfive\" = \"String HigFive\";\n" - } - ], - "result": - { - "file": "en.lproj/Localizable.strings", - "content": - "/* Translation-Revision-Date: Initial comment */\n\"string 1\" = \"String 1\";\n\n\"string 3\" = \"String 3\";\n\"string highfive\" = \"String HigFive\";\n\"string goodbye\" = \"String GoodBye\";\n\"string 2\" = \"Test\";\n" - } -} \ No newline at end of file diff --git a/spec/test-data/translations/test-merge-ios-merge-overwrite.json b/spec/test-data/translations/test-merge-ios-merge-overwrite.json deleted file mode 100644 index e5613ca13..000000000 --- a/spec/test-data/translations/test-merge-ios-merge-overwrite.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "test_data": - [ - { - "file": "en.lproj/Localizable.strings", - "content": - "/* Translation-Revision-Date: Initial comment */\n" - }, - { - "file": "en.lproj/Localizable_current.strings", - "content": - "/* Translation-Revision-Date: Initial comment */\n\"string 1\" = \"String 1\";\n\"string 2\" = \"String 2\";\n\"string 3\" = \"String 3\";\n" - }, - { - "file": "en.lproj/Localizable_pending.strings", - "content": - "/* Translation-Revision-Date: Initial comment */\n\"string goodbye\" = \"String GoodBye\";\n\"string 2\" = \"Test\";\n" - } - ], - "result": - { - "file": "en.lproj/Localizable.strings", - "content": - "/* Translation-Revision-Date: Initial comment */\n\"string 1\" = \"String 1\";\n\n\"string 3\" = \"String 3\";\n\"string goodbye\" = \"String GoodBye\";\n\"string 2\" = \"Test\";\n" - } -} \ No newline at end of file diff --git a/spec/test-data/translations/test-merge-ios-merge-simple.json b/spec/test-data/translations/test-merge-ios-merge-simple.json deleted file mode 100644 index 4a2ec1935..000000000 --- a/spec/test-data/translations/test-merge-ios-merge-simple.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "test_data": - [ - { - "file": "en.lproj/Localizable.strings", - "content": - "/* Translation-Revision-Date: Initial comment */\n" - }, - { - "file": "en.lproj/Localizable_current.strings", - "content": - "/* Translation-Revision-Date: Initial comment */\n\t\"string 1\" = \"String 1\";\n\t\"string 2\" = \"String 2\";\n\t\"string 3\" = \"String 3\";\n" - }, - { - "file": "en.lproj/Localizable_pending.strings", - "content": - "/* Translation-Revision-Date: Initial comment */\n\"string goodbye\" = \"String GoodBye\";\n" - } - ], - "result": - { - "file": "en.lproj/Localizable.strings", - "content": - "/* Translation-Revision-Date: Initial comment */\n\t\"string 1\" = \"String 1\";\n\t\"string 2\" = \"String 2\";\n\t\"string 3\" = \"String 3\";\n\"string goodbye\" = \"String GoodBye\";\n" - } -} \ No newline at end of file diff --git a/spec/test-data/translations/test-merge-ios-nomerge.json b/spec/test-data/translations/test-merge-ios-nomerge.json deleted file mode 100644 index 9ab105e64..000000000 --- a/spec/test-data/translations/test-merge-ios-nomerge.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "test_data": - [ - { - "file": "en.lproj/Localizable.strings", - "content": - "/* Translation-Revision-Date: Initial comment */\n" - }, - { - "file": "en.lproj/Localizable_current.strings", - "content": - "/* Translation-Revision-Date: Initial commend */\n\t\"string 1\" = \"String 1\";\n\t\"string 2\" = \"String 2\";\n\t\"string 3\" = \"String 3\";\n" - } - ], - "result": - { - "file": "en.lproj/Localizable.strings", - "content": - "/* Translation-Revision-Date: Initial commend */\n\t\"string 1\" = \"String 1\";\n\t\"string 2\" = \"String 2\";\n\t\"string 3\" = \"String 3\";\n" - } -} \ No newline at end of file From fdff3eab98274c1d4165b3c8cf7d01667f3a4fe1 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Mon, 7 Feb 2022 09:48:41 +0100 Subject: [PATCH 08/13] Remove deprecated `android_update_metadata` action Currently only used in Simplenote Android, which is on pause. See https://github.com/Automattic/simplenote-android/blob/ca4c775cf62dd0f3178e50564d8d4a17d17408ef/fastlane/Fastfile#L199 --- .../android/android_update_metadata.rb | 52 ------------------- 1 file changed, 52 deletions(-) delete mode 100644 lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_update_metadata.rb diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_update_metadata.rb b/lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_update_metadata.rb deleted file mode 100644 index d0d4176e6..000000000 --- a/lib/fastlane/plugin/wpmreleasetoolkit/actions/android/android_update_metadata.rb +++ /dev/null @@ -1,52 +0,0 @@ -module Fastlane - module Actions - module SharedValues - ANDROID_UPDATE_METADATA_CUSTOM_VALUE = :ANDROID_UPDATE_METADATA_CUSTOM_VALUE - end - - class AndroidUpdateMetadataAction < Action - def self.run(params) - require_relative '../../helper/android/android_git_helper' - - Fastlane::Helper::Android::GitHelper.update_metadata(ENV['validate_translations']) - end - - ##################################################### - # @!group Documentation - ##################################################### - - def self.description - 'Downloads translated metadata from the translation system' - end - - def self.details - 'Downloads translated metadata from the translation system. This action is deprecated in favor of `android_download_translations`' - end - - def self.available_options - end - - def self.output - end - - def self.return_value - end - - def self.authors - ['loremattei'] - end - - def self.is_supported?(platform) - platform == :android - end - - def self.category - :deprecated - end - - def self.deprecated_notes - 'This action is deprecated in favor of `android_download_translations`' - end - end - end -end From fdc15c4a0972bfb997d613d0327c042ae25a6966 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Mon, 7 Feb 2022 10:08:49 +0100 Subject: [PATCH 09/13] Add changelog entry regarding deprecation removals --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e221a6361..4537dbeda 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ _None_ * Removes the `drawText` binary from the gem (instead depending on it being installed via `brew`). Because this update can not be safely applied with no side effects, it's considered a breaking change. [#312] * When doing Git operations, if no branch is provided, we'll use `trunk` as a default instead of `develop` [#335] +* Remove deprecated `android_merge_translators_strings`, `android_update_metadata`, and `ios_merge_translators_strings` actions [#337] ### New Features From 1f5754239f27b800237296a2e05ec032a5f1d6fd Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Mon, 7 Feb 2022 10:24:23 +0100 Subject: [PATCH 10/13] Account for `FastlaneCore::Helper:is_ci?` usage in tests --- spec/file_reference_spec.rb | 14 ++++++-------- spec/spec_helper.rb | 18 ------------------ 2 files changed, 6 insertions(+), 26 deletions(-) diff --git a/spec/file_reference_spec.rb b/spec/file_reference_spec.rb index 92eb9793b..357f97325 100644 --- a/spec/file_reference_spec.rb +++ b/spec/file_reference_spec.rb @@ -69,19 +69,17 @@ describe '#source_contents' do it 'gets the contents from the secrets repo' do - set_circle_env(false) do - allow(File).to receive(:read).with(subject.secrets_repository_file_path).and_return('source contents') - expect(subject.source_contents).to eq('source contents') - end + allow(FastlaneCore::Helper).to receive(:is_ci?).and_return(false) + allow(File).to receive(:read).with(subject.secrets_repository_file_path).and_return('source contents') + expect(subject.source_contents).to eq('source contents') end end describe '#source_contents on ci' do it 'gets the contents from the secrets repo' do - set_circle_env(true) do - allow(File).to receive(:read).with(subject.secrets_repository_file_path).and_return('source contents') - expect(subject.source_contents).to eq(nil) - end + allow(FastlaneCore::Helper).to receive(:is_ci?).and_return(true) + allow(File).to receive(:read).with(subject.secrets_repository_file_path).and_return('source contents') + expect(subject.source_contents).to eq(nil) end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 8bc4ad62d..10b24d2b4 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -25,24 +25,6 @@ module SpecHelper config.filter_run_when_matching :focus end -def set_circle_env(define_ci) - is_ci = ENV.key?('CIRCLECI') - orig_circle_ci = ENV['CIRCLECI'] - if define_ci - ENV['CIRCLECI'] = 'true' - else - ENV.delete 'CIRCLECI' - end - - yield -ensure - if is_ci - ENV['CIRCLECI'] = orig_circle_ci - else - ENV.delete 'CIRCLECI' - end -end - # Allows Action.sh to be executed even when running in a test environment (where Fastlane's code disables it by default) # def allow_fastlane_action_sh From fa390b6bfa4688c649f9032586ae2b7871372ea2 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Tue, 8 Feb 2022 11:24:32 +0100 Subject: [PATCH 11/13] Remove unused method associated with removed `ios_localize_project` --- .../helper/ios/ios_git_helper.rb | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_git_helper.rb b/lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_git_helper.rb index 01909b8c1..80898348b 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_git_helper.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_git_helper.rb @@ -28,23 +28,6 @@ def self.commit_version_bump(include_deliverfile: true, include_metadata: true) Fastlane::Helper::GitHelper.commit(message: 'Bump version number', files: files_list, push: true) end - # Calls the `Scripts/localize.py` script in the project root folder and push the `*.strings` files - # - # That script updates the `.strings` files with translations from GlotPress. - # - # @env PROJECT_ROOT_FOLDER The path to the git root of the project - # @env PROJECT_NAME The name of the directory containing the project code (especially containing the `build.gradle` file) - # - # @deprecated This method is only used by the `ios_localize_project` action, which is itself deprecated - # in favor of the new `ios_generate_strings_file_from_code` action - # @todo [Next Major] Remove this method once we fully remove `ios_localize_project` - # - def self.localize_project - Action.sh("cd #{get_from_env!(key: 'PROJECT_ROOT_FOLDER')} && ./Scripts/localize.py") - - Fastlane::Helper::GitHelper.commit(message: 'Update strings for localization', files: strings_files, push: true) || UI.message('No new strings, skipping commit') - end - # Call the `Scripts/update-translations.rb` then the `fastlane/download_metadata` Scripts from the host project folder # # @env PROJECT_ROOT_FOLDER The path to the git root of the project From fae13ff5e44a2eb173da48bcafe7a9a8c2255b1e Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Tue, 8 Feb 2022 11:29:43 +0100 Subject: [PATCH 12/13] Remove unused method associated with `android_update_metadata` --- .../helper/android/android_git_helper.rb | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/helper/android/android_git_helper.rb b/lib/fastlane/plugin/wpmreleasetoolkit/helper/android/android_git_helper.rb index 33dad2971..d9768e830 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/helper/android/android_git_helper.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/helper/android/android_git_helper.rb @@ -27,26 +27,6 @@ def self.commit_version_bump ) end end - - # Calls the `tools/update-translations.sh` script from the project repo, then lint them using the provided gradle task - # - # Deprecated. Use the `android_download_translations` action instead. - # - # @env PROJECT_ROOT_FOLDER The path to the git root of the project - # @env PROJECT_NAME The name of the directory containing the project code (especially containing the `build.gradle` file) - # - # @param [String] validate_translation_command The name of the gradle task to run to validate the translations - # - # @todo Remove this once every client has migrated to `android_download_translations` and we got rid of that legacy action. - # - def self.update_metadata(validate_translation_command) - Action.sh('./tools/update-translations.sh') - Action.sh('git', 'submodule', 'update', '--init', '--recursive') - Action.sh('./gradlew', validate_translation_command) - - res_dir = File.join(ENV['PROJECT_ROOT_FOLDER'], ENV['PROJECT_NAME'], 'src', 'main', 'res') - Fastlane::Helper::GitHelper.commit(message: 'Update translations', files: res_dir, push: true) - end end end end From ac57799b9454b0dcb9c11c05fc82ad944bdd8390 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Tue, 8 Feb 2022 20:08:07 +0100 Subject: [PATCH 13/13] Revert "Remove unused method associated with removed `ios_localize_project`" This reverts commit fa390b6bfa4688c649f9032586ae2b7871372ea2. --- .../helper/ios/ios_git_helper.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_git_helper.rb b/lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_git_helper.rb index 80898348b..01909b8c1 100644 --- a/lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_git_helper.rb +++ b/lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_git_helper.rb @@ -28,6 +28,23 @@ def self.commit_version_bump(include_deliverfile: true, include_metadata: true) Fastlane::Helper::GitHelper.commit(message: 'Bump version number', files: files_list, push: true) end + # Calls the `Scripts/localize.py` script in the project root folder and push the `*.strings` files + # + # That script updates the `.strings` files with translations from GlotPress. + # + # @env PROJECT_ROOT_FOLDER The path to the git root of the project + # @env PROJECT_NAME The name of the directory containing the project code (especially containing the `build.gradle` file) + # + # @deprecated This method is only used by the `ios_localize_project` action, which is itself deprecated + # in favor of the new `ios_generate_strings_file_from_code` action + # @todo [Next Major] Remove this method once we fully remove `ios_localize_project` + # + def self.localize_project + Action.sh("cd #{get_from_env!(key: 'PROJECT_ROOT_FOLDER')} && ./Scripts/localize.py") + + Fastlane::Helper::GitHelper.commit(message: 'Update strings for localization', files: strings_files, push: true) || UI.message('No new strings, skipping commit') + end + # Call the `Scripts/update-translations.rb` then the `fastlane/download_metadata` Scripts from the host project folder # # @env PROJECT_ROOT_FOLDER The path to the git root of the project