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