-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathRakefile
84 lines (70 loc) · 2.23 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
LINT_IGNORES = [].freeze
require 'rubygems'
require 'puppetlabs_spec_helper/rake_tasks'
# require 'puppet-lint/tasks/puppet-lint'
desc 'Validate manifests, templates, and ruby files'
task :validate do
PuppetLint.configuration.send('disable_80chars')
PuppetLint.configuration.ignore_paths = ['spec/**/*.pp', 'pkg/**/*.pp']
Dir['manifests/**/*.pp'].each do |manifest|
sh "puppet parser validate --noop #{manifest}"
end
Dir['examples/**/*.pp'].each do |example|
sh "puppet parser validate --noop #{example}"
end
Dir['spec/**/*.rb', 'lib/**/*.rb'].each do |ruby_file|
sh "ruby -c #{ruby_file}" unless ruby_file =~ %r{spec/fixtures}
end
Dir['templates/**/*.erb'].each do |template|
sh "erb -P -x -T '-' #{template} | ruby -c"
end
end
desc 'Checking puppet module code style.'
task :lint do
begin
require 'puppet-lint'
rescue LoadError
raise 'Cannot load puppet-lint.'
end
success = true
linter = PuppetLint.new
linter.configuration.log_format = '%<path>s:%<linenumber>s:%<check>s:%<KIND>s:%<message>s'
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|
parts = puppet_file.split('/')
module_name = parts[1]
next if LINT_IGNORES.include? module_name
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
task default: :spec
spec_pattern = 'spec/**/*_spec.rb'
def_spec_options = '-f d --color'
namespace :spec do
desc 'Run unit tests only'
RSpec::Core::RakeTask.new(:unit) do |spec|
spec.pattern = spec_pattern
spec.rspec_opts = def_spec_options
spec.rspec_opts << ' --tag unit'
end
end
task(:spec).clear.enhance(['rubocop', 'spec:unit'])
desc 'Runs unit tests and linters for manifests, libraries and metadata'
task :test do
Rake::Task[:rubocop].invoke
Rake::Task[:lint].invoke
Rake::Task[:metadata_lint].invoke
Rake::Task[:build].invoke
Rake::Task[:clean].invoke
Rake::Task[:spec].invoke
end