forked from sous-chefs/kafka
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
90 lines (78 loc) · 2.26 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
# encoding: utf-8
require 'rspec/core/rake_task'
require 'foodcritic'
require 'tmpdir'
RSpec::Core::RakeTask.new(:spec)
FoodCritic::Rake::LintTask.new
desc 'Run ChefSpec and FoodCritic'
task :test do
Rake::Task['foodcritic'].execute
Rake::Task['spec'].execute
end
desc 'Package the latest version as a .tar.gz archive'
task :package => :spec do
contents = Dir.glob('*')
contents.reject! { |path| path.start_with?('.') }
contents.reject! { |path| %w(test spec gemfiles pkg).include?(path) }
contents.select! { |path| File.directory?(path) }
contents << 'metadata.rb'
contents << 'README.md'
version = %x(git tag -l | tail -1).strip
release_name = %(kafka-cookbook-#{version})
archive = %(#{release_name}.tar.gz)
current_directory = File.expand_path('..', __FILE__)
unless File.exist?(archive)
Dir.mktmpdir do |sandbox_path|
File.join(sandbox_path, release_name).tap do |cbk|
Dir.mkdir(cbk)
FileUtils.cp_r(contents, cbk)
end
Dir.chdir(sandbox_path) do
%x(tar -czf #{archive} #{release_name})
FileUtils.mv(archive, current_directory)
end
end
puts %(Created archive of #{version} as #{archive})
else
puts %(#{archive} already exist, exiting...)
exit(1)
end
end
desc 'Test all v0.8.x versions'
namespace :test do
task :docker do
docker_status = %x{boot2docker status}.strip
if docker_status != 'running'
%x{boot2docker poweroff}
%x{boot2docker up}
end
versions = %w[0.8.0 0.8.1 0.8.1.1 0.8.2-beta]
versions.each do |version|
puts '>>> Start testing version %s' % version
envs = []
envs << %(KITCHEN_LOCAL_YAML='.kitchen.docker.yml')
envs << %(KAFKA_VERSION=#{version})
envs << %(SCALA_VERSION=2.8.0) if version == '0.8.0'
envs = envs.join(' ')
output = []
rd, wr = IO.pipe
pid = Process.fork do
$stdout.reopen(wr)
rd.close
exec(%(#{envs} bundle exec kitchen test))
end
wr.close
rd.each do |line|
output << line
end
_, status = Process.waitpid2(pid)
if status.success?
puts '>>> Done testing version %s' % version
else
puts output
puts '>>> Run failed, see output above ^'
break
end
end
end
end