From 38220961c9f88c8110229a187d05d6106ff93769 Mon Sep 17 00:00:00 2001 From: Adam Ruzicka Date: Fri, 12 Jan 2024 14:04:01 +0100 Subject: [PATCH 1/4] Add shared GitHub Actions workflow for ruby --- .github/workflows/ruby_ci.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .github/workflows/ruby_ci.yml diff --git a/.github/workflows/ruby_ci.yml b/.github/workflows/ruby_ci.yml new file mode 100644 index 00000000..2d4cdefe --- /dev/null +++ b/.github/workflows/ruby_ci.yml @@ -0,0 +1,19 @@ +name: CI + +on: pull_request + +concurrency: + group: ${{ github.ref_name }}-${{ github.workflow }} + cancel-in-progress: true + +jobs: + rubocop: + name: Rubocop + uses: theforeman/actions/.github/workflows/rubocop.yml@v0 + + test: + name: Ruby + needs: rubocop + uses: theforeman/actions/.github/workflows/foreman_plugin.yml@v0 + with: + plugin: foreman_templates From 875ea93e3638376cb33d53d047fdce6f2b085f84 Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Tue, 23 Jan 2024 12:44:16 +0100 Subject: [PATCH 2/4] Update .github/workflows/ruby_ci.yml --- .github/workflows/ruby_ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ruby_ci.yml b/.github/workflows/ruby_ci.yml index 2d4cdefe..bce7b0ef 100644 --- a/.github/workflows/ruby_ci.yml +++ b/.github/workflows/ruby_ci.yml @@ -10,6 +10,8 @@ jobs: rubocop: name: Rubocop uses: theforeman/actions/.github/workflows/rubocop.yml@v0 + with: + command: bundle exec rubocop --parallel --format github test: name: Ruby From 0a87e3d0995d9041c7e1e8e802f35cd9cfee1b55 Mon Sep 17 00:00:00 2001 From: Oleh Fedorenko Date: Fri, 26 Jan 2024 14:12:36 +0000 Subject: [PATCH 3/4] Fix rubocop --- .rubocop_todo.yml | 6 ++++++ .../foreman_templates/template_extensions.rb | 2 +- .../foreman_templates/template_exporter.rb | 6 ++++-- .../foreman_templates/template_importer.rb | 2 +- foreman_templates.gemspec | 7 ++++--- .../api/v2/template_controller_test.rb | 4 ++-- test/unit/template_exporter_test.rb | 16 ++++++++-------- 7 files changed, 26 insertions(+), 17 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index cf6ea369..6c55c602 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -18,3 +18,9 @@ Gemspec/RequiredRubyVersion: # Include: **/Rakefile, **/*.rake Rails/RakeEnvironment: Enabled: false + +Style/OptionalBooleanParameter: + Enabled: false + +Lint/ConstantDefinitionInBlock: + Enabled: false diff --git a/app/models/concerns/foreman_templates/template_extensions.rb b/app/models/concerns/foreman_templates/template_extensions.rb index 6411e2e7..b0ba3761 100644 --- a/app/models/concerns/foreman_templates/template_extensions.rb +++ b/app/models/concerns/foreman_templates/template_extensions.rb @@ -5,7 +5,7 @@ module TemplateExtensions extend ActiveSupport::Concern def template_file - Shellwords.escape(name.downcase.tr(' /', '_') + '.erb') + Shellwords.escape("#{name.downcase.tr(' /', '_')}.erb") end end end diff --git a/app/services/foreman_templates/template_exporter.rb b/app/services/foreman_templates/template_exporter.rb index 8c15edfa..1ecf0061 100644 --- a/app/services/foreman_templates/template_exporter.rb +++ b/app/services/foreman_templates/template_exporter.rb @@ -168,8 +168,10 @@ def find_taxed_templates end def templates_query(tax_ids) - Template.where(:id => TaxableTaxonomy.where(:taxonomy_id => tax_ids, - :taxable_type => Template.subclasses.map(&:name)).pluck(:taxable_id)) + Template.where(:id => TaxableTaxonomy.where( + :taxonomy_id => tax_ids, + :taxable_type => Template.subclasses.map(&:name) + ).pluck(:taxable_id)) end def taxes_ids(tax_type) diff --git a/app/services/foreman_templates/template_importer.rb b/app/services/foreman_templates/template_importer.rb index 1bc22e89..3f026b38 100644 --- a/app/services/foreman_templates/template_importer.rb +++ b/app/services/foreman_templates/template_importer.rb @@ -47,7 +47,7 @@ def import_from_git def parse_files! Dir["#{@dir}/#{@dirname}/**/*.erb"].each do |template_file| - logger.debug 'Parsing: ' + template_file.gsub(%r{#{@dir}\/#{@dirname}}, '') + logger.debug "Parsing: #{template_file.gsub(%r{#{@dir}/#{@dirname}}, '')}" parse_result = ParseResult.new(template_file) text = File.read(template_file) diff --git a/foreman_templates.gemspec b/foreman_templates.gemspec index d73398ae..a0702a1d 100644 --- a/foreman_templates.gemspec +++ b/foreman_templates.gemspec @@ -14,9 +14,10 @@ Gem::Specification.new do |s| "LICENSE", "README.md" ] - s.files = Dir["{app,config,db,lib,webpack}/**/*"] + ["LICENSE", "Rakefile", "README.md", "package.json"] + \ - # .mo files are compiled; .po are sources; .edit.po are temporary files - Dir['locale/*/LC_MESSAGES/*.mo'] + Dir["locale/*/#{s.name}.po"] + s.files = Dir["{app,config,db,lib,webpack}/**/*"] + \ + ["LICENSE", "Rakefile", "README.md", "package.json"] + \ + # .mo files are compiled; .po are sources; .edit.po are temporary files + Dir['locale/*/LC_MESSAGES/*.mo'] + Dir["locale/*/#{s.name}.po"] s.homepage = 'https://github.com/theforeman/foreman_templates' s.licenses = ["GPL-3.0"] s.summary = 'Template-syncing engine for Foreman' diff --git a/test/functional/api/v2/template_controller_test.rb b/test/functional/api/v2/template_controller_test.rb index 740a0adc..1045f206 100644 --- a/test/functional/api/v2/template_controller_test.rb +++ b/test/functional/api/v2/template_controller_test.rb @@ -26,7 +26,7 @@ class TemplateControllerTest < ::ActionController::TestCase FactoryBot.create(:provisioning_template, :name => 'export_test_template') post :export, params: { "repo" => tmpdir, "filter" => "^export_test_template", "negate" => true, "metadata_export_mode" => "keep" } assert_response :success - refute Dir.entries("#{tmpdir}/provisioning_templates/provision").include?('export_test_template.erb') + refute_includes(Dir.entries("#{tmpdir}/provisioning_templates/provision"), 'export_test_template.erb') end end @@ -151,7 +151,7 @@ class TemplateControllerTest < ::ActionController::TestCase FactoryBot.create(:provisioning_template, :name => 'exporting_template', :template_kind => kind) post :export, params: { "repo" => tmpdir, "filter" => "exporting_template", "metadata_export_mode" => "refresh" } assert_response :success - assert Dir.entries("#{tmpdir}/provisioning_templates/provision").include?('exporting_template.erb') + assert_includes(Dir.entries("#{tmpdir}/provisioning_templates/provision"), 'exporting_template.erb') end end diff --git a/test/unit/template_exporter_test.rb b/test/unit/template_exporter_test.rb index 3782ca6b..fb238dd2 100644 --- a/test/unit/template_exporter_test.rb +++ b/test/unit/template_exporter_test.rb @@ -43,25 +43,25 @@ class TemplateExporterTest < ActiveSupport::TestCase exporter = TemplateExporter.new(:filter => "", :organization_params => { :organization_ids => [@org.id] }) templates = exporter.templates_to_dump assert_equal 2, templates.count - assert templates.include?(@ptable) - assert templates.include?(@provisioning_template) + assert_includes(templates, @ptable) + assert_includes(templates, @provisioning_template) end test 'should export templates only from specified org by name' do exporter = TemplateExporter.new(:filter => "", :organization_params => { :organization_names => [@org.name] }) templates = exporter.templates_to_dump assert_equal 2, templates.count - assert templates.include?(@ptable) - assert templates.include?(@provisioning_template) + assert_includes(templates, @ptable) + assert_includes(templates, @provisioning_template) end test 'should export template only in both organization and location' do - loc = FactoryBot.create(:location, :name => 'TemplateLoc') + loc = FactoryBot.create(:location, :name => 'TemplateLoc') template = FactoryBot.create(:provisioning_template, :name => 'exported_template_with_taxonomies', :organizations => [@org], :locations => [loc]) exporter = TemplateExporter.new(:filter => "", :organization_params => { :organization_ids => [@org.id] }, :location_params => { :location_ids => [loc.id] }) templates = exporter.templates_to_dump assert_equal 1, templates.count - assert templates.include?(template) + assert_includes(templates, template) end end @@ -80,8 +80,8 @@ class TemplateExporterTest < ActiveSupport::TestCase exporter = TemplateExporter.new(:filter => "", :organization_id => @org.id) templates = exporter.templates_to_dump assert_equal 2, templates.count - assert templates.include?(@ptable) - assert templates.include?(@provisioning_template) + assert_includes(templates, @ptable) + assert_includes(templates, @provisioning_template) end end From 75fe52c92f48f65eb49cee962af7382786f80600 Mon Sep 17 00:00:00 2001 From: Oleh Fedorenko Date: Fri, 26 Jan 2024 15:22:35 +0000 Subject: [PATCH 4/4] Run CI on push --- .github/workflows/ruby_ci.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ruby_ci.yml b/.github/workflows/ruby_ci.yml index bce7b0ef..06ce3683 100644 --- a/.github/workflows/ruby_ci.yml +++ b/.github/workflows/ruby_ci.yml @@ -1,6 +1,11 @@ name: CI -on: pull_request +on: + pull_request: + push: + branches: + - master + - '*-stable' concurrency: group: ${{ github.ref_name }}-${{ github.workflow }}