To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / lib / tasks / ci.rake @ 1297:0a574315af3e

History | View | Annotate | Download (3.2 KB)

1 14:1d32c0a0efbf Chris
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
11
# Tasks can be hooked into by redefining them in a plugin
12
namespace :ci do
13
  desc "Setup Redmine for a new build."
14
  task :setup do
15
    Rake::Task["ci:dump_environment"].invoke
16 1294:3e4c3460b6ca Chris
    Rake::Task["tmp:clear"].invoke
17 14:1d32c0a0efbf Chris
    Rake::Task["db:create"].invoke
18
    Rake::Task["db:migrate"].invoke
19
    Rake::Task["db:schema:dump"].invoke
20 119:8661b858af72 Chris
    Rake::Task["test:scm:update"].invoke
21 14:1d32c0a0efbf Chris
  end
22
23
  desc "Build Redmine"
24
  task :build do
25
    Rake::Task["test"].invoke
26
  end
27
28
  # Use this to cleanup after building or run post-build analysis.
29
  desc "Finish the build"
30
  task :teardown do
31
  end
32
33 1115:433d4f72a19b Chris
  desc "Creates and configures the databases for the CI server"
34
  task :database do
35
    path = 'config/database.yml'
36
    unless File.exists?(path)
37
      database = ENV['DATABASE_ADAPTER']
38
      ruby = ENV['RUBY_VER'].gsub('.', '').gsub('-', '')
39
      branch = ENV['BRANCH'].gsub('.', '').gsub('-', '')
40
      dev_db_name = "ci_#{branch}_#{ruby}_dev"
41
      test_db_name = "ci_#{branch}_#{ruby}_test"
42
43
      case database
44
      when 'mysql'
45
        raise "Error creating databases" unless
46
          system(%|mysql -u jenkins --password=jenkins -e 'create database #{dev_db_name} character set utf8;'|) &&
47
          system(%|mysql -u jenkins --password=jenkins -e 'create database #{test_db_name} character set utf8;'|)
48
        dev_conf =  { 'adapter' => (RUBY_VERSION >= '1.9' ? 'mysql2' : 'mysql'), 'database' => dev_db_name, 'host' => 'localhost', 'username' => 'jenkins', 'password' => 'jenkins', 'encoding' => 'utf8' }
49
        test_conf = { 'adapter' => (RUBY_VERSION >= '1.9' ? 'mysql2' : 'mysql'), 'database' => test_db_name, 'host' => 'localhost', 'username' => 'jenkins', 'password' => 'jenkins', 'encoding' => 'utf8' }
50
      when 'postgresql'
51
        raise "Error creating databases" unless
52
          system(%|psql -U jenkins -d postgres -c "create database #{dev_db_name} owner jenkins encoding 'UTF8';"|) &&
53
          system(%|psql -U jenkins -d postgres -c "create database #{test_db_name} owner jenkins encoding 'UTF8';"|)
54
        dev_conf =  { 'adapter' => 'postgresql', 'database' => dev_db_name, 'host' => 'localhost', 'username' => 'jenkins', 'password' => 'jenkins' }
55
        test_conf = { 'adapter' => 'postgresql', 'database' => test_db_name, 'host' => 'localhost', 'username' => 'jenkins', 'password' => 'jenkins' }
56
      when 'sqlite3'
57
        dev_conf =  { 'adapter' => 'sqlite3', 'database' => "db/#{dev_db_name}.sqlite3" }
58
        test_conf = { 'adapter' => 'sqlite3', 'database' => "db/#{test_db_name}.sqlite3" }
59
      else
60
        raise "Unknown database"
61
      end
62
63
      File.open(path, 'w') do |f|
64
        f.write YAML.dump({'development' => dev_conf, 'test' => test_conf})
65
      end
66
    end
67
  end
68
69 14:1d32c0a0efbf Chris
  desc "Dump the environment information to a BUILD_ENVIRONMENT ENV variable for debugging"
70
  task :dump_environment do
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 1115:433d4f72a19b Chris
77 14:1d32c0a0efbf Chris
  end
78
end