diff --git a/.travis.yml b/.travis.yml index 91d37ec76a059af119748e767c3fcb3d23e415b2..f4376eac22ee360c5e5e19104bb28bd07ddd4fb1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,5 @@ --- +dist: bionic language: ruby # Workaround https://github.com/bundler/bundler/issues/3558 before_install: gem install bundler @@ -7,6 +8,7 @@ script: bundle exec rake rvm: - 2.4.4 - 2.5.1 + - 2.6.5 env: - PUPPET_VERSION="~> 5.5.10" - PUPPET_VERSION="~> 6.1.0" @@ -29,3 +31,10 @@ deploy: tags: true all_branches: true repo: voxpupuli/puppet-syntax +notifications: + email: false + irc: + on_success: always + on_failure: always + channels: + - "chat.freenode.org#voxpupuli-notifications" diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e8e369e69a72bdec2ded983ccbd32e5ef386328..7de0f0b55464e5207a3dd7597b1ef18e27aa3bc0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,33 @@ All notable changes to this project will be documented in this file. +## [v2.6.1](https://github.com/voxpupuli/puppet-syntax/tree/v2.6.1) (2020-01-11) + +[Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v2.6.0...v2.6.1) + +**Fixed bugs:** + +- Add `puppet` gem as runtime dependency [\#116](https://github.com/voxpupuli/puppet-syntax/pull/116) ([bastelfreak](https://github.com/bastelfreak)) + +**Merged pull requests:** + +- traivs: run tests on Ubuntu 18.04 [\#117](https://github.com/voxpupuli/puppet-syntax/pull/117) ([bastelfreak](https://github.com/bastelfreak)) +- travis: enable irc / disable email notifications [\#114](https://github.com/voxpupuli/puppet-syntax/pull/114) ([bastelfreak](https://github.com/bastelfreak)) + +## [v2.6.0](https://github.com/voxpupuli/puppet-syntax/tree/v2.6.0) (2019-10-05) + +[Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v2.5.0...v2.6.0) + +**Implemented enhancements:** + +- add support for validating puppet plans \(fixes \#95, fixes \#96\) [\#97](https://github.com/voxpupuli/puppet-syntax/pull/97) ([slauger](https://github.com/slauger)) +- Allow specifying file paths for manifests and templates too [\#87](https://github.com/voxpupuli/puppet-syntax/pull/87) ([lavagetto](https://github.com/lavagetto)) + +**Merged pull requests:** + +- Test on ruby 2.6 [\#111](https://github.com/voxpupuli/puppet-syntax/pull/111) ([alexjfisher](https://github.com/alexjfisher)) +- Adding KMS tags to allowed EYAML methods [\#105](https://github.com/voxpupuli/puppet-syntax/pull/105) ([craigwatson](https://github.com/craigwatson)) + ## [v2.5.0](https://github.com/voxpupuli/puppet-syntax/tree/v2.5.0) (2019-07-07) [Full Changelog](https://github.com/voxpupuli/puppet-syntax/compare/v2.4.3...v2.5.0) diff --git a/Gemfile b/Gemfile index 19a87e8cbe2be464a4e5df6e240e6d339cdfb230..0a0c20cb9d214d511cda979df3c7c433fde576ff 100644 --- a/Gemfile +++ b/Gemfile @@ -18,7 +18,8 @@ end gemspec # Override gemspec for CI matrix builds. -gem 'puppet', *location_for(ENV['PUPPET_VERSION'] || '>2.7.0') +# But only if the environment variable is set +gem 'puppet', *location_for(ENV['PUPPET_VERSION'] || '>= 5') if ENV['PUPPET_VERSION'] # older version required for ruby 1.9 compat, as it is pulled in as dependency of puppet, this has to be carried by the module gem 'json_pure', '<= 2.0.1' diff --git a/README.md b/README.md index 55e5774af8c02c8902922acc6421ff0e89e16bbe..f30584a10349c87bd8e61eb255b4bd9bc98aa5e8 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,11 @@ To configure Puppet::Syntax, add any of the following settings to your `Rakefile PuppetSyntax.hieradata_paths = ["**/data/**/*.yaml", "hieradata/**/*.yaml", "hiera*.yaml"] +* To configure specific paths for the Puppet syntax checks or for the templates checks, specify `manifests_paths` or `templates_paths` respectively. This is useful if you want to check specific paths only. + + PuppetSyntax.manifests_paths = ["**/environments/future/*.pp"] + PuppetSyntax.templates_paths = ["**/modules/**/templates/*.erb"] + * To validate the syntax of code written for application orchestration, enable `app_management`: PuppetSyntax.app_management = true diff --git a/lib/puppet-syntax.rb b/lib/puppet-syntax.rb index 7e5c089c0f0d4a12049a9c5df6786a48ef4a41ba..d01291109b295020893601fbfe947f8a1db4e829 100644 --- a/lib/puppet-syntax.rb +++ b/lib/puppet-syntax.rb @@ -12,6 +12,13 @@ module PuppetSyntax "hieradata/**/*.*{yaml,yml}", "hiera*.*{yaml,yml}" ] + @manifests_paths = [ + '**/*.pp' + ] + @templates_paths = [ + '**/templates/**/*.erb', + '**/templates/**/*.epp' + ] @fail_on_deprecation_notices = true @app_management = Puppet.version.to_i >= 5 ? true : false @check_hiera_keys = false @@ -20,6 +27,8 @@ module PuppetSyntax attr_accessor :exclude_paths, :future_parser, :hieradata_paths, + :manifests_paths, + :templates_paths, :fail_on_deprecation_notices, :epp_only, :check_hiera_keys diff --git a/lib/puppet-syntax/hiera.rb b/lib/puppet-syntax/hiera.rb index e283c6aa5ba6acff2be826ead5f82beaa749032d..6c9fb8befe8a23424f8c7b217d3883dee45e9fd6 100644 --- a/lib/puppet-syntax/hiera.rb +++ b/lib/puppet-syntax/hiera.rb @@ -56,7 +56,7 @@ module PuppetSyntax method = 'PKCS7' end - return "has unknown eyaml method #{method}" unless ['PKCS7','GPG'].include? method + return "has unknown eyaml method #{method}" unless ['PKCS7','GPG','GKMS','KMS'].include? method return "has unpadded or truncated base64 data" unless base64.length % 4 == 0 # Base64#decode64 will silently ignore characters outside the alphabet, diff --git a/lib/puppet-syntax/manifests.rb b/lib/puppet-syntax/manifests.rb index b11b878882d77bb0e83cf8d8e58e71aff08a6168..a92aa5146e81dd60616442bc7b75d6af5cd4d481 100644 --- a/lib/puppet-syntax/manifests.rb +++ b/lib/puppet-syntax/manifests.rb @@ -64,6 +64,7 @@ module PuppetSyntax def validate_manifest(file) Puppet[:parser] = 'future' if PuppetSyntax.future_parser and Puppet.version.to_i < 4 Puppet[:app_management] = true if PuppetSyntax.app_management && (Puppet::Util::Package.versioncmp(Puppet.version, '4.3.0') >= 0 && Puppet.version.to_i < 5) + Puppet[:tasks] = true if Puppet::Util::Package.versioncmp(Puppet.version, '5.4.0') >= 0 and file.match(/.*plans\/.*\.pp$/) Puppet::Face[:parser, :current].validate(file) end end diff --git a/lib/puppet-syntax/tasks/puppet-syntax.rb b/lib/puppet-syntax/tasks/puppet-syntax.rb index 7013dc14ae3ed0360601e455719ff2c9d5178b99..b995600262c87f583520515e7e0a833490e8f6b1 100644 --- a/lib/puppet-syntax/tasks/puppet-syntax.rb +++ b/lib/puppet-syntax/tasks/puppet-syntax.rb @@ -13,11 +13,11 @@ module PuppetSyntax end def filelist_manifests - filelist("**/*.pp") + filelist(PuppetSyntax.manifests_paths) end def filelist_templates - filelist(["**/templates/**/*.erb", "**/templates/**/*.epp"]) + filelist(PuppetSyntax.templates_paths) end def filelist_hiera_yaml diff --git a/lib/puppet-syntax/version.rb b/lib/puppet-syntax/version.rb index 5eb4f769919d694a1f6443ae2cd672f7653b40e7..1d9a78248ebe99a2c0db553ad3b0eddb632aef62 100644 --- a/lib/puppet-syntax/version.rb +++ b/lib/puppet-syntax/version.rb @@ -1,3 +1,3 @@ module PuppetSyntax - VERSION = '2.5.0' + VERSION = '2.6.1' end diff --git a/puppet-syntax.gemspec b/puppet-syntax.gemspec index 7731acf46cefc0402c7ba64f5562375064a1f393..93791c3ad9d93773348826d9c3468ad41eaaa044 100644 --- a/puppet-syntax.gemspec +++ b/puppet-syntax.gemspec @@ -19,6 +19,7 @@ Gem::Specification.new do |spec| spec.require_paths = ["lib"] spec.add_dependency "rake" + spec.add_dependency "puppet", ">= 5" spec.add_development_dependency "pry" spec.add_development_dependency "rb-readline" diff --git a/spec/puppet-syntax/templates_spec.rb b/spec/puppet-syntax/templates_spec.rb index bcd10caa4902c2373f5d850e1c15f16ad0932204..e349c2c011bc77b08732274debe91caf987c4d9b 100644 --- a/spec/puppet-syntax/templates_spec.rb +++ b/spec/puppet-syntax/templates_spec.rb @@ -2,6 +2,13 @@ require 'spec_helper' describe PuppetSyntax::Templates do let(:subject) { PuppetSyntax::Templates.new } + let(:conditional_warning_regex) do + if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.6.0') + %r{2: warning: found `= literal' in conditional} + else + %r{2: warning: found = in conditional} + end + end it 'should expect an array of files' do expect { subject.check(nil) }.to raise_error(/Expected an array of files/) @@ -34,7 +41,7 @@ describe PuppetSyntax::Templates do res = subject.check(files) expect(res.size).to eq(1) - expect(res[0]).to match(/2: warning: found = in conditional/) + expect(res[0]).to match(conditional_warning_regex) end it 'should read more than one valid file' do @@ -50,7 +57,7 @@ describe PuppetSyntax::Templates do expect(res.size).to eq(2) expect(res[0]).to match(/2: syntax error, unexpected/) - expect(res[1]).to match(/2: warning: found = in conditional/) + expect(res[1]).to match(conditional_warning_regex) end it 'should ignore a TypeError' do diff --git a/spec/puppet-syntax_spec.rb b/spec/puppet-syntax_spec.rb index 757079085e50675fbabe8079d14dd45b61810859..a056bfc6bb836968b9b5ba93233b8cb2aaea8c72 100644 --- a/spec/puppet-syntax_spec.rb +++ b/spec/puppet-syntax_spec.rb @@ -44,4 +44,12 @@ describe PuppetSyntax do expect(PuppetSyntax.epp_only).to eq(true) end + it 'should support setting paths for manifests, templates and hiera' do + PuppetSyntax.hieradata_paths = [] + expect(PuppetSyntax.hieradata_paths).to eq([]) + PuppetSyntax.manifests_paths = ["**/environments/production/**/*.pp"] + expect(PuppetSyntax.manifests_paths).to eq(["**/environments/production/**/*.pp"]) + PuppetSyntax.templates_paths = [] + expect(PuppetSyntax.templates_paths).to eq([]) + end end