-
Notifications
You must be signed in to change notification settings - Fork 8
/
Rakefile
72 lines (61 loc) · 1.75 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
#!/usr/bin/env rake
# encoding: utf-8
require 'foodcritic'
require 'rspec/core/rake_task'
require 'rubocop/rake_task'
require 'chef/cookbook/metadata'
# General tasks
# Rubocop before rspec so we don't lint vendored cookbooks
desc 'Run all tests except Kitchen (default task)'
task default: [:lint, :spec]
# Lint the cookbook
desc 'Run all linters: rubocop and foodcritic'
task lint: [:rubocop, :foodcritic]
# Run the whole shebang
desc 'Run all tests'
task test: [:lint, :integration, :spec]
# RSpec
desc 'Run chefspec tests'
task :spec do
puts 'Running Chefspec tests'
RSpec::Core::RakeTask.new(:spec)
end
# Foodcritic
desc 'Run foodcritic lint checks'
task :foodcritic do
if Gem::Version.new('1.9.2') <= Gem::Version.new(RUBY_VERSION.dup)
puts 'Running Foodcritic tests...'
FoodCritic::Rake::LintTask.new do |t|
t.options = { fail_tags: ['any'] }
puts 'done.'
end
else
puts "WARN: foodcritic run is skipped as Ruby #{RUBY_VERSION} is < 1.9.2."
end
end
# Rubocop
desc 'Run Rubocop lint checks'
task :rubocop do
RuboCop::RakeTask.new
end
# Automatically generate a changelog for this project. Only loaded if
# the necessary gem is installed.
begin
# read version from metadata
metadata = Chef::Cookbook::Metadata.new
metadata.instance_eval(File.read('metadata.rb'))
# build changelog
require 'github_changelog_generator/task'
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
config.future_release = "v#{metadata.version}"
end
rescue LoadError
puts '>>>>> GitHub Changelog Generator not loaded, omitting tasks'
end
namespace :test do
task :integration do
concurrency = ENV['CONCURRENCY'] || 1
os = ENV['OS'] || ''
sh('sh', '-c', "bundle exec kitchen test -c #{concurrency} #{os}")
end
end