-
Notifications
You must be signed in to change notification settings - Fork 70
/
Rakefile
72 lines (60 loc) · 1.82 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
# encoding: utf-8
# rubocop:disable Style/SymbolArray
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
puts 'Running Foodcritic tests...'
FoodCritic::Rake::LintTask.new do |t|
t.options = { fail_tags: ['any'] }
puts 'done.'
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}"
config.user = 'dev-sec'
config.project = 'chef-ssh-hardening'
config.exclude_labels = ['no changelog', 'question', 'duplicate', 'wontfix', 'invalid']
end
rescue LoadError
puts '>>>>> GitHub Changelog Generator not loaded, omitting tasks'
end
desc 'Run kitchen integration tests'
task :kitchen do
concurrency = ENV['CONCURRENCY'] || 1
instance = ENV['INSTANCE'] || ''
args = ENV['CI'] ? '--destroy=always' : ''
sh('sh', '-c', "bundle exec kitchen test -c #{concurrency} #{args} #{instance}")
end