diff --git a/.rubocop.yml b/.rubocop.yml deleted file mode 100644 index 05d6214..0000000 --- a/.rubocop.yml +++ /dev/null @@ -1,9 +0,0 @@ ---- -Metrics/MethodLength: - Max: 15 - -Metrics/AbcSize: - Max: 50 - -Metrics/BlockLength: - Enabled: false diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 3b2fc55..0000000 --- a/.travis.yml +++ /dev/null @@ -1,4 +0,0 @@ -nguage: ruby -rvm: - - 2.2 - - 2.3.3 diff --git a/github/workflows/publish.yml b/github/workflows/publish.yml new file mode 100644 index 0000000..1afbc15 --- /dev/null +++ b/github/workflows/publish.yml @@ -0,0 +1,33 @@ +name: Ruby Gem + +on: + push: + tags: + - v* + +permissions: + packages: write + contents: read + +jobs: + build: + name: publish + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.2 + - run: bundle install + - name: Publish to GPR + run: | + mkdir -p $HOME/.gem + touch $HOME/.gem/credentials + chmod 0600 $HOME/.gem/credentials + printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials + gem build *.gemspec + gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem + env: + GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}" + OWNER: ${{ github.repository_owner }} + CI_COMMIT_TAG: ${{github.ref_name}} diff --git a/github/workflows/release.yml b/github/workflows/release.yml new file mode 100644 index 0000000..a426373 --- /dev/null +++ b/github/workflows/release.yml @@ -0,0 +1,23 @@ +name: release + +on: + push: + branches: + - main + - master + pull_request: + +permissions: + contents: write + +jobs: + release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - uses: go-semantic-release/action@v1 + with: + allow-initial-development-versions: true + github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/github/workflows/rspec.yml b/github/workflows/rspec.yml new file mode 100644 index 0000000..9a65832 --- /dev/null +++ b/github/workflows/rspec.yml @@ -0,0 +1,30 @@ +name: rspec +on: + push: + tags: + - v* + branches: + - main + - master + pull_request: + +permissions: + contents: read + pull-requests: read + +jobs: + rspec: + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest] + # Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0' + ruby: ["2.5", "2.7", "3.0", "3.1", "3.2"] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true # runs 'bundle install' and caches installed gems automatically + - run: bundle exec rspec diff --git a/lib/puppet-lint/plugins/check_global_resource.rb b/lib/puppet-lint/plugins/check_global_resource.rb index b0ebbb1..ce41562 100644 --- a/lib/puppet-lint/plugins/check_global_resource.rb +++ b/lib/puppet-lint/plugins/check_global_resource.rb @@ -21,23 +21,23 @@ def check_for_global_resources next if @secure.any? { |s| s[0] < r[:start] && s[1] > r[:end] } notify :error, - message: "Resource #{r[:type].value} in global space", - line: r[:type].line, - column: r[:type].column + message: "Resource #{r[:type].value} in global space", + line: r[:type].line, + column: r[:type].column end end def check_for_global_includes tokens.each_index do |i| token = tokens[i] - next unless token.type == :NAME && token.value == 'include' + next unless token.type == :NAME && token.value == "include" next if @secure.any? { |s| s[0] < i && s[1] > i } notify :error, - message: "include #{token.next_code_token.value} in global space", - line: token.line, - column: token.column + message: "include #{token.next_code_token.value} in global space", + line: token.line, + column: token.column end end end diff --git a/puppet-lint-global_resource-check.gemspec b/puppet-lint-global_resource-check.gemspec index 20f8556..1ae5536 100644 --- a/puppet-lint-global_resource-check.gemspec +++ b/puppet-lint-global_resource-check.gemspec @@ -1,28 +1,27 @@ Gem::Specification.new do |spec| - spec.name = 'puppet-lint-global_resource-check' - spec.version = '0.3.2' - spec.homepage = 'https://github.com/ninech/puppet-lint-global_resource-check' - spec.license = 'MIT' - spec.author = 'Marius Rieder' - spec.email = 'marius.rieder@nine.ch' - spec.files = Dir[ - 'README.md', - 'LICENSE', - 'lib/**/*', - 'spec/**/*', + spec.name = "puppet-lint-global_resource-check" + spec.version = ENV.fetch("CI_COMMIT_TAG", "v0.0.1").delete_prefix("v") + spec.homepage = "https://github.com/ninech/puppet-lint-global_resource-check" + spec.license = "MIT" + spec.author = "Marius Rieder" + spec.email = "marius.rieder@nine.ch" + spec.files = Dir[ + "README.md", + "LICENSE", + "lib/**/*", + "spec/**/*", ] - spec.test_files = Dir['spec/**/*'] - spec.summary = 'puppet-lint global_resource check' + spec.summary = "puppet-lint global_resource check" spec.description = <<-EOF Extends puppet-lint to ensure that your manifests have no global resources. EOF - spec.add_dependency 'puppet-lint', '~> 2.1' - spec.add_development_dependency 'rspec', '~> 3.0' - spec.add_development_dependency 'rspec-its', '~> 1.0' - spec.add_development_dependency 'rspec-collection_matchers', '~> 1.0' - spec.add_development_dependency 'rspec-json_expectations' - spec.add_development_dependency 'rake' - spec.add_development_dependency 'rubocop' - spec.add_development_dependency 'simplecov-console' + spec.add_dependency "puppet-lint", "~> 2.1" + spec.add_development_dependency "rspec", "~> 3.4" + spec.add_development_dependency "rspec-its", "~> 1.3" + spec.add_development_dependency "rspec-collection_matchers", "~> 1.2" + spec.add_development_dependency "rspec-json_expectations" + spec.add_development_dependency "rake" + spec.add_development_dependency "standardrb" + spec.add_development_dependency "simplecov-console" end diff --git a/spec/puppet-lint/plugins/check_global_resource_spec.rb b/spec/puppet-lint/plugins/check_global_resource_spec.rb index 3252f5e..c71cfab 100644 --- a/spec/puppet-lint/plugins/check_global_resource_spec.rb +++ b/spec/puppet-lint/plugins/check_global_resource_spec.rb @@ -1,44 +1,44 @@ -require 'spec_helper' +require "spec_helper" -describe 'global_resource' do - context 'just a class' do +describe "global_resource" do + context "just a class" do let(:code) { "class test { file { 'file': } }" } - it 'should not detect any problems' do + it "should not detect any problems" do expect(problems).to have(0).problems end end - context 'just a define' do + context "just a define" do let(:code) { "define test ($param = undef) { file { 'file': } }" } - it 'should not detect any problems' do + it "should not detect any problems" do expect(problems).to have(0).problems end end - context 'allow node resources' do + context "allow node resources" do let(:code) { "node 'test' { file { 'file': } }" } - it 'should not detect any problems' do + it "should not detect any problems" do expect(problems).to have(0).problems end end - context 'global file' do + context "global file" do let(:code) do "file { 'file': } define test ($param = undef) { file { 'file': } }" end - it 'should detect a problem' do + it "should detect a problem" do expect(problems).to have(1).problems end end - context 'global includes' do + context "global includes" do let(:code) { "class test { file { 'file': } } \ninclude class" } - it 'should detect a problem' do + it "should detect a problem" do expect(problems).to have(1).problems end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d0444ca..2e22dda 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,12 +1,12 @@ -require 'puppet-lint' -require 'simplecov' -require 'simplecov-console' +require "puppet-lint" +require "simplecov" +require "simplecov-console" PuppetLint::Plugins.load_spec_helper SimpleCov.formatter = SimpleCov::Formatter::Console SimpleCov.start do - add_filter '/spec' - add_filter '.bundle' - add_filter '/vendor' + add_filter "/spec" + add_filter ".bundle" + add_filter "/vendor" end