PageRenderTime 40ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/tasks/ci.rake

https://bitbucket.org/eimajenthat/redmine
Ruby | 81 lines | 68 code | 10 blank | 3 comment | 4 complexity | 8502945595e54b01d25b8432fe48bf41 MD5 | raw file
Possible License(s): GPL-2.0
  1. desc "Run the Continous Integration tests for Redmine"
  2. task :ci do
  3. # RAILS_ENV and ENV[] can diverge so force them both to test
  4. ENV['RAILS_ENV'] = 'test'
  5. RAILS_ENV = 'test'
  6. Rake::Task["ci:setup"].invoke
  7. Rake::Task["ci:build"].invoke
  8. Rake::Task["ci:teardown"].invoke
  9. end
  10. # Tasks can be hooked into by redefining them in a plugin
  11. namespace :ci do
  12. desc "Setup Redmine for a new build."
  13. task :setup do
  14. Rake::Task["ci:dump_environment"].invoke
  15. Rake::Task["db:create"].invoke
  16. Rake::Task["db:migrate"].invoke
  17. Rake::Task["db:schema:dump"].invoke
  18. Rake::Task["test:scm:update"].invoke
  19. end
  20. desc "Build Redmine"
  21. task :build do
  22. Rake::Task["test"].invoke
  23. end
  24. # Use this to cleanup after building or run post-build analysis.
  25. desc "Finish the build"
  26. task :teardown do
  27. end
  28. desc "Creates and configures the databases for the CI server"
  29. task :database do
  30. path = 'config/database.yml'
  31. unless File.exists?(path)
  32. database = ENV['DATABASE_ADAPTER']
  33. ruby = ENV['RUBY_VER'].gsub('.', '').gsub('-', '')
  34. branch = ENV['BRANCH'].gsub('.', '').gsub('-', '')
  35. dev_db_name = "ci_#{branch}_#{ruby}_dev"
  36. test_db_name = "ci_#{branch}_#{ruby}_test"
  37. case database
  38. when 'mysql'
  39. raise "Error creating databases" unless
  40. system(%|mysql -u jenkins --password=jenkins -e 'create database #{dev_db_name} character set utf8;'|) &&
  41. system(%|mysql -u jenkins --password=jenkins -e 'create database #{test_db_name} character set utf8;'|)
  42. dev_conf = { 'adapter' => (RUBY_VERSION >= '1.9' ? 'mysql2' : 'mysql'), 'database' => dev_db_name, 'host' => 'localhost', 'username' => 'jenkins', 'password' => 'jenkins', 'encoding' => 'utf8' }
  43. test_conf = { 'adapter' => (RUBY_VERSION >= '1.9' ? 'mysql2' : 'mysql'), 'database' => test_db_name, 'host' => 'localhost', 'username' => 'jenkins', 'password' => 'jenkins', 'encoding' => 'utf8' }
  44. when 'postgresql'
  45. raise "Error creating databases" unless
  46. system(%|psql -U jenkins -d postgres -c "create database #{dev_db_name} owner jenkins encoding 'UTF8';"|) &&
  47. system(%|psql -U jenkins -d postgres -c "create database #{test_db_name} owner jenkins encoding 'UTF8';"|)
  48. dev_conf = { 'adapter' => 'postgresql', 'database' => dev_db_name, 'host' => 'localhost', 'username' => 'jenkins', 'password' => 'jenkins' }
  49. test_conf = { 'adapter' => 'postgresql', 'database' => test_db_name, 'host' => 'localhost', 'username' => 'jenkins', 'password' => 'jenkins' }
  50. when 'sqlite3'
  51. dev_conf = { 'adapter' => 'sqlite3', 'database' => "db/#{dev_db_name}.sqlite3" }
  52. test_conf = { 'adapter' => 'sqlite3', 'database' => "db/#{test_db_name}.sqlite3" }
  53. when 'sqlserver'
  54. dev_conf = { 'adapter' => 'sqlserver', 'database' => dev_db_name, 'host' => 'mssqlserver', 'port' => 1433, 'username' => 'jenkins', 'password' => 'jenkins' }
  55. test_conf = { 'adapter' => 'sqlserver', 'database' => test_db_name, 'host' => 'mssqlserver', 'port' => 1433, 'username' => 'jenkins', 'password' => 'jenkins' }
  56. else
  57. raise "Unknown database"
  58. end
  59. File.open(path, 'w') do |f|
  60. f.write YAML.dump({'development' => dev_conf, 'test' => test_conf})
  61. end
  62. end
  63. end
  64. desc "Dump the environment information to a BUILD_ENVIRONMENT ENV variable for debugging"
  65. task :dump_environment do
  66. ENV['BUILD_ENVIRONMENT'] = ['ruby -v', 'gem -v', 'gem list'].collect do |command|
  67. result = `#{command}`
  68. "$ #{command}\n#{result}"
  69. end.join("\n")
  70. end
  71. end