Permalink
Browse files

(maint) Improve TravisCI testing

Adds support for parser validation as well as linting.
  • Loading branch information...
1 parent e712d9f commit 01719c67994407d20563a40d5663aa97138e70ec @xaque208 committed Dec 14, 2013
Showing with 69 additions and 1 deletion.
  1. +1 −0 .puppet-lintrc
  2. +1 −1 .travis.yml
  3. +1 −0 Gemfile
  4. +66 −0 Rakefile
View
@@ -0,0 +1 @@
+--no-single_quote_string_with_variables-check
View
@@ -1,4 +1,4 @@
-script: bundle exec rspec
+script: rake ci:all
language: ruby
rvm:
- "1.8.7"
View
@@ -3,3 +3,4 @@ gem 'rspec'
gem 'rspec-mocks'
gem 'rspec-expectations'
gem 'puppet'
+gem 'puppet-lint'
View
@@ -0,0 +1,66 @@
+# Thank rtyler for donating some code.
+#
+# https://gist.github.com/rtyler/3041462
+#
+LINT_IGNORES = ['rvm']
+
+namespace :ci do
+ task :all do
+ Rake::Task['ci:validate'].invoke
+ Rake::Task['ci:spec'].invoke
+ Rake::Task['ci:lint'].invoke
+ end
+
+ desc "Validate the manifests"
+ task :validate do
+ FileList['**/*.pp'].each do |puppet_file|
+ puts "Validating code parsing for #{puppet_file}"
+ %x{puppet parser validate #{puppet_file}}
+ end
+ end
+
+ desc "Run spec tests"
+ task :spec do
+ puts "Executing spec tests"
+ %x{bundle exec rspec}
+ end
+
+ desc "Check puppet module code style."
+ task :lint do
+ begin
+ require 'puppet-lint'
+ rescue LoadError
+ fail 'Cannot load puppet-lint, did you install it?'
+ end
+
+ success = true
+
+ linter = PuppetLint.new
+ linter.configuration.log_format =
+ '%{path}:%{linenumber}:%{check}:%{KIND}:%{message}'
+
+ lintrc = ".puppet-lintrc"
+ if File.file?(lintrc)
+ File.read(lintrc).each_line do |line|
+ check = line.sub(/--no-([a-zA-Z0-9_]*)-check/, '\1').chomp
+ linter.configuration.send("disable_#{check}")
+ end
+ end
+
+ FileList['**/*.pp'].each do |puppet_file|
+ if puppet_file.start_with? 'modules'
+ parts = puppet_file.split('/')
+ module_name = parts[1]
+ next if LINT_IGNORES.include? module_name
+ end
+
+ puts "Evaluating code style for #{puppet_file}"
+ linter.file = puppet_file
+ linter.run
+ success = false if linter.errors?
+ end
+
+ abort "Checking puppet module code style FAILED" if success.is_a?(FalseClass)
+ end
+end
+

0 comments on commit 01719c6

Please sign in to comment.