Skip to content

Commit cd86b88

Browse files
committed
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.
1 parent c64de9b commit cd86b88

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

.travis.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
set -ev
3+
MODS="$(git diff HEAD~1 Puppetfile | grep ^- -B2 | grep mod | cut -d"'" -f2)"
4+
rake validate_puppetfile SPEC_OPTS='--format documentation --color --backtrace' || exit 1
5+
for module in ${MODS}; do
6+
if [ -e ./${module}/Rakefile ]; then
7+
rake test_modules[./${module}/Rakefile] SPEC_OPTS='--format documentation --color --backtrace' || exit 1
8+
else
9+
echo "Missing ./${module}/Rakefile, not running spec tests."
10+
fi
11+
done

.travis.yml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
11
language: ruby
22
install:
3-
- gem install bundler
4-
- gem install rake
5-
- gem install r10k
6-
script: "rake test SPEC_OPTS='--format documentation --color --backtrace'"
3+
script: "./.travis.sh"
74
rvm:
8-
- 1.9.3
95
- 2.0.0
106
matrix:
117
fast_finish: true
128
env:
139
matrix:
14-
- PUPPET_GEM_VERSION="~> 3.3.0"
15-
- PUPPET_GEM_VERSION="~> 3.4.0"
16-
- PUPPET_GEM_VERSION="~> 3.6.0"
1710
- PUPPET_GEM_VERSION="~> 3.7.0"
1811
notifications:
1912
email: false

Rakefile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@ task(:default).clear
22
task :default => :test
33

44
desc 'Run Puppetfile Validation'
5-
task :test => [:validate_puppetfile,:all_modules]
5+
task :test => [:validate_puppetfile,:test_modules]
66

77
desc "Validate the Puppetfile syntax"
88
task :validate_puppetfile do
99
$stderr.puts "---> syntax:puppetfile"
1010
sh "r10k puppetfile check"
1111
end
1212

13-
desc "Run rspec tests for each modules"
14-
task :all_modules do
15-
FileList["*/Rakefile"].each do |project|
13+
desc "Run rspec test on specified modules"
14+
task :test_modules, [:modules] do |t, args|
15+
args.with_defaults(:modules => FileList["*/Rakefile"])
16+
Array(args[:modules]).each do |project|
1617
dir = project.pathmap("%d")
1718
Dir.chdir(dir) do
1819
puts "======"

0 commit comments

Comments
 (0)