diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..a392f30 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,31 @@ +name: Release + +on: + push: + tags: + - '*' + +jobs: + release: + runs-on: ubuntu-latest + if: github.repository_owner == 'voxpupuli' + steps: + - uses: actions/checkout@v2 + - name: Install Ruby 3.0 + uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.0' + bundler: 'none' + - name: Build gem + run: gem build *.gemspec + - name: Publish gem to rubygems.org + run: gem push *.gem + env: + GEM_HOST_API_KEY: '${{ secrets.RUBYGEMS_AUTH_TOKEN }}' + - name: Setup GitHub packages access + run: | + mkdir -p ~/.gem + echo ":github: Bearer ${{ secrets.GITHUB_TOKEN }}" >> ~/.gem/credentials + chmod 0600 ~/.gem/credentials + - name: Publish gem to GitHub packages + run: gem push --key github --host https://rubygems.pkg.github.com/${{ github.repository_owner }} *.gem diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..ce74c2a --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,36 @@ +name: Test + +on: + - pull_request + - push + +env: + BUNDLE_WITHOUT: release + +jobs: + test: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - ruby: "2.4" + - ruby: "2.5" + - ruby: "2.6" + - ruby: "2.7" + - ruby: "3.0" + coverage: "yes" + env: + COVERAGE: ${{ matrix.coverage }} + name: Ruby ${{ matrix.ruby }} + steps: + - uses: actions/checkout@v2 + - name: Install Ruby ${{ matrix.ruby }} + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + - name: Run tests + run: bundle exec rake spec + - name: Verify gem builds + run: gem build *.gemspec diff --git a/.gitignore b/.gitignore index 7a0b779..1d7b280 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,5 @@ /.bundle/ -/.vendor /vendor/gems/ /Gemfile.lock -pkg/ -.ruby-* -*.gem -coverage +vendor/bundle +.vendor/ diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b383cc0..0000000 --- a/.travis.yml +++ /dev/null @@ -1,13 +0,0 @@ ---- -language: 'ruby' -dist: 'xenial' -cache: 'bundler' -script: - - 'bundle exec rake spec' -rvm: - - '2.5.3' # Puppet 6.3 - - '2.4.5' # Puppet 5.5 -matrix: - fast_finish: true -notifications: - email: false diff --git a/Gemfile b/Gemfile index fa75df1..20e2ce6 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,12 @@ -source 'https://rubygems.org' +source ENV['GEM_SOURCE'] || 'https://rubygems.org' gemspec + +group :release do + gem 'github_changelog_generator', require: false +end + +group :coverage, optional: ENV['COVERAGE']!='yes' do + gem 'simplecov-console', :require => false + gem 'codecov', :require => false +end diff --git a/README.md b/README.md index 6eed37c..d4beec1 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,10 @@ puppet-lint-topscope-variable-check ======================== -[![Build Status](https://api.travis-ci.org/sixt/puppet-lint-topscope-variable-check.svg)](https://travis-ci.org/sixt/puppet-lint-topscope-variable-check) -[![Gem Version](https://badge.fury.io/rb/puppet-lint-topscope-variable-check.svg)](https://badge.fury.io/rb/puppet-lint-topscope-variable-check) - +[![License](https://img.shields.io/github/license/voxpupuli/puppet-lint-topscope-variable-check.svg)](https://github.com/voxpupuli/puppet-lint-topscope-variable-check/blob/master/LICENSE) +[![Test](https://github.com/voxpupuli/puppet-lint-topscope-variable-check/actions/workflows/test.yml/badge.svg)](https://github.com/voxpupuli/puppet-lint-topscope-variable-check/actions/workflows/test.yml) +[![Release](https://github.com/voxpupuli/puppet-lint-topscope-variable-check/actions/workflows/release.yml/badge.svg)](https://github.com/voxpupuli/puppet-lint-topscope-variable-check/actions/workflows/release.yml) +[![RubyGem Version](https://img.shields.io/gem/v/puppet-lint-topscope-variable-check.svg)](https://rubygems.org/gems/puppet-lint-topscope-variable-check) +[![RubyGem Downloads](https://img.shields.io/gem/dt/puppet-lint-topscope-variable-check.svg)](https://rubygems.org/gems/puppet-lint-topscope-variable-check) A puppet-lint plugin to check that topscope variables in a class do not begin with $:: @@ -73,13 +75,22 @@ PuppetLint.configuration.send('disable_topscope_variable') ``` ## Limitations -The fix function of this plugin does not work when the variable is used in a string. +The fix function of this plugin does not work when the variable is used in a string and hasn't been enclosed with `{}`. For example: ``` puppet $foo = "/etc/$::foobar::path/test" ``` +Note: The [Variables Not Enclosed](http://puppet-lint.com/checks/variables_not_enclosed/) check can fix the missing braces and then the fix from this plugin should work. + +## Transfer Notice + +This plugin and github repository was originally developed and maintained by [Sixt](https://www.sixt.com/). +On 2021/11/24 the github project was transferred to [Voxpupuli](https://voxpupuli.org/) for ongoing improvement and maintenance. + +Previously: https://github.com/Sixt/puppet-lint-topscope-variable-check + ## License ``` MIT License diff --git a/Rakefile b/Rakefile index 5d4b01f..5cfe529 100644 --- a/Rakefile +++ b/Rakefile @@ -1,7 +1,19 @@ require 'rspec/core/rake_task' -require 'rubocop/rake_task' -RuboCop::RakeTask.new RSpec::Core::RakeTask.new(:spec) task default: :spec + +begin + require 'rubygems' + require 'github_changelog_generator/task' + + GitHubChangelogGenerator::RakeTask.new :changelog do |config| + config.header = "# Changelog\n\nAll notable changes to this project will be documented in this file." + config.exclude_labels = %w{duplicate question invalid wontfix wont-fix skip-changelog modulesync} + config.user = 'voxpupuli' + config.project = 'puppet-lint-topscope-variable-check' + config.future_release = Gem::Specification.load("#{config.project}.gemspec").version + end +rescue LoadError +end diff --git a/spec/puppet-lint/plugins/topscope_variable_spec.rb b/spec/puppet-lint/plugins/topscope_variable_spec.rb index f5aed67..f7fc661 100644 --- a/spec/puppet-lint/plugins/topscope_variable_spec.rb +++ b/spec/puppet-lint/plugins/topscope_variable_spec.rb @@ -5,7 +5,7 @@ context 'with fix disabled' do context 'with correct topscope' do let(:code) do - <<-PUP.strip_heredoc + <<~PUP class foo::blub { notify { 'foo': message => $foo::bar @@ -21,7 +21,7 @@ class foo::blub { context 'with incorrect topscope' do let(:code) do - <<-PUP.strip_heredoc + <<~PUP class foo::blub { notify { 'foo': message => $::foo::bar @@ -37,7 +37,7 @@ class foo::blub { context 'with correct topscope in params' do let(:code) do - <<-PUP.strip_heredoc + <<~PUP class foo::blub( String $foo = $params::foo ) { @@ -53,7 +53,7 @@ class foo::blub( context 'with incorrect topscope in params' do let(:code) do - <<-PUP.strip_heredoc + <<~PUP class foo::blub( String $foo = $::foo::params::foo ) { @@ -69,7 +69,7 @@ class foo::blub( context 'with a fact that has been used improperly' do let(:code) do - <<-PUP.strip_heredoc + <<~PUP class foo::blub { notify { 'foo': message => $blub::bar @@ -95,7 +95,7 @@ class foo::blub { context 'with correct topscope' do let(:code) do - <<-PUP.strip_heredoc + <<~PUP class foo::blub { notify { 'foo': message => $foo::bar @@ -111,7 +111,7 @@ class foo::blub { context 'with incorrect topscope' do let(:code) do - <<-PUP.strip_heredoc + <<~PUP class foo::blub { notify { 'foo': message => $::foo::bar @@ -129,7 +129,7 @@ class foo::blub { end it 'should remove :: after the $' do - expect(manifest).to eq <<-PUP.strip_heredoc + expect(manifest).to eq <<~PUP class foo::blub { notify { 'foo': message => $foo::bar @@ -141,7 +141,7 @@ class foo::blub { context 'with incorrect topscope in quoted variable' do let(:code) do - <<-PUP.strip_heredoc + <<~PUP class foo::blub { notify { 'foo': message => ">${::foo::bar}<" @@ -155,24 +155,24 @@ class foo::blub { end it 'should fix the problem' do - expect(problems).to contain_fixed(msg).on_line(3).in_column(19) - end - - # it 'should remove :: after the $' do - # expect(manifest).to eq <<-PUP.strip_heredoc - # class foo::blub { - # notify { 'foo': - # message => ">${foo::bar}<" - # } - # } - # PUP - # end + expect(problems).to contain_fixed(msg).on_line(3).in_column(20) + end + + it 'should remove :: after the $' do + expect(manifest).to eq <<~PUP + class foo::blub { + notify { 'foo': + message => ">${foo::bar}<" + } + } + PUP + end end end context 'without a class scope' do let(:code) do - <<-PUP.strip_heredoc + <<~PUP include ::foo PUP end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4c412f6..2871e8d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,13 +1,29 @@ -require 'coveralls' -Coveralls.wear! +# frozen_string_literal: true -require 'puppet-lint' -PuppetLint::Plugins.load_spec_helper +begin + require 'simplecov' + require 'simplecov-console' + require 'codecov' +rescue LoadError +else + SimpleCov.start do + track_files 'lib/**/*.rb' + + add_filter '/spec' -# strip left spaces from heredoc -# this emulates the behaviour of the ~ heredoc from ruby 2.3 -class String - def strip_heredoc - gsub(/^#{scan(/^\s*/).min_by(&:length)}/, '') + enable_coverage :branch + + # do not track vendored files + add_filter '/vendor' + add_filter '/.vendor' end + + SimpleCov.formatters = [ + SimpleCov::Formatter::Console, + SimpleCov::Formatter::Codecov, + ] end + +require 'puppet-lint' + +PuppetLint::Plugins.load_spec_helper