-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate
generate_release
command to new tool (#543)
### TL;DR Migrated `generate_release` command from old tool version. It takes ~40s to run for all locales on my machine. ### What changed? - Added a new `GenerateReleaseCommand` that orchestrates the release process - Introduced a new CLI command `release` with options for version and locales - Enhanced error handling in the base Command class - Added helper methods for version file path and locale detection - Updated the distribution generation to use consistent version file paths ### How to test? 1. Run `product_taxonomy release --version=YYYY-MM` 2. Verify that: - Distribution files are generated - Documentation is updated - VERSION file contains the new version - Git tag is created - README badge is updated with the new version 3. Run with `--locales=all` to test multi-locale generation Sample command output: ``` ❯ bin/product_taxonomy release --version=2025-01 --locales=all Generating release for version: 2025-01 Generating distribution files... Version: 2025-01 Locales: bg-BG, cs, da, de, el, en, es, fi, fr, hr-HR, hu, id-ID, it, ja, ko, lt-LT, nb, nl, pl, pt-BR, pt-PT, ro-RO, ru, sk-SK, sl-SI, sv, th, tr, vi, zh-CN, zh-TW Validating localizations Generating files for bg-BG Generating files for cs Generating files for da Generating files for de Generating files for el Generating files for en Generating files for es Generating files for fi Generating files for fr Generating files for hr-HR Generating files for hu Generating files for id-ID Generating files for it Generating files for ja Generating files for ko Generating files for lt-LT Generating files for nb Generating files for nl Generating files for pl Generating files for pt-BR Generating files for pt-PT Generating files for ro-RO Generating files for ru Generating files for sk-SK Generating files for sl-SI Generating files for sv Generating files for th Generating files for tr Generating files for vi Generating files for zh-CN Generating files for zh-TW Generating integration mappings for google/2021-09-21 Generating integration mappings for shopify/2022-02 Generating integration mappings for shopify/2024-07 Generating integration mappings for shopify/2024-10 Generating documentation files... Version: 2025-01 Generating sibling groups... Generating category search index... Generating attributes... Generating mappings... Generating attributes with categories... Generating attribute with categories search index... Generating release folder... Generating index.html... Generating attributes.html... Updating VERSION file... Creating git tag... Updating README.md... Completed in 38.7 seconds ```
- Loading branch information
Showing
6 changed files
with
147 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
dev/lib/product_taxonomy/commands/generate_release_command.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# frozen_string_literal: true | ||
|
||
module ProductTaxonomy | ||
class GenerateReleaseCommand < Command | ||
def initialize(options) | ||
super | ||
|
||
@version = options[:version] || File.read(version_file_path).strip | ||
@locales = if options[:locales] == ["all"] | ||
locales_defined_in_data_path | ||
else | ||
options[:locales] | ||
end | ||
end | ||
|
||
def execute | ||
logger.info("Generating release for version: #{@version}") | ||
|
||
logger.info("Generating distribution files...") | ||
GenerateDistCommand.new(version: @version, locales: @locales).execute | ||
|
||
logger.info("Generating documentation files...") | ||
GenerateDocsCommand.new(version: @version, locales: @locales).execute | ||
|
||
logger.info("Updating VERSION file...") | ||
File.write(version_file_path, @version) | ||
|
||
logger.info("Creating git tag...") | ||
system("git", "tag", "v#{@version}") | ||
|
||
logger.info("Updating README.md...") | ||
update_readme | ||
end | ||
|
||
private | ||
|
||
def update_readme | ||
readme_path = File.expand_path("../dist/README.md", ProductTaxonomy.data_path) | ||
content = File.read(readme_path) | ||
content.gsub!(%r{badge/Version-.*?-blue\.svg}) do | ||
badge_version = @version.gsub("-", "--") | ||
"badge/Version-#{badge_version}-blue.svg" | ||
end | ||
File.write(readme_path, content) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# frozen_string_literal: true | ||
|
||
require "test_helper" | ||
require "tmpdir" | ||
|
||
module ProductTaxonomy | ||
class GenerateReleaseCommandTest < TestCase | ||
setup do | ||
@tmp_base_path = Dir.mktmpdir | ||
@version = "2024-01" | ||
@version_file_path = File.expand_path("VERSION", @tmp_base_path) | ||
|
||
# Create test files and directories | ||
FileUtils.mkdir_p(File.expand_path("dist", @tmp_base_path)) | ||
File.write(@version_file_path, "2023-12") | ||
File.write( | ||
File.expand_path("dist/README.md", @tmp_base_path), | ||
'<img src="https://img.shields.io/badge/Version-2023--12-blue.svg" alt="Version">', | ||
) | ||
|
||
# Stub dependencies | ||
Command.any_instance.stubs(:version_file_path).returns(@version_file_path) | ||
Command.any_instance.stubs(:load_taxonomy) | ||
GenerateDistCommand.any_instance.stubs(:execute) | ||
GenerateDocsCommand.any_instance.stubs(:execute) | ||
ProductTaxonomy.stubs(:data_path).returns("#{@tmp_base_path}/data") | ||
end | ||
|
||
teardown do | ||
FileUtils.remove_entry(@tmp_base_path) | ||
end | ||
|
||
test "initialize sets version from options if provided" do | ||
command = GenerateReleaseCommand.new(version: @version) | ||
assert_equal @version, command.instance_variable_get(:@version) | ||
end | ||
|
||
test "initialize reads version from file if not provided in options" do | ||
command = GenerateReleaseCommand.new({}) | ||
assert_equal "2023-12", command.instance_variable_get(:@version) | ||
end | ||
|
||
test "initialize sets all locales when 'all' is specified" do | ||
Command.any_instance.stubs(:locales_defined_in_data_path).returns(["en", "fr", "es"]) | ||
command = GenerateReleaseCommand.new(locales: ["all"]) | ||
assert_equal ["en", "fr", "es"], command.instance_variable_get(:@locales) | ||
end | ||
|
||
test "initialize sets specific locales when provided" do | ||
command = GenerateReleaseCommand.new(locales: ["en", "fr"]) | ||
assert_equal ["en", "fr"], command.instance_variable_get(:@locales) | ||
end | ||
|
||
test "execute performs all required steps in order" do | ||
command = GenerateReleaseCommand.new(version: @version, locales: ["en"]) | ||
|
||
# Set up expectations | ||
GenerateDistCommand.any_instance.expects(:execute) | ||
GenerateDocsCommand.any_instance.expects(:execute) | ||
command.expects(:system).with("git", "tag", "v#{@version}") | ||
|
||
command.execute | ||
|
||
# Verify VERSION file was updated | ||
assert_equal @version, File.read(@version_file_path) | ||
end | ||
|
||
test "execute updates README.md version badge" do | ||
command = GenerateReleaseCommand.new(version: @version) | ||
|
||
command.execute | ||
|
||
readme_content = File.read(File.expand_path("dist/README.md", @tmp_base_path)) | ||
assert_equal '<img src="https://img.shields.io/badge/Version-2024--01-blue.svg" alt="Version">', readme_content | ||
end | ||
end | ||
end |