Skip to content

Commit

Permalink
Add shared GitHub Actions workflow for ruby (theforeman#180)
Browse files Browse the repository at this point in the history
* Add shared GitHub Actions workflow for ruby

* Update .github/workflows/ruby_ci.yml

* Fix rubocop

* Run CI on push

---------

Co-authored-by: Adam Ruzicka <[email protected]>
Co-authored-by: Ewoud Kohl van Wijngaarden <[email protected]>
  • Loading branch information
3 people authored Jan 29, 2024
1 parent 5b0bc68 commit d307b43
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 17 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/ruby_ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: CI

on:
pull_request:
push:
branches:
- master
- '*-stable'

concurrency:
group: ${{ github.ref_name }}-${{ github.workflow }}
cancel-in-progress: true

jobs:
rubocop:
name: Rubocop
uses: theforeman/actions/.github/workflows/rubocop.yml@v0
with:
command: bundle exec rubocop --parallel --format github

test:
name: Ruby
needs: rubocop
uses: theforeman/actions/.github/workflows/foreman_plugin.yml@v0
with:
plugin: foreman_templates
6 changes: 6 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@ Gemspec/RequiredRubyVersion:
# Include: **/Rakefile, **/*.rake
Rails/RakeEnvironment:
Enabled: false

Style/OptionalBooleanParameter:
Enabled: false

Lint/ConstantDefinitionInBlock:
Enabled: false
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 4 additions & 2 deletions app/services/foreman_templates/template_exporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion app/services/foreman_templates/template_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions foreman_templates.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions test/functional/api/v2/template_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
16 changes: 8 additions & 8 deletions test/unit/template_exporter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down

0 comments on commit d307b43

Please sign in to comment.