-
Notifications
You must be signed in to change notification settings - Fork 8
/
Rakefile
113 lines (99 loc) · 2.5 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
101
102
103
104
105
106
107
108
109
110
111
112
113
require 'rspec/core/rake_task'
require 'foodcritic'
require 'kitchen'
directory = File.expand_path(File.dirname(__FILE__))
desc 'Sets up knife, and vendors cookbooks'
task :setup_test_environment do
File.open('knife.rb', 'w+') do |file|
file.write <<-EOF
log_level :debug
log_location STDOUT
cookbook_path ['.', 'berks-cookbooks/' ]
EOF
end
sh('berks vendor')
end
desc 'verifies version and changelog'
task :verify_version do
def old_version?
f = `git show master:metadata.rb`
f.each_line do |line|
if line =~ /^version/
_k, v = line.strip.split
@old_version = v
end
end
@old_version
end
def new_version?
f = File.read('metadata.rb')
f.each_line do |line|
if line =~ /^version/
_k, v = line.strip.split
@new_version = v
end
end
@new_version
end
if `git rev-parse --abbrev-ref HEAD`.strip != ('master' && 'HEAD')
old_version = old_version?.tr('\'', '')
new_version = new_version?.tr('\'', '')
puts "Verifying Metdata Version - Old:#{old_version}, New:#{new_version}"
if old_version == new_version
raise 'You need to increment version before test will pass'
end
puts "Verifying Changelog Contains Version #{new_version}"
counter = 0
f = File.read('CHANGELOG.md')
f.each_line do |line|
counter += 1 if line.match new_version
end
raise 'CHANGELOG update needed' if counter == 0
end
end
desc 'runs cookstyle'
task cookstyle: [:setup_test_environment] do
cmd = 'chef exec cookstyle -D --format offenses --display-cop-names'
puts cmd
sh(cmd)
end
desc 'runs foodcritic'
task :foodcritic do
cmd = "chef exec foodcritic --epic-fail any #{directory}"
puts cmd
sh(cmd)
end
desc 'runs foodcritic linttask'
task :fc_new do
FoodCritic::Rake::LintTask.new(:chef) do |t|
t.options = {
fail_tags: ['any']
}
end
end
desc 'runs rspec'
task :rspec do
cmd = 'chef exec rspec --color --format documentation'
puts cmd
sh(cmd)
end
desc 'runs testkitchen'
task :kitchen do
cmd = 'chef exec kitchen test --concurrency=2'
puts cmd
sh(cmd)
end
desc 'clean up test files'
task :clean do
cmd = 'rm -fr berks-cookbooks knife.rb'
puts cmd
sh(cmd)
end
desc 'runs all tests except kitchen'
task except_kitchen: [:verify_version, :cookstyle, :foodcritic, :rspec] do
puts 'running all tests except kitchen'
end
desc 'runs all tests'
task all: [:except_kitchen, :kitchen] do
puts 'running all tests'
end