From f9e9232ab5780eeb0ed1a8fd01a9aef8e7801f72 Mon Sep 17 00:00:00 2001 From: Fran Zekan Date: Thu, 13 Jul 2023 12:05:58 +0200 Subject: [PATCH 1/5] Ignore .idea folder --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 6100dc738..9c0078dd3 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ coverage/* .DS_Store gemfiles/*.lock +.idea/ From 04163633de4c6cf1286cbe77fc0d25fd89b77e6b Mon Sep 17 00:00:00 2001 From: Fran Zekan Date: Thu, 13 Jul 2023 12:06:35 +0200 Subject: [PATCH 2/5] Allow usage of .yml.erb and .yml files (without breaking existing compatibility of erb templates in .yml files) --- lib/mrsk/configuration.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/mrsk/configuration.rb b/lib/mrsk/configuration.rb index ee6dce056..2e48fecb3 100644 --- a/lib/mrsk/configuration.rb +++ b/lib/mrsk/configuration.rb @@ -33,7 +33,12 @@ def load_config_file(file) end def destination_config_file(base_config_file, destination) - base_config_file.sub_ext(".#{destination}.yml") if destination + return unless destination + + return base_config_file.sub_ext(".#{destination}.yml") if base_config_file.extname == ".yml" + return base_config_file.sub(/\.yml.erb$/, ".#{destination}.yml.erb") if base_config_file.extname == ".erb" + + raise 'Unsupported config file extension. Please use .yml or .yml.erb' end end From a1a927b64b531fd6c28ebdbcb5be9df7f1856ec7 Mon Sep 17 00:00:00 2001 From: Fran Zekan Date: Thu, 13 Jul 2023 12:12:27 +0200 Subject: [PATCH 3/5] Add tests for .yml.erb support --- test/configuration_test.rb | 10 +++++++++- test/fixtures/deploy.staging.yml.erb | 2 ++ test/fixtures/{deploy.erb.yml => deploy.yml.erb} | 0 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/deploy.staging.yml.erb rename test/fixtures/{deploy.erb.yml => deploy.yml.erb} (100%) diff --git a/test/configuration_test.rb b/test/configuration_test.rb index 0f7e12ffe..d93e9a8ba 100644 --- a/test/configuration_test.rb +++ b/test/configuration_test.rb @@ -243,10 +243,18 @@ class ConfigurationTest < ActiveSupport::TestCase end test "erb evaluation of yml config" do - config = Mrsk::Configuration.create_from config_file: Pathname.new(File.expand_path("fixtures/deploy.erb.yml", __dir__)) + config = Mrsk::Configuration.create_from config_file: Pathname.new(File.expand_path("fixtures/deploy.yml.erb", __dir__)) assert_equal "my-user", config.registry["username"] end + test "erb evaluation of yml config with destinations" do + config_file = Pathname.new(File.expand_path("fixtures/deploy.yml.erb", __dir__)) + + config = Mrsk::Configuration.create_from config_file: config_file, destination: 'staging' + assert_equal "my-user", config.registry["username"] + assert_equal "my-password-override", config.registry["password"] + end + test "destination yml config merge" do dest_config_file = Pathname.new(File.expand_path("fixtures/deploy_for_dest.yml", __dir__)) diff --git a/test/fixtures/deploy.staging.yml.erb b/test/fixtures/deploy.staging.yml.erb new file mode 100644 index 000000000..5b2b81f53 --- /dev/null +++ b/test/fixtures/deploy.staging.yml.erb @@ -0,0 +1,2 @@ +registry: + password: <%= "my-password-override" %> diff --git a/test/fixtures/deploy.erb.yml b/test/fixtures/deploy.yml.erb similarity index 100% rename from test/fixtures/deploy.erb.yml rename to test/fixtures/deploy.yml.erb From 9ab4fdc6170227f18c62e4b59a039197d6d7f3a3 Mon Sep 17 00:00:00 2001 From: Fran Zekan Date: Thu, 13 Jul 2023 12:59:18 +0200 Subject: [PATCH 4/5] Simplify extension replacement --- lib/mrsk/configuration.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mrsk/configuration.rb b/lib/mrsk/configuration.rb index 2e48fecb3..722e51f03 100644 --- a/lib/mrsk/configuration.rb +++ b/lib/mrsk/configuration.rb @@ -35,7 +35,7 @@ def load_config_file(file) def destination_config_file(base_config_file, destination) return unless destination - return base_config_file.sub_ext(".#{destination}.yml") if base_config_file.extname == ".yml" + return base_config_file.sub(/\.yml$/, ".#{destination}.yml") if base_config_file.extname == ".yml" return base_config_file.sub(/\.yml.erb$/, ".#{destination}.yml.erb") if base_config_file.extname == ".erb" raise 'Unsupported config file extension. Please use .yml or .yml.erb' From 67ffb6e28417c0068fe66a30bdf9433650c98b6d Mon Sep 17 00:00:00 2001 From: Fran Zekan Date: Mon, 25 Dec 2023 11:21:30 +0100 Subject: [PATCH 5/5] Remove idea from .gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 9c0078dd3..6100dc738 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,3 @@ coverage/* .DS_Store gemfiles/*.lock -.idea/