comparison lib/tasks/ci.rake @ 1464:261b3d9a4903 redmine-2.4

Update to Redmine 2.4 branch rev 12663
author Chris Cannam
date Tue, 14 Jan 2014 14:37:42 +0000
parents 3e4c3460b6ca
children b450a9d58aed
comparison
equal deleted inserted replaced
1296:038ba2d95de8 1464:261b3d9a4903
6 Rake::Task["ci:setup"].invoke 6 Rake::Task["ci:setup"].invoke
7 Rake::Task["ci:build"].invoke 7 Rake::Task["ci:build"].invoke
8 Rake::Task["ci:teardown"].invoke 8 Rake::Task["ci:teardown"].invoke
9 end 9 end
10 10
11 # Tasks can be hooked into by redefining them in a plugin
12 namespace :ci do 11 namespace :ci do
13 desc "Setup Redmine for a new build." 12 desc "Setup Redmine for a new build"
14 task :setup do 13 task :setup do
15 Rake::Task["ci:dump_environment"].invoke
16 Rake::Task["tmp:clear"].invoke 14 Rake::Task["tmp:clear"].invoke
17 Rake::Task["db:create"].invoke 15 Rake::Task["log:clear"].invoke
16 Rake::Task["db:create:all"].invoke
18 Rake::Task["db:migrate"].invoke 17 Rake::Task["db:migrate"].invoke
19 Rake::Task["db:schema:dump"].invoke 18 Rake::Task["db:schema:dump"].invoke
19 Rake::Task["test:scm:setup:all"].invoke
20 Rake::Task["test:scm:update"].invoke 20 Rake::Task["test:scm:update"].invoke
21 end 21 end
22 22
23 desc "Build Redmine" 23 desc "Build Redmine"
24 task :build do 24 task :build do
25 Rake::Task["test"].invoke 25 Rake::Task["test"].invoke
26 # Rake::Task["test:ui"].invoke if RUBY_VERSION >= '1.9.3'
26 end 27 end
27 28
28 # Use this to cleanup after building or run post-build analysis.
29 desc "Finish the build" 29 desc "Finish the build"
30 task :teardown do 30 task :teardown do
31 end 31 end
32 end
32 33
33 desc "Creates and configures the databases for the CI server" 34 desc "Creates database.yml for the CI server"
34 task :database do 35 file 'config/database.yml' do
35 path = 'config/database.yml' 36 require 'yaml'
36 unless File.exists?(path) 37 database = ENV['DATABASE_ADAPTER']
37 database = ENV['DATABASE_ADAPTER'] 38 ruby = ENV['RUBY_VER'].gsub('.', '').gsub('-', '')
38 ruby = ENV['RUBY_VER'].gsub('.', '').gsub('-', '') 39 branch = ENV['BRANCH'].gsub('.', '').gsub('-', '')
39 branch = ENV['BRANCH'].gsub('.', '').gsub('-', '') 40 dev_db_name = "ci_#{branch}_#{ruby}_dev"
40 dev_db_name = "ci_#{branch}_#{ruby}_dev" 41 test_db_name = "ci_#{branch}_#{ruby}_test"
41 test_db_name = "ci_#{branch}_#{ruby}_test"
42 42
43 case database 43 case database
44 when 'mysql' 44 when 'mysql'
45 raise "Error creating databases" unless 45 dev_conf = {'adapter' => (RUBY_VERSION >= '1.9' ? 'mysql2' : 'mysql'),
46 system(%|mysql -u jenkins --password=jenkins -e 'create database #{dev_db_name} character set utf8;'|) && 46 'database' => dev_db_name, 'host' => 'localhost',
47 system(%|mysql -u jenkins --password=jenkins -e 'create database #{test_db_name} character set utf8;'|) 47 'username' => 'jenkins', 'password' => 'jenkins',
48 dev_conf = { 'adapter' => (RUBY_VERSION >= '1.9' ? 'mysql2' : 'mysql'), 'database' => dev_db_name, 'host' => 'localhost', 'username' => 'jenkins', 'password' => 'jenkins', 'encoding' => 'utf8' } 48 'encoding' => 'utf8'}
49 test_conf = { 'adapter' => (RUBY_VERSION >= '1.9' ? 'mysql2' : 'mysql'), 'database' => test_db_name, 'host' => 'localhost', 'username' => 'jenkins', 'password' => 'jenkins', 'encoding' => 'utf8' } 49 test_conf = dev_conf.merge('database' => test_db_name)
50 when 'postgresql' 50 when 'postgresql'
51 raise "Error creating databases" unless 51 dev_conf = {'adapter' => 'postgresql', 'database' => dev_db_name,
52 system(%|psql -U jenkins -d postgres -c "create database #{dev_db_name} owner jenkins encoding 'UTF8';"|) && 52 'host' => 'localhost',
53 system(%|psql -U jenkins -d postgres -c "create database #{test_db_name} owner jenkins encoding 'UTF8';"|) 53 'username' => 'jenkins', 'password' => 'jenkins'}
54 dev_conf = { 'adapter' => 'postgresql', 'database' => dev_db_name, 'host' => 'localhost', 'username' => 'jenkins', 'password' => 'jenkins' } 54 test_conf = dev_conf.merge('database' => test_db_name)
55 test_conf = { 'adapter' => 'postgresql', 'database' => test_db_name, 'host' => 'localhost', 'username' => 'jenkins', 'password' => 'jenkins' } 55 when /sqlite3/
56 when 'sqlite3' 56 dev_conf = {'adapter' => (Object.const_defined?(:JRUBY_VERSION) ?
57 dev_conf = { 'adapter' => 'sqlite3', 'database' => "db/#{dev_db_name}.sqlite3" } 57 'jdbcsqlite3' : 'sqlite3'),
58 test_conf = { 'adapter' => 'sqlite3', 'database' => "db/#{test_db_name}.sqlite3" } 58 'database' => "db/#{dev_db_name}.sqlite3"}
59 else 59 test_conf = dev_conf.merge('database' => "db/#{test_db_name}.sqlite3")
60 raise "Unknown database" 60 when 'sqlserver'
61 end 61 dev_conf = {'adapter' => 'sqlserver', 'database' => dev_db_name,
62 62 'host' => 'mssqlserver', 'port' => 1433,
63 File.open(path, 'w') do |f| 63 'username' => 'jenkins', 'password' => 'jenkins'}
64 f.write YAML.dump({'development' => dev_conf, 'test' => test_conf}) 64 test_conf = dev_conf.merge('database' => test_db_name)
65 end 65 else
66 end 66 abort "Unknown database"
67 end 67 end
68 68
69 desc "Dump the environment information to a BUILD_ENVIRONMENT ENV variable for debugging" 69 File.open('config/database.yml', 'w') do |f|
70 task :dump_environment do 70 f.write YAML.dump({'development' => dev_conf, 'test' => test_conf})
71
72 ENV['BUILD_ENVIRONMENT'] = ['ruby -v', 'gem -v', 'gem list'].collect do |command|
73 result = `#{command}`
74 "$ #{command}\n#{result}"
75 end.join("\n")
76
77 end 71 end
78 end 72 end
79