-
Notifications
You must be signed in to change notification settings - Fork 22
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
- Loading branch information
1 parent
db61e20
commit 3b0c9b1
Showing
6 changed files
with
165 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
50 changes: 50 additions & 0 deletions
50
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,50 @@ | ||
# 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("Validating localizations...") | ||
LocalizationsValidator.validate!(@locales) | ||
|
||
logger.info("Updating VERSION file...") | ||
File.write(version_file_path, @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("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,94 @@ | ||
# 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 | ||
LocalizationsValidator.expects(:validate!).with(["en"]) | ||
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) | ||
LocalizationsValidator.stubs(:validate!) | ||
|
||
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 | ||
|
||
test "execute validates localizations before proceeding" do | ||
command = GenerateReleaseCommand.new(version: @version, locales: ["en"]) | ||
|
||
# Remove any existing stubs | ||
LocalizationsValidator.unstub(:validate!) | ||
|
||
# Set up the expectation before the error | ||
LocalizationsValidator.expects(:validate!).with(["en"]).raises(ArgumentError) | ||
|
||
assert_raises(ArgumentError) { command.execute } | ||
|
||
# Verify other steps weren't executed | ||
assert_equal "2023-12", File.read(@version_file_path) | ||
end | ||
end | ||
end |