From 1241ef7c85e7dc094dd9df79366396a77748e6e6 Mon Sep 17 00:00:00 2001 From: Gene Liverman Date: Sun, 7 May 2017 16:57:16 -0700 Subject: [PATCH] More testing --- .rubocop.yml | 5 +++ Gemfile | 5 ++- Gemfile.lock | 15 ++++++++ Rakefile | 37 +++++++++++++++++-- Vagrantfile | 4 +- bin/dots.rb | 3 +- puppet/Puppetfile | 4 +- puppet/scripts/code_manager_config_version.rb | 10 ----- puppet/scripts/config_version.rb | 5 +-- 9 files changed, 65 insertions(+), 23 deletions(-) create mode 100644 .rubocop.yml delete mode 100755 puppet/scripts/code_manager_config_version.rb diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..8ca7d19 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,5 @@ +AllCops: + Exclude: + - 'vendor/**/*' + - 'spec/fixtures/**/*' + TargetRubyVersion: 2.0 diff --git a/Gemfile b/Gemfile index b409f9b..4c44d2f 100644 --- a/Gemfile +++ b/Gemfile @@ -1,11 +1,13 @@ # vim:ft=ruby source 'https://rubygems.org' +# rubocop:disable ConditionalAssignment if ENV.key?('PUPPET_VERSION') - puppetversion = "#{ENV['PUPPET_VERSION']}" + puppetversion = ENV['PUPPET_VERSION'].to_s else puppetversion = ['~> 4.0'] end +# rubocop:enable ConditionalAssignment group :production do gem 'os', '~> 1.0' @@ -20,6 +22,7 @@ group :development, :unit_tests do gem 'metadata-json-lint', '~> 1.0' gem 'puppetlabs_spec_helper', '~> 1.1' gem 'rspec-puppet', '~> 2.5' + gem 'rubocop', '~> 0.48' gem 'yamllint', '~> 0.0.9' # puppet-lint and plugins diff --git a/Gemfile.lock b/Gemfile.lock index e331bab..d7ae886 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,6 +2,7 @@ GEM remote: https://rubygems.org/ specs: CFPropertyList (2.2.8) + ast (2.3.0) colored (1.2) cri (2.6.1) colored (~> 1.2) @@ -37,6 +38,9 @@ GEM multi_json (1.12.1) multipart-post (2.0.0) os (1.0.0) + parser (2.4.0.0) + ast (~> 2.2) + powerpack (0.1.1) puppet (4.5.3) facter (> 2.0, < 4) hiera (>= 2.0, < 4) @@ -90,6 +94,8 @@ GEM multi_json (~> 1.10) puppet_forge (~> 2.2) semantic_puppet (~> 0.1.0) + rainbow (2.2.2) + rake rake (12.0.0) rspec (3.6.0) rspec-core (~> 3.6.0) @@ -106,12 +112,20 @@ GEM rspec-puppet (2.5.0) rspec rspec-support (3.6.0) + rubocop (0.48.1) + parser (>= 2.3.3.1, < 3.0) + powerpack (~> 0.1) + rainbow (>= 1.99.1, < 3.0) + ruby-progressbar (~> 1.7) + unicode-display_width (~> 1.0, >= 1.0.1) + ruby-progressbar (1.8.1) rugged (0.25.1.1) semantic_puppet (0.1.4) gettext-setup (>= 0.3) spdx-licenses (1.1.0) text (1.3.1) trollop (2.1.2) + unicode-display_width (1.2.1) yamllint (0.0.9) trollop (~> 2) @@ -140,6 +154,7 @@ DEPENDENCIES puppetlabs_spec_helper (~> 1.1) r10k (~> 2.3) rspec-puppet (~> 2.5) + rubocop (~> 0.48) rugged (~> 0.24) yamllint (~> 0.0.9) diff --git a/Rakefile b/Rakefile index 318b828..4e8b100 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,4 @@ +require 'rubocop/rake_task' require 'rubygems' require 'puppetlabs_spec_helper/rake_tasks' require 'puppet-lint/tasks/puppet-lint' @@ -9,28 +10,56 @@ exclude_paths = [ 'spec/**/*' ] +RuboCop::RakeTask.new +RuboCop::RakeTask.new(:rubocop) do |task| + # task.patterns = ['lib/**/*.rb'] + # only show the files with failures + # task.formatters = ['files'] + # don't abort rake on failure + # task.fail_on_error = false +end + PuppetLint.configuration.fail_on_warnings = true PuppetLint.configuration.ignore_paths = exclude_paths -PuppetLint.configuration.log_format = '%{path}:%{linenumber}:%{check}:%{KIND}:%{message}' +PuppetLint.configuration.log_format = + '%{path}:%{linenumber}:%{check}:%{KIND}:%{message}' PuppetSyntax.exclude_paths = exclude_paths desc 'Validate manifests, templates, and ruby files' task :validate do - Dir['puppet/manifests/**/*.pp', 'puppet/site/*/manifests/**/*.pp'].each do |manifest| + Dir['puppet/manifests/**/*.pp', + 'puppet/site/*/manifests/**/*.pp'].each do |manifest| sh "puppet parser validate --noop #{manifest}" end - Dir['bin/**/*.rb', 'spec/**/*.rb'].each do |ruby_file| - # sh "ruby -c #{ruby_file}" unless ruby_file.match? %r{spec\/fixtures} + Dir['bin/**/*.rb', + 'spec/**/*.rb'].each do |ruby_file| + # rubocop:disable RegexpLiteral sh "ruby -c #{ruby_file}" unless ruby_file =~ /spec\/fixtures/ + # rubocop:enable RegexpLiteral end Dir['puppet/site/*/templates/**/*.erb'].each do |template| sh "erb -P -x -T '-' #{template} | ruby -c" end end +YamlLint::RakeTask.new do |yamllint| + yamllint.paths = %w[ + .*.yaml + .*.yml + *.yaml + *.yml + copy/**/*.yml + link/**/*.yml + puppet/hieradata/**/*.yml + puppet/hieradata/**/*.yaml + ] +end + task :tests do Rake::Task[:lint].invoke + Rake::Task[:yamllint].invoke Rake::Task[:validate].invoke + Rake::Task[:rubocop].invoke Rake::Task[:spec].invoke end diff --git a/Vagrantfile b/Vagrantfile index 9b3e97e..6579212 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -1,3 +1,3 @@ -Vagrant.configure("2") do |config| - config.vm.box = "genebean/centos-7-nocm" +Vagrant.configure('2') do |config| + config.vm.box = 'genebean/centos-7-nocm' end diff --git a/bin/dots.rb b/bin/dots.rb index 1991051..0c847fa 100755 --- a/bin/dots.rb +++ b/bin/dots.rb @@ -12,7 +12,8 @@ if OS.mac? elsif Integer(stdout.strip.split('.')[0]) < 10 puts "Wow... you're sure running an old os (#{stdout.strip} to be exact)" else - abort("It seems you are on a Mac but I don't know what to do on v#{stdout.strip}") + abort("It seems you are on a Mac but I don't know what to do on \ + v#{stdout.strip}") end elsif OS.liux? puts 'It seems you are on Linux' diff --git a/puppet/Puppetfile b/puppet/Puppetfile index 0abb83b..60c2dd5 100644 --- a/puppet/Puppetfile +++ b/puppet/Puppetfile @@ -1,4 +1,4 @@ -forge "http://forge.puppetlabs.com" +# rubocop:disable FileName +forge 'http://forge.puppetlabs.com' mod 'puppetlabs-vcsrepo', '1.5.0' - diff --git a/puppet/scripts/code_manager_config_version.rb b/puppet/scripts/code_manager_config_version.rb deleted file mode 100755 index 28afda7..0000000 --- a/puppet/scripts/code_manager_config_version.rb +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env ruby -require 'json' - -environmentpath = ARGV[0] -environment = ARGV[1] - -r10k_deploy_file_path = File.join(environmentpath, environment, '.r10k-deploy.json') - -# output the sha1 from the control-repo -puts JSON.parse(File.read(r10k_deploy_file_path))['signature'] diff --git a/puppet/scripts/config_version.rb b/puppet/scripts/config_version.rb index b34524a..8a19a95 100755 --- a/puppet/scripts/config_version.rb +++ b/puppet/scripts/config_version.rb @@ -1,11 +1,10 @@ #!/usr/bin/env ruby begin require 'rugged' -rescue LoadError => e +rescue LoadError t = Time.new puts t.to_i else - environmentpath = ARGV[0] environment = ARGV[1] @@ -16,7 +15,7 @@ else head_sha = head.target_id # the commit message associated the newest commit - commit = repo.lookup(head_sha) + # commit = repo.lookup(head_sha) # add something to find the remote url