Skip to content

Instantly share code, notes, and snippets.

@mattwynne
Created February 28, 2009 08:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattwynne/71920 to your computer and use it in GitHub Desktop.
Save mattwynne/71920 to your computer and use it in GitHub Desktop.
desc 'Continuous build target. Runs specs and features.'
task :cruise => [] do
# needs grant all on *.* to builder@localhost IDENTIFIED BY 'password' to work
begin
ENV["RAILS_FEATURES_ENV"] = "features"
Dir.chdir(RAILS_ROOT) do
`rm -rf tmp/webrat*.html`
end
[
'cruise:prepare_config',
'cruise:prepare',
'spec',
'features'
].each do |task|
Rake::Task[task].invoke
end
ensure
ENV['CC_BUILD_ARTIFACTS'] ||= RAILS_ROOT + '/tmp'
puts "Copying any webrat dumps to #{ENV['CC_BUILD_ARTIFACTS']}"
system("cp #{RAILS_ROOT}/tmp/webrat*.html #{ENV['CC_BUILD_ARTIFACTS']}")
# Tidy up
Rake::Task['cruise:cleanup'].invoke
end
end
namespace :cruise do
ENVIRONMENTS = [ 'test', 'features' ]
desc 'Prepare environment for cruise control build.'
task :prepare => [
'cruise:generate_db_config',
'db:migrate',
'cruise:create_db',
]
desc 'Drops the temporary test database created in cruise:prepare.'
task :cleanup => [
'cruise:drop_db'
]
desc 'Creates the config files needed for the build to run'
task :prepare_config do
system("cp #{RAILS_ROOT}/config/solr.yml.ci #{RAILS_ROOT}/config/solr.yml")
end
desc 'Creates the temporary test databases'
task :create_db => [
'cruise:generate_db_config',
'cruise:prepare_config'
] do
ENVIRONMENTS.each do |environment|
sh("rake db:create RAILS_ENV=#{environment}") # we do it like this as other tasks (e.g. db:test:prepare) have to be run agaist the development environment
end
end
desc 'Drops the temporary test database'
task :drop_db => [
'cruise:generate_db_config',
'cruise:prepare_config'
] do
ENVIRONMENTS.each do |environment|
sh("rake db:drop RAILS_ENV=#{environment}") # we do it like this as other tasks (e.g. db:test:prepare) have to be run agaist the development environment
end
end
desc 'Generates database.yml using database.yml.ci.erb as a template'
task :generate_db_config do
ENV['CC_BUILD_LABEL'] ||= "123456" #for testing - will be set by Cruise when running for real
require 'erb'
template_file = File.read(RAILS_ROOT + '/config/database.yml.ci.erb')
output_file = RAILS_ROOT + '/config/database.yml'
template = ERB.new(template_file)
FileUtils.rm_f output_file
File.open(output_file, 'w') {|f| f.write(template.result) }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment