forked from craigwatson/puppet-vmwaretools
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
100 lines (88 loc) · 2.46 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# Rakefile
require 'rubygems'
require 'erb'
require 'open3'
require 'bundler'
Bundler.require(:rake)
require 'rake/clean'
desc "Check puppet module syntax."
task :syntax do
begin
require 'puppet/face'
rescue LoadError
fail 'Cannot load puppet/face, are you sure you have Puppet 2.7?'
end
def validate_manifest(file)
begin
Puppet::Face[:parser, '0.0.1'].validate(file)
rescue Puppet::Error => error
puts error.message
end
end
puts "Checking puppet module syntax..."
FileList['**/*.pp'].each do |manifest|
# exclude the vendor/ dir
next if manifest =~ /vendor/
puts "Evaluating syntax for #{manifest}"
validate_manifest manifest
end
end
desc "test erb syntax"
task :erb do
FileList['**/*.erb'].each do |template|
# exclude the vendor/ dir
next if template =~ /vendor/
puts "Evaluating (erb) template syntax - #{template}"
Open3.popen3('ruby -Ku -c') do |stdin, stdout, stderr|
stdin.puts(ERB.new(File.read(template), nil, '-').src)
stdin.close
if error = ((stderr.readline rescue false))
puts template + error[1..-1].sub(/^[^:]*:\d+: /, '')
exit 1
end
stdout.close rescue false
stderr.close rescue false
end
end
end
desc "Check puppet module code style."
task :style do
begin
require 'puppet-lint'
rescue LoadError
fail 'Cannot load puppet-lint, did you install it?'
end
puts "Checking puppet module code style..."
linter = PuppetLint.new
linter.configuration.log_format = '%{path} line %{linenumber} : %{KIND} %{message}'
linter.configuration.send("disable_80chars")
FileList['**/*.pp'].each do |puppet_file|
# exclude the vendor/ dir
next if puppet_file =~ /vendor/
puts "Evaluating code style for #{puppet_file}"
linter.file = puppet_file
linter.run
end
fail if linter.errors?
end
#TODO: this hasn't been tested yet
#
desc "Generate documentation."
task :doc do |t|
puts "Generating puppet documentation..."
work_dir = File.dirname(__FILE__)
sh %{puppet doc \
--outputdir #{work_dir}/doc \
--mode rdoc \
--manifestdir #{work_dir}/manifests \
--modulepath #{work_dir}/modules \
--manifest #{work_dir}/site.pp}
if File.exists? "#{work_dir}/doc/files/#{work_dir}/modules"
FileUtils.mv "#{work_dir}/doc/files/#{work_dir}", "#{work_dir}/doc/files"
end
Dir.glob('./**/*.*').each do |file|
if File.file? "#{file}"
sh %{sed -i "s@#{work_dir}/@/@g" "#{file}"}
end
end
end