forked from sous-chefs/zabbix-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
135 lines (114 loc) · 3.38 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/env rake
#
# Berkshelf
#
desc 'Install berkshelf cookbooks locally'
task :berkshelf do
system('berks install')
system('berks update')
end
# Style tests. Rubocop and Foodcritic
namespace :style do
begin
require 'foodcritic'
desc 'Run Chef style checks'
task :foodcritic do
FoodCritic::Rake::LintTask.new(:chef) do |t|
puts 'Running Foodcritic...'
t.options = {
fail_tags: ['any']
}
end
end
rescue LoadError
puts '>>>>> foodcritic gem not loaded, omitting tasks' unless ENV['CI']
end
begin
require 'rubocop/rake_task'
desc 'Run Ruby style checks'
RuboCop::RakeTask.new(:ruby)
rescue LoadError
puts '>>>>> Rubocop gem not loaded, omitting tasks' unless ENV['CI']
end
end
namespace :unit do
begin
require 'rspec/core/rake_task'
desc 'Runs specs with chefspec.'
RSpec::Core::RakeTask.new(:rspec)
rescue LoadError
puts '>>>>> chefspec gem not loaded, omitting tasks' unless ENV['CI']
end
end
# Integration tests. Kitchen.ci
namespace :integration do
begin
desc 'Run integration tests with kitchen-vagrant'
task :vagrant do
require 'kitchen'
Kitchen.logger = Kitchen.default_file_logger
Kitchen::Config.new.instances.each do |instance|
instance.test(:always)
end
end
rescue LoadError
puts '>>>>> kitchen gem not loaded, omitting tasks' unless ENV['CI']
end
begin
desc 'Run integration tests with kitchen-docker'
task :docker do
ENV['KI_DRIVER'] = 'docker'
require 'kitchen'
Kitchen.logger = Kitchen.default_file_logger
Kitchen::Config.new.instances.each do |instance|
instance.test(:always)
end
end
rescue LoadError
puts '>>>>> kitchen gem not loaded, omitting tasks' unless ENV['CI']
end
end
desc 'Run Test Kitchen integration tests'
task 'integration:vagrant'
desc 'Run all style checks'
task style: ['style:foodcritic', 'style:ruby']
desc 'Run all unit tests'
task unit: ['unit:rspec']
desc 'Run style and unit tests for light CI'
task travis: %w(berkshelf style unit)
desc 'Run all tests including test Kitchen with Vagrant'
task default: ['unit', 'style', 'integration:vagrant']
desc 'Run all tests including test Kitchen with Docker'
task docker: ['unit', 'style', 'integration:docker']
desc 'print cookbook version'
task :version do
puts cookbook_version
end
desc 'bump minor version'
task :bump do
versions = cookbook_version.split('.')
versions[2] = versions[2].to_i + 1
version = versions.join('.')
puts "bumping cookbook version to #{version}"
update_cookbook_version version
# run_command "git commit metadata.rb -m 'version bumped to #{version}'"
end
VERSION_WITH_NAME_REGEX = /version\s*'\d+\.\d+\.\d+'/
VERSION_REGEX = /\d+\.\d+\.\d+/
def cookbook_version
# Read in the metadata file
metadata = IO.read(File.join(File.dirname(__FILE__), 'metadata.rb')).chomp
version_with_name = VERSION_WITH_NAME_REGEX.match(metadata)[0]
VERSION_REGEX.match(version_with_name)[0]
end
def update_cookbook_version(version)
# Read in the metadata file
metadata = File.read('metadata.rb')
new_metadata = metadata.gsub(/#{VERSION_WITH_NAME_REGEX}/, "version '#{version}'")
File.open('metadata.rb', 'w') { |file| file.puts new_metadata }
puts
end
def run_command(command)
output = `#{command}`
raise "#{command} failed with:\n#{output}" unless $CHILD_STATUS.success?
end