This repository has been archived by the owner on Dec 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathRakefile
70 lines (55 loc) · 1.59 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
require 'rubygems'
require 'bundler'
Bundler.setup
require 'rake'
require 'foodcritic'
task :default => [:foodcritic]
desc "Runs foodcritic linter"
task :foodcritic do
if Gem::Version.new("1.9.2") <= Gem::Version.new(RUBY_VERSION.dup)
sandbox = File.join(File.dirname(__FILE__), %w{tmp foodcritic})
sandbox_paths = prepare_foodcritic_sandbox(sandbox)
print "Running foodcritic ... "
linter = FoodCritic::Linter.new
result = linter.check \
cookbook_paths: sandbox_paths[:cookbooks],
role_pahts: sandbox_paths[:roles],
exclude_paths: exclude_paths,
fail_tags: ['any']
if result.failed? or result.warnings.size > 0
puts "FAILED"
puts result
fail
else
puts "OK"
puts result
end
if exclude_paths.any?
puts "WARNING! Excluded those files:"
puts exclude_paths.join($/)
end
else
puts "WARNING: Skipped running foodcritic. Ruby 1.9.2 or higher required"
end
end
private
def prepare_foodcritic_sandbox(sandbox)
files = %w{*.md *.rb attributes definitions files libraries providers
recipes resources templates}
rm_rf sandbox
cookbooks_trgt = File.join(sandbox, 'cookbooks')
mkdir_p sandbox
Dir.glob("vendor/cookbooks/*").each do |dir|
trgt = File.join(cookbooks_trgt, File.basename(dir))
mkdir_p trgt
cp_r Dir.glob("#{dir}/{#{files.join(',')}}"), trgt
end
roles_trgt = File.join(sandbox, 'roles')
mkdir_p roles_trgt
cp_r Dir.glob('roles/*.rb'), roles_trgt
puts "\n\n"
{roles: roles_trgt, cookbooks: cookbooks_trgt}
end
def exclude_paths
['devbox/recipes/_mysql.rb']
end