From 31739eb2c1c238e91c8270acad867ca2ff13c646 Mon Sep 17 00:00:00 2001 From: Gael Chamoulaud Date: Tue, 18 Nov 2014 15:20:46 +0100 Subject: [PATCH 1/2] Add Rakefile to run rspec tests over all the puppet modules. Signed-off-by: Gael Chamoulaud (cherry picked from commit 4244305283339b920c6daaec69460a35e34d72d1) --- .gitignore | 5 +++++ .travis.yml | 19 +++++++++++++++++++ Gemfile | 21 +++++++++++++++++++++ Rakefile | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 77 insertions(+) create mode 100644 .gitignore create mode 100644 .travis.yml create mode 100644 Gemfile create mode 100644 Rakefile diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..1c3d2ce9c --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +*.swp +Gemfile.lock +.vendor +vendor +*/spec/* diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000..d289530b0 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,19 @@ +language: ruby +install: + - gem install bundler + - gem install rake + - gem install r10k +script: "rake test SPEC_OPTS='--format documentation --color --backtrace'" +rvm: + - 1.9.3 + - 2.0.0 +matrix: + fast_finish: true +env: + matrix: + - PUPPET_GEM_VERSION="~> 3.3.0" + - PUPPET_GEM_VERSION="~> 3.4.0" + - PUPPET_GEM_VERSION="~> 3.6.0" + - PUPPET_GEM_VERSION="~> 3.7.0" +notifications: + email: false diff --git a/Gemfile b/Gemfile new file mode 100644 index 000000000..b59363b38 --- /dev/null +++ b/Gemfile @@ -0,0 +1,21 @@ +source ENV['GEM_SOURCE'] || "https://rubygems.org" + +group :development, :test do + gem 'bundler' + gem 'r10k' + gem 'rake', '10.1.1' +end + +if facterversion = ENV['FACTER_GEM_VERSION'] + gem 'facter', facterversion, :require => false +else + gem 'facter', :require => false +end + +if puppetversion = ENV['PUPPET_GEM_VERSION'] + gem 'puppet', puppetversion, :require => false +else + gem 'puppet', :require => false +end + +# vim:ft=ruby diff --git a/Rakefile b/Rakefile new file mode 100644 index 000000000..fa32c7f0a --- /dev/null +++ b/Rakefile @@ -0,0 +1,32 @@ +task(:default).clear +task :default => :test + +desc 'Run Puppetfile Validation' +task :test => [:validate_puppetfile,:all_modules] + +desc "Validate the Puppetfile syntax" +task :validate_puppetfile do + $stderr.puts "---> syntax:puppetfile" + sh "r10k puppetfile check" +end + +desc "Run rspec tests for each modules" +task :all_modules do + FileList["*/Rakefile"].each do |project| + dir = project.pathmap("%d") + Dir.chdir(dir) do + puts "======" + puts "= Running spec test for #{project}" + puts "======" + system('rm -Rf vendor/') + system('rm -Rf .bundle/') + FileUtils.mkdir 'vendor' + ENV['GEM_HOME'] = "vendor" + system('bundle install --path=vendor/ --gemfile=./Gemfile') + ENV['BUNDLE_GEMFILE'] = "./Gemfile" + system('bundle exec rake spec') + system('rm -Rf vendor') + system('rm -Rf .bundle/') + end + end +end From 0765c6fb4d60658e11df9ca1099652a6a7a1632b Mon Sep 17 00:00:00 2001 From: Lukas Bezdicka Date: Thu, 4 Dec 2014 14:42:12 +0100 Subject: [PATCH 2/2] Run travis tests only on changed modules Rakefile is changed to allow specifying modules to test and travis now runs .travis.sh which gets changed modules from Puppetfile. (cherry picked from commit cd86b88ca206decbab2e1fa8afb26c457ec7f80b) --- .travis.sh | 11 +++++++++++ .travis.yml | 9 +-------- Rakefile | 9 +++++---- 3 files changed, 17 insertions(+), 12 deletions(-) create mode 100755 .travis.sh diff --git a/.travis.sh b/.travis.sh new file mode 100755 index 000000000..1f87176e7 --- /dev/null +++ b/.travis.sh @@ -0,0 +1,11 @@ +#!/bin/bash +set -ev +MODS="$(git diff HEAD~1 Puppetfile | grep ^- -B2 | grep mod | cut -d"'" -f2)" +rake validate_puppetfile SPEC_OPTS='--format documentation --color --backtrace' || exit 1 +for module in ${MODS}; do + if [ -e ./${module}/Rakefile ]; then + rake test_modules[./${module}/Rakefile] SPEC_OPTS='--format documentation --color --backtrace' || exit 1 + else + echo "Missing ./${module}/Rakefile, not running spec tests." + fi +done diff --git a/.travis.yml b/.travis.yml index d289530b0..0e8e151dc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,19 +1,12 @@ language: ruby install: - - gem install bundler - - gem install rake - - gem install r10k -script: "rake test SPEC_OPTS='--format documentation --color --backtrace'" +script: "./.travis.sh" rvm: - - 1.9.3 - 2.0.0 matrix: fast_finish: true env: matrix: - - PUPPET_GEM_VERSION="~> 3.3.0" - - PUPPET_GEM_VERSION="~> 3.4.0" - - PUPPET_GEM_VERSION="~> 3.6.0" - PUPPET_GEM_VERSION="~> 3.7.0" notifications: email: false diff --git a/Rakefile b/Rakefile index fa32c7f0a..e5dfbc99b 100644 --- a/Rakefile +++ b/Rakefile @@ -2,7 +2,7 @@ task(:default).clear task :default => :test desc 'Run Puppetfile Validation' -task :test => [:validate_puppetfile,:all_modules] +task :test => [:validate_puppetfile,:test_modules] desc "Validate the Puppetfile syntax" task :validate_puppetfile do @@ -10,9 +10,10 @@ task :validate_puppetfile do sh "r10k puppetfile check" end -desc "Run rspec tests for each modules" -task :all_modules do - FileList["*/Rakefile"].each do |project| +desc "Run rspec test on specified modules" +task :test_modules, [:modules] do |t, args| + args.with_defaults(:modules => FileList["*/Rakefile"]) + Array(args[:modules]).each do |project| dir = project.pathmap("%d") Dir.chdir(dir) do puts "======"