-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathRakefile
208 lines (188 loc) · 5.95 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
require 'rake'
require 'rake/packagetask'
require 'rubygems/package_task'
require 'rspec/core/rake_task'
require 'git'
require 'net/ssh'
require 'English'
require 'control_spec_helper/util'
task :default do
sh %(rake -T)
end
require 'fileutils'
RSpec::Core::RakeTask.new(:spec)
Rake::Task[:spec].enhance ['fixtures:prep']
def version
require 'control_spec_helper/version'
ControlSpecHelper::Version::STRING
end
namespace :package do
desc 'Create the gem'
task :gem do
spec = Gem::Specification.load('control_spec_helper.gemspec')
begin
Dir.mkdir('pkg')
rescue => e
puts e
end
if Gem::Version.new(`gem -v`) >= Gem::Version.new('2.0.0.a')
Gem::Package.build(spec)
else
Gem::Builder.new(spec).build
end
FileUtils.move("control_spec_helper-#{version}.gem", 'pkg')
end
end
desc 'Run rubocop against tree'
task :rubocop do
puts `rubocop`
end
desc 'Cleanup pkg directory'
task :clean do
FileUtils.rm_rf('pkg')
end
namespace :fixtures do
desc 'Prepare fixtures directory'
task :create do
FileUtils.mkdir('fixtures') unless File.directory?('fixtures')
end
task :shared_prep do
unless File.exist?('fixtures/puppet-control')
puts 'Cloning puppet_control repository...'
Git.clone('https://github.com/slalompdx/puppet-control.git',
'puppet-control',
path: 'fixtures',
branch: 'fixture')
end
end
desc 'Remove fixtures directory'
task :clean do
if File.exist?('fixtures/puppet-control')
Dir.chdir('fixtures/puppet-control') do
`unset RUBYLIB ; vagrant destroy -f`
end
end
FileUtils.rm_rf('fixtures')
end
desc 'Bring up test vm'
task vm: [:create, 'package:gem', :shared_prep] do
Bundler.with_clean_env do
Dir.chdir("#{File.dirname(__FILE__)}/fixtures/puppet-control") do
puts 'Bringing up test VM...'
IO.popen('unset RUBYLIB ; vagrant up') do |io|
io.each { |s| print s }
end
end
end
end
desc 'Copy built gem into fixtures directory'
task copy_gem: [:create, 'package:gem', :shared_prep] do
Bundler.with_clean_env do
Dir.chdir("#{File.dirname(__FILE__)}/fixtures/puppet-control") do
puts 'Copying control_spec_helper into fixtures'
FileUtils.mkdir_p('./vendor/cache') unless File.exist?('./vendor/cache')
FileUtils.mkdir_p('./vendor/gems') unless File.exist?('./vendor/gems')
FileUtils.cp("../../pkg/control_spec_helper-#{version}.gem",
'./vendor/cache')
`gem unpack \
./vendor/cache/*.gem \
--target=./fixtures/puppet-control/vendor/gems/`
end
end
end
desc 'Install control_spec_helper gem on client vm'
task install_gem: [:copy_gem] do
Bundler.with_clean_env do
Dir.chdir("#{File.dirname(__FILE__)}/fixtures/puppet-control") do
connection = build_vagrant_connection(vagrant_ssh_config)
puts 'Installing control_spec_helper gem...'
ssh_exec!(
connection,
'cd /vagrant && gem install ./vendor/cache/*.gem --no-ri --no-rdoc'
)
connection.close
end
end
end
desc 'Run bundle install on client vm'
task bundle_install: [:install_gem] do
Bundler.with_clean_env do
Dir.chdir("#{File.dirname(__FILE__)}/fixtures/puppet-control") do
connection = build_vagrant_connection(vagrant_ssh_config)
puts 'Running bundle install...'
ssh_exec!(connection, 'cd /vagrant && bundle install --path=vendor/')
connection.close
end
end
end
desc 'Install vagrant on client vm'
task install_vagrant: [:vm] do
Bundler.with_clean_env do
Dir.chdir("#{File.dirname(__FILE__)}/fixtures/puppet-control") do
connection = build_vagrant_connection(vagrant_ssh_config)
response = ssh_exec!(connection, 'rpm -qa | grep vagrant')
if response[2] != 0
puts 'Installing vagrant...'
ssh_exec!(
connection,
'sudo rpm -ivh https://releases.hashicorp.com/'\
'vagrant/1.8.1/vagrant_1.8.1_x86_64.rpm'
)
else
puts 'Skipping vagrant install, already present...'
end
end
end
end
desc 'Link puppet binary on client vm'
task link_puppet: [:vm] do
Bundler.with_clean_env do
Dir.chdir("#{File.dirname(__FILE__)}/fixtures/puppet-control") do
connection = build_vagrant_connection(vagrant_ssh_config)
puts 'Linking puppet binary...'
ssh_exec!(connection,
'sudo ls /usr/bin/puppet || '\
'sudo ln -s /opt/puppetlabs/bin/puppet /usr/bin/puppet'
)
connection.close
end
end
end
desc 'Run r10k on client vm'
task run_r10k: [:vm] do
Bundler.with_clean_env do
Dir.chdir("#{File.dirname(__FILE__)}/fixtures/puppet-control") do
connection = build_vagrant_connection(vagrant_ssh_config)
puts 'Running r10k on vm...'
ssh_exec!(connection,
'cd /vagrant ; bundle exec rake r10k')
connection.close
end
end
end
desc 'Convenience method - Update gem on existing vm'
task :update_gem do
Rake::Task['package:gem'].invoke
Rake::Task['fixtures:copy_gem'].invoke
Rake::Task['fixtures:install_gem'].invoke
Rake::Task['fixtures:bundle_install'].invoke
end
desc 'Prepare fixtures repository'
task prep: [:create, 'package:gem', :shared_prep] do
Rake::Task['fixtures:vm'].invoke
Rake::Task['fixtures:copy_gem'].invoke
Rake::Task['fixtures:install_gem'].invoke
Rake::Task['fixtures:bundle_install'].invoke
Rake::Task['fixtures:install_vagrant'].invoke
Rake::Task['fixtures:link_puppet'].invoke
Rake::Task['fixtures:run_r10k'].invoke
end
end
desc 'Execute unit tests'
task unit: ['fixtures:shared_prep'] do
exec 'bundle exec rspec -P spec/unit/*_spec.rb'
end
desc 'Execute acceptance tests'
task acceptance: ['fixtures:prep'] do
exec 'bundle exec rspec -P spec/tasks/*_spec.rb'
end