Skip to content

Commit d307b43

Browse files
ofedorenadamruzickaekohl
authored
Add shared GitHub Actions workflow for ruby (#180)
* Add shared GitHub Actions workflow for ruby * Update .github/workflows/ruby_ci.yml * Fix rubocop * Run CI on push --------- Co-authored-by: Adam Ruzicka <aruzicka@redhat.com> Co-authored-by: Ewoud Kohl van Wijngaarden <ewoud@kohlvanwijngaarden.nl>
1 parent 5b0bc68 commit d307b43

File tree

8 files changed

+52
-17
lines changed

8 files changed

+52
-17
lines changed

.github/workflows/ruby_ci.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- master
8+
- '*-stable'
9+
10+
concurrency:
11+
group: ${{ github.ref_name }}-${{ github.workflow }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
rubocop:
16+
name: Rubocop
17+
uses: theforeman/actions/.github/workflows/rubocop.yml@v0
18+
with:
19+
command: bundle exec rubocop --parallel --format github
20+
21+
test:
22+
name: Ruby
23+
needs: rubocop
24+
uses: theforeman/actions/.github/workflows/foreman_plugin.yml@v0
25+
with:
26+
plugin: foreman_templates

.rubocop_todo.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,9 @@ Gemspec/RequiredRubyVersion:
1818
# Include: **/Rakefile, **/*.rake
1919
Rails/RakeEnvironment:
2020
Enabled: false
21+
22+
Style/OptionalBooleanParameter:
23+
Enabled: false
24+
25+
Lint/ConstantDefinitionInBlock:
26+
Enabled: false

app/models/concerns/foreman_templates/template_extensions.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module TemplateExtensions
55
extend ActiveSupport::Concern
66

77
def template_file
8-
Shellwords.escape(name.downcase.tr(' /', '_') + '.erb')
8+
Shellwords.escape("#{name.downcase.tr(' /', '_')}.erb")
99
end
1010
end
1111
end

app/services/foreman_templates/template_exporter.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,10 @@ def find_taxed_templates
168168
end
169169

170170
def templates_query(tax_ids)
171-
Template.where(:id => TaxableTaxonomy.where(:taxonomy_id => tax_ids,
172-
:taxable_type => Template.subclasses.map(&:name)).pluck(:taxable_id))
171+
Template.where(:id => TaxableTaxonomy.where(
172+
:taxonomy_id => tax_ids,
173+
:taxable_type => Template.subclasses.map(&:name)
174+
).pluck(:taxable_id))
173175
end
174176

175177
def taxes_ids(tax_type)

app/services/foreman_templates/template_importer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def import_from_git
4747

4848
def parse_files!
4949
Dir["#{@dir}/#{@dirname}/**/*.erb"].each do |template_file|
50-
logger.debug 'Parsing: ' + template_file.gsub(%r{#{@dir}\/#{@dirname}}, '')
50+
logger.debug "Parsing: #{template_file.gsub(%r{#{@dir}/#{@dirname}}, '')}"
5151
parse_result = ParseResult.new(template_file)
5252

5353
text = File.read(template_file)

foreman_templates.gemspec

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ Gem::Specification.new do |s|
1414
"LICENSE",
1515
"README.md"
1616
]
17-
s.files = Dir["{app,config,db,lib,webpack}/**/*"] + ["LICENSE", "Rakefile", "README.md", "package.json"] + \
18-
# .mo files are compiled; .po are sources; .edit.po are temporary files
19-
Dir['locale/*/LC_MESSAGES/*.mo'] + Dir["locale/*/#{s.name}.po"]
17+
s.files = Dir["{app,config,db,lib,webpack}/**/*"] + \
18+
["LICENSE", "Rakefile", "README.md", "package.json"] + \
19+
# .mo files are compiled; .po are sources; .edit.po are temporary files
20+
Dir['locale/*/LC_MESSAGES/*.mo'] + Dir["locale/*/#{s.name}.po"]
2021
s.homepage = 'https://github.com/theforeman/foreman_templates'
2122
s.licenses = ["GPL-3.0"]
2223
s.summary = 'Template-syncing engine for Foreman'

test/functional/api/v2/template_controller_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class TemplateControllerTest < ::ActionController::TestCase
2626
FactoryBot.create(:provisioning_template, :name => 'export_test_template')
2727
post :export, params: { "repo" => tmpdir, "filter" => "^export_test_template", "negate" => true, "metadata_export_mode" => "keep" }
2828
assert_response :success
29-
refute Dir.entries("#{tmpdir}/provisioning_templates/provision").include?('export_test_template.erb')
29+
refute_includes(Dir.entries("#{tmpdir}/provisioning_templates/provision"), 'export_test_template.erb')
3030
end
3131
end
3232

@@ -151,7 +151,7 @@ class TemplateControllerTest < ::ActionController::TestCase
151151
FactoryBot.create(:provisioning_template, :name => 'exporting_template', :template_kind => kind)
152152
post :export, params: { "repo" => tmpdir, "filter" => "exporting_template", "metadata_export_mode" => "refresh" }
153153
assert_response :success
154-
assert Dir.entries("#{tmpdir}/provisioning_templates/provision").include?('exporting_template.erb')
154+
assert_includes(Dir.entries("#{tmpdir}/provisioning_templates/provision"), 'exporting_template.erb')
155155
end
156156
end
157157

test/unit/template_exporter_test.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,25 +43,25 @@ class TemplateExporterTest < ActiveSupport::TestCase
4343
exporter = TemplateExporter.new(:filter => "", :organization_params => { :organization_ids => [@org.id] })
4444
templates = exporter.templates_to_dump
4545
assert_equal 2, templates.count
46-
assert templates.include?(@ptable)
47-
assert templates.include?(@provisioning_template)
46+
assert_includes(templates, @ptable)
47+
assert_includes(templates, @provisioning_template)
4848
end
4949

5050
test 'should export templates only from specified org by name' do
5151
exporter = TemplateExporter.new(:filter => "", :organization_params => { :organization_names => [@org.name] })
5252
templates = exporter.templates_to_dump
5353
assert_equal 2, templates.count
54-
assert templates.include?(@ptable)
55-
assert templates.include?(@provisioning_template)
54+
assert_includes(templates, @ptable)
55+
assert_includes(templates, @provisioning_template)
5656
end
5757

5858
test 'should export template only in both organization and location' do
59-
loc = FactoryBot.create(:location, :name => 'TemplateLoc')
59+
loc = FactoryBot.create(:location, :name => 'TemplateLoc')
6060
template = FactoryBot.create(:provisioning_template, :name => 'exported_template_with_taxonomies', :organizations => [@org], :locations => [loc])
6161
exporter = TemplateExporter.new(:filter => "", :organization_params => { :organization_ids => [@org.id] }, :location_params => { :location_ids => [loc.id] })
6262
templates = exporter.templates_to_dump
6363
assert_equal 1, templates.count
64-
assert templates.include?(template)
64+
assert_includes(templates, template)
6565
end
6666
end
6767

@@ -80,8 +80,8 @@ class TemplateExporterTest < ActiveSupport::TestCase
8080
exporter = TemplateExporter.new(:filter => "", :organization_id => @org.id)
8181
templates = exporter.templates_to_dump
8282
assert_equal 2, templates.count
83-
assert templates.include?(@ptable)
84-
assert templates.include?(@provisioning_template)
83+
assert_includes(templates, @ptable)
84+
assert_includes(templates, @provisioning_template)
8585
end
8686
end
8787

0 commit comments

Comments
 (0)