Chris@14: desc "Run the Continous Integration tests for Redmine" Chris@14: task :ci do Chris@14: # RAILS_ENV and ENV[] can diverge so force them both to test Chris@14: ENV['RAILS_ENV'] = 'test' Chris@14: RAILS_ENV = 'test' Chris@14: Rake::Task["ci:setup"].invoke Chris@14: Rake::Task["ci:build"].invoke Chris@14: Rake::Task["ci:teardown"].invoke Chris@14: end Chris@14: Chris@14: # Tasks can be hooked into by redefining them in a plugin Chris@14: namespace :ci do Chris@14: desc "Setup Redmine for a new build." Chris@14: task :setup do Chris@14: Rake::Task["ci:dump_environment"].invoke Chris@1294: Rake::Task["tmp:clear"].invoke Chris@14: Rake::Task["db:create"].invoke Chris@14: Rake::Task["db:migrate"].invoke Chris@14: Rake::Task["db:schema:dump"].invoke Chris@119: Rake::Task["test:scm:update"].invoke Chris@14: end Chris@14: Chris@14: desc "Build Redmine" Chris@14: task :build do Chris@14: Rake::Task["test"].invoke Chris@14: end Chris@14: Chris@14: # Use this to cleanup after building or run post-build analysis. Chris@14: desc "Finish the build" Chris@14: task :teardown do Chris@14: end Chris@14: Chris@1115: desc "Creates and configures the databases for the CI server" Chris@1115: task :database do Chris@1115: path = 'config/database.yml' Chris@1115: unless File.exists?(path) Chris@1115: database = ENV['DATABASE_ADAPTER'] Chris@1115: ruby = ENV['RUBY_VER'].gsub('.', '').gsub('-', '') Chris@1115: branch = ENV['BRANCH'].gsub('.', '').gsub('-', '') Chris@1115: dev_db_name = "ci_#{branch}_#{ruby}_dev" Chris@1115: test_db_name = "ci_#{branch}_#{ruby}_test" Chris@1115: Chris@1115: case database Chris@1115: when 'mysql' Chris@1115: raise "Error creating databases" unless Chris@1115: system(%|mysql -u jenkins --password=jenkins -e 'create database #{dev_db_name} character set utf8;'|) && Chris@1115: system(%|mysql -u jenkins --password=jenkins -e 'create database #{test_db_name} character set utf8;'|) Chris@1115: dev_conf = { 'adapter' => (RUBY_VERSION >= '1.9' ? 'mysql2' : 'mysql'), 'database' => dev_db_name, 'host' => 'localhost', 'username' => 'jenkins', 'password' => 'jenkins', 'encoding' => 'utf8' } Chris@1115: test_conf = { 'adapter' => (RUBY_VERSION >= '1.9' ? 'mysql2' : 'mysql'), 'database' => test_db_name, 'host' => 'localhost', 'username' => 'jenkins', 'password' => 'jenkins', 'encoding' => 'utf8' } Chris@1115: when 'postgresql' Chris@1115: raise "Error creating databases" unless Chris@1115: system(%|psql -U jenkins -d postgres -c "create database #{dev_db_name} owner jenkins encoding 'UTF8';"|) && Chris@1115: system(%|psql -U jenkins -d postgres -c "create database #{test_db_name} owner jenkins encoding 'UTF8';"|) Chris@1115: dev_conf = { 'adapter' => 'postgresql', 'database' => dev_db_name, 'host' => 'localhost', 'username' => 'jenkins', 'password' => 'jenkins' } Chris@1115: test_conf = { 'adapter' => 'postgresql', 'database' => test_db_name, 'host' => 'localhost', 'username' => 'jenkins', 'password' => 'jenkins' } Chris@1115: when 'sqlite3' Chris@1115: dev_conf = { 'adapter' => 'sqlite3', 'database' => "db/#{dev_db_name}.sqlite3" } Chris@1115: test_conf = { 'adapter' => 'sqlite3', 'database' => "db/#{test_db_name}.sqlite3" } Chris@1115: else Chris@1115: raise "Unknown database" Chris@1115: end Chris@1115: Chris@1115: File.open(path, 'w') do |f| Chris@1115: f.write YAML.dump({'development' => dev_conf, 'test' => test_conf}) Chris@1115: end Chris@1115: end Chris@1115: end Chris@1115: Chris@14: desc "Dump the environment information to a BUILD_ENVIRONMENT ENV variable for debugging" Chris@14: task :dump_environment do Chris@14: Chris@14: ENV['BUILD_ENVIRONMENT'] = ['ruby -v', 'gem -v', 'gem list'].collect do |command| Chris@14: result = `#{command}` Chris@14: "$ #{command}\n#{result}" Chris@14: end.join("\n") Chris@1115: Chris@14: end Chris@14: end Chris@14: