From d215cc136c3cd50261a03537e825cc4fd896fe4a Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Tue, 29 Jan 2013 17:34:35 +0000 Subject: [PATCH] CI tasks cleanup. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11283 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- lib/tasks/ci.rake | 86 ++++++++++++++++-------------------------- lib/tasks/testing.rake | 1 + 2 files changed, 34 insertions(+), 53 deletions(-) diff --git a/lib/tasks/ci.rake b/lib/tasks/ci.rake index aa464fd66..c507b8d88 100644 --- a/lib/tasks/ci.rake +++ b/lib/tasks/ci.rake @@ -8,14 +8,14 @@ task :ci do Rake::Task["ci:teardown"].invoke end -# Tasks can be hooked into by redefining them in a plugin namespace :ci do - desc "Setup Redmine for a new build." + desc "Setup Redmine for a new build" task :setup do - Rake::Task["ci:dump_environment"].invoke + Rake::Task["log:clear"].invoke Rake::Task["db:create"].invoke Rake::Task["db:migrate"].invoke Rake::Task["db:schema:dump"].invoke + Rake::Task["test:scm:setup:all"].invoke Rake::Task["test:scm:update"].invoke end @@ -24,58 +24,38 @@ namespace :ci do Rake::Task["test"].invoke end - # Use this to cleanup after building or run post-build analysis. desc "Finish the build" task :teardown do end - - desc "Creates and configures the databases for the CI server" - task :database do - path = 'config/database.yml' - unless File.exists?(path) - database = ENV['DATABASE_ADAPTER'] - ruby = ENV['RUBY_VER'].gsub('.', '').gsub('-', '') - branch = ENV['BRANCH'].gsub('.', '').gsub('-', '') - dev_db_name = "ci_#{branch}_#{ruby}_dev" - test_db_name = "ci_#{branch}_#{ruby}_test" - - case database - when 'mysql' - raise "Error creating databases" unless - system(%|mysql -u jenkins --password=jenkins -e 'create database #{dev_db_name} character set utf8;'|) && - system(%|mysql -u jenkins --password=jenkins -e 'create database #{test_db_name} character set utf8;'|) - dev_conf = { 'adapter' => (RUBY_VERSION >= '1.9' ? 'mysql2' : 'mysql'), 'database' => dev_db_name, 'host' => 'localhost', 'username' => 'jenkins', 'password' => 'jenkins', 'encoding' => 'utf8' } - test_conf = { 'adapter' => (RUBY_VERSION >= '1.9' ? 'mysql2' : 'mysql'), 'database' => test_db_name, 'host' => 'localhost', 'username' => 'jenkins', 'password' => 'jenkins', 'encoding' => 'utf8' } - when 'postgresql' - raise "Error creating databases" unless - system(%|psql -U jenkins -d postgres -c "create database #{dev_db_name} owner jenkins encoding 'UTF8';"|) && - system(%|psql -U jenkins -d postgres -c "create database #{test_db_name} owner jenkins encoding 'UTF8';"|) - dev_conf = { 'adapter' => 'postgresql', 'database' => dev_db_name, 'host' => 'localhost', 'username' => 'jenkins', 'password' => 'jenkins' } - test_conf = { 'adapter' => 'postgresql', 'database' => test_db_name, 'host' => 'localhost', 'username' => 'jenkins', 'password' => 'jenkins' } - when 'sqlite3' - dev_conf = { 'adapter' => 'sqlite3', 'database' => "db/#{dev_db_name}.sqlite3" } - test_conf = { 'adapter' => 'sqlite3', 'database' => "db/#{test_db_name}.sqlite3" } - when 'sqlserver' - dev_conf = { 'adapter' => 'sqlserver', 'database' => dev_db_name, 'host' => 'mssqlserver', 'port' => 1433, 'username' => 'jenkins', 'password' => 'jenkins' } - test_conf = { 'adapter' => 'sqlserver', 'database' => test_db_name, 'host' => 'mssqlserver', 'port' => 1433, 'username' => 'jenkins', 'password' => 'jenkins' } - else - raise "Unknown database" - end - - File.open(path, 'w') do |f| - f.write YAML.dump({'development' => dev_conf, 'test' => test_conf}) - end - end - end - - desc "Dump the environment information to a BUILD_ENVIRONMENT ENV variable for debugging" - task :dump_environment do - - ENV['BUILD_ENVIRONMENT'] = ['ruby -v', 'gem -v', 'gem list'].collect do |command| - result = `#{command}` - "$ #{command}\n#{result}" - end.join("\n") - - end end +desc "Creates database.yml for the CI server" +file 'config/database.yml' do + require 'yaml' + database = ENV['DATABASE_ADAPTER'] + ruby = ENV['RUBY_VER'].gsub('.', '').gsub('-', '') + branch = ENV['BRANCH'].gsub('.', '').gsub('-', '') + dev_db_name = "ci_#{branch}_#{ruby}_dev" + test_db_name = "ci_#{branch}_#{ruby}_test" + + case database + when 'mysql' + dev_conf = {'adapter' => (RUBY_VERSION >= '1.9' ? 'mysql2' : 'mysql'), 'database' => dev_db_name, 'host' => 'localhost', 'username' => 'jenkins', 'password' => 'jenkins', 'encoding' => 'utf8'} + test_conf = dev_conf.merge('database' => test_db_name) + when 'postgresql' + dev_conf = {'adapter' => 'postgresql', 'database' => dev_db_name, 'host' => 'localhost', 'username' => 'jenkins', 'password' => 'jenkins'} + test_conf = dev_conf.merge('database' => test_db_name) + when 'sqlite3' + dev_conf = {'adapter' => 'sqlite3', 'database' => "db/#{dev_db_name}.sqlite3"} + test_conf = dev_conf.merge('database' => "db/#{test_db_name}.sqlite3") + when 'sqlserver' + dev_conf = {'adapter' => 'sqlserver', 'database' => dev_db_name, 'host' => 'mssqlserver', 'port' => 1433, 'username' => 'jenkins', 'password' => 'jenkins'} + test_conf = dev_conf.merge('database' => test_db_name) + else + abort "Unknown database" + end + + File.open('config/database.yml', 'w') do |f| + f.write YAML.dump({'development' => dev_conf, 'test' => test_conf}) + end +end diff --git a/lib/tasks/testing.rake b/lib/tasks/testing.rake index cfb8e77f9..3601d7660 100644 --- a/lib/tasks/testing.rake +++ b/lib/tasks/testing.rake @@ -102,6 +102,7 @@ namespace :test do Rake::Task['test:rdm_routing'].comment = "Run the routing tests" Rake::TestTask.new(:ui => "db:test:prepare") do |t| + abort "ruby1.9 is required to run test:ui" if RUBY_VERSION < '1.9' t.libs << "test" t.verbose = true t.test_files = FileList['test/ui/**/*_test.rb']