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