forked from cloudfoundry/cloud_controller_ng
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
95 lines (80 loc) · 2.53 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
# Copyright (c) 2009-2012 VMware, Inc.
$:.unshift File.expand_path("../lib", __FILE__)
require "rspec/core/rake_task"
require "ci/reporter/rake/rspec"
require "yaml"
require "sequel"
require "steno"
require "vcap/config"
require "cloud_controller/config"
require "cloud_controller/db"
ENV['CI_REPORTS'] = File.join("spec", "artifacts", "reports")
task default: :spec
namespace :spec do
desc "Run specs producing results for CI"
task :ci => ["ci:setup:rspec"] do
require "simplecov-rcov"
require "simplecov"
# RCov Formatter's output path is hard coded to be "rcov" under
# SimpleCov.coverage_path
SimpleCov.coverage_dir(File.join("spec", "artifacts"))
SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
SimpleCov.start do
add_filter "/spec/"
add_filter "/migrations/"
add_filter '/vendor\/bundle/'
RSpec::Core::Runner.disable_autorun!
end
exit RSpec::Core::Runner.run(['--fail-fast', '--backtrace', 'spec']).to_i
end
end
desc "Run specs"
RSpec::Core::RakeTask.new do |t|
# Keep --backtrace for CI backtraces to be useful
t.rspec_opts = %w(
--backtrace
--format progress
--colour
)
end
desc "Run specs with code coverage"
task :coverage do
require "simplecov"
SimpleCov.coverage_dir(File.join("spec", "artifacts", "coverage"))
SimpleCov.start do
add_filter "/spec/"
add_filter "/migrations/"
RSpec::Core::Runner.disable_autorun!
RSpec::Core::Runner.run(['.'])
end
end
namespace :db do
desc "Create a Sequel migration in ./db/migrate"
task :create_migration do
name = ENV["NAME"]
abort("no NAME specified. use `rake db:create_migration NAME=add_users`") if !name
migrations_dir = File.join("db", "migrations")
version = ENV["VERSION"] || Time.now.utc.strftime("%Y%m%d%H%M%S")
filename = "#{version}_#{name}.rb"
FileUtils.mkdir_p(migrations_dir)
open(File.join(migrations_dir, filename), "w") do |f|
f.write <<-EOF
# Copyright (c) 2009-2012 VMware, Inc.
Sequel.migration do
change do
end
end
EOF
end
end
desc "Perform Sequel migration to database"
task :migrate do
migrations = File.expand_path("../db/migrations", __FILE__)
config_file = ENV["CLOUD_CONTROLLER_NG_CONFIG"]
config_file ||= File.expand_path("../config/cloud_controller.yml", __FILE__)
config = VCAP::CloudController::Config.from_file(config_file)
db_logger = Steno.logger("cc.db.migrations")
db = VCAP::CloudController::DB.connect(db_logger, config[:db])
VCAP::CloudController::DB.apply_migrations(db)
end
end