-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathRakefile
77 lines (64 loc) · 1.87 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
require 'rake'
require 'rspec/core/rake_task'
task :build => 'docker:build'
task :ci_build => 'docker:ci_build'
task :test => 'docker:test'
task :publish => 'docker:publish'
task :default => 'docker:build_and_test'
namespace :docker do
task :build_and_test => [:build, :test]
task :default => :build_and_test
desc "Build all containers within a CI environment"
task :ci_build do
require_relative '_scripts/ci-build.rb'
end
desc "Build all containers"
task :build do
require_relative '_scripts/build.rb'
end
tests = []
Dir.glob('./spec/**/*_spec.rb').each do |file|
spec_parts = file.match('\.\/spec\/(.+)\/(.+)_spec\.rb')
test_name = "test:#{spec_parts[1]}:#{spec_parts[2]}"
desc "Run tests from spec in '#{file}'"
RSpec::Core::RakeTask.new(test_name, :ci) do |t, task_args|
t.pattern = file
if task_args[:ci]
if ENV['CIRCLE_TEST_REPORTS']
report_dir = ENV['CIRCLE_TEST_REPORTS'].to_s
else
report_dir = '.'
end
t.rspec_opts = "--format RspecJunitFormatter --out #{report_dir}/rspec.xml"
end
end
tests << test_name
end
desc "Run all tests."
task "test:all" => tests
desc "Run tests in parallel on CircleCI"
task "test:_circleci_parallel" do
if ENV['CIRCLECI']
i = 0
total_nodes = ENV['CIRCLE_NODE_TOTAL'].to_i
node_index = ENV['CIRCLE_NODE_INDEX'].to_i
tests.each do |test|
if ((i % total_nodes) == node_index)
system! "bundle exec rake docker:#{test}[ci]"
end
i += 1
end
else
puts "Not CircleCI, cowardly refusing to run."
end
end
desc "Publish all containers"
task :publish do
require_relative '_scripts/publish.rb'
end
def system! (cmd, ignore_exit = false)
system(cmd)
# Non-zero exit on failure.
exit $?.exitstatus unless $?.success? or ignore_exit
end
end