##// END OF EJS Templates
CI tasks cleanup....
Jean-Philippe Lang -
r11053:d215cc136c3c
parent child
Show More
@@ -1,81 +1,61
1 desc "Run the Continous Integration tests for Redmine"
1 desc "Run the Continous Integration tests for Redmine"
2 task :ci do
2 task :ci do
3 # RAILS_ENV and ENV[] can diverge so force them both to test
3 # RAILS_ENV and ENV[] can diverge so force them both to test
4 ENV['RAILS_ENV'] = 'test'
4 ENV['RAILS_ENV'] = 'test'
5 RAILS_ENV = 'test'
5 RAILS_ENV = 'test'
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
14 Rake::Task["log:clear"].invoke
16 Rake::Task["db:create"].invoke
15 Rake::Task["db:create"].invoke
17 Rake::Task["db:migrate"].invoke
16 Rake::Task["db:migrate"].invoke
18 Rake::Task["db:schema:dump"].invoke
17 Rake::Task["db:schema:dump"].invoke
18 Rake::Task["test:scm:setup:all"].invoke
19 Rake::Task["test:scm:update"].invoke
19 Rake::Task["test:scm:update"].invoke
20 end
20 end
21
21
22 desc "Build Redmine"
22 desc "Build Redmine"
23 task :build do
23 task :build do
24 Rake::Task["test"].invoke
24 Rake::Task["test"].invoke
25 end
25 end
26
26
27 # Use this to cleanup after building or run post-build analysis.
28 desc "Finish the build"
27 desc "Finish the build"
29 task :teardown do
28 task :teardown do
30 end
29 end
30 end
31
31
32 desc "Creates and configures the databases for the CI server"
32 desc "Creates database.yml for the CI server"
33 task :database do
33 file 'config/database.yml' do
34 path = 'config/database.yml'
34 require 'yaml'
35 unless File.exists?(path)
36 database = ENV['DATABASE_ADAPTER']
35 database = ENV['DATABASE_ADAPTER']
37 ruby = ENV['RUBY_VER'].gsub('.', '').gsub('-', '')
36 ruby = ENV['RUBY_VER'].gsub('.', '').gsub('-', '')
38 branch = ENV['BRANCH'].gsub('.', '').gsub('-', '')
37 branch = ENV['BRANCH'].gsub('.', '').gsub('-', '')
39 dev_db_name = "ci_#{branch}_#{ruby}_dev"
38 dev_db_name = "ci_#{branch}_#{ruby}_dev"
40 test_db_name = "ci_#{branch}_#{ruby}_test"
39 test_db_name = "ci_#{branch}_#{ruby}_test"
41
40
42 case database
41 case database
43 when 'mysql'
42 when 'mysql'
44 raise "Error creating databases" unless
45 system(%|mysql -u jenkins --password=jenkins -e 'create database #{dev_db_name} character set utf8;'|) &&
46 system(%|mysql -u jenkins --password=jenkins -e 'create database #{test_db_name} character set utf8;'|)
47 dev_conf = { 'adapter' => (RUBY_VERSION >= '1.9' ? 'mysql2' : 'mysql'), 'database' => dev_db_name, 'host' => 'localhost', 'username' => 'jenkins', 'password' => 'jenkins', 'encoding' => 'utf8' }
43 dev_conf = {'adapter' => (RUBY_VERSION >= '1.9' ? 'mysql2' : 'mysql'), 'database' => dev_db_name, 'host' => 'localhost', 'username' => 'jenkins', 'password' => 'jenkins', 'encoding' => 'utf8'}
48 test_conf = { 'adapter' => (RUBY_VERSION >= '1.9' ? 'mysql2' : 'mysql'), 'database' => test_db_name, 'host' => 'localhost', 'username' => 'jenkins', 'password' => 'jenkins', 'encoding' => 'utf8' }
44 test_conf = dev_conf.merge('database' => test_db_name)
49 when 'postgresql'
45 when 'postgresql'
50 raise "Error creating databases" unless
51 system(%|psql -U jenkins -d postgres -c "create database #{dev_db_name} owner jenkins encoding 'UTF8';"|) &&
52 system(%|psql -U jenkins -d postgres -c "create database #{test_db_name} owner jenkins encoding 'UTF8';"|)
53 dev_conf = { 'adapter' => 'postgresql', 'database' => dev_db_name, 'host' => 'localhost', 'username' => 'jenkins', 'password' => 'jenkins' }
46 dev_conf = {'adapter' => 'postgresql', 'database' => dev_db_name, 'host' => 'localhost', 'username' => 'jenkins', 'password' => 'jenkins'}
54 test_conf = { 'adapter' => 'postgresql', 'database' => test_db_name, 'host' => 'localhost', 'username' => 'jenkins', 'password' => 'jenkins' }
47 test_conf = dev_conf.merge('database' => test_db_name)
55 when 'sqlite3'
48 when 'sqlite3'
56 dev_conf = { 'adapter' => 'sqlite3', 'database' => "db/#{dev_db_name}.sqlite3" }
49 dev_conf = {'adapter' => 'sqlite3', 'database' => "db/#{dev_db_name}.sqlite3"}
57 test_conf = { 'adapter' => 'sqlite3', 'database' => "db/#{test_db_name}.sqlite3" }
50 test_conf = dev_conf.merge('database' => "db/#{test_db_name}.sqlite3")
58 when 'sqlserver'
51 when 'sqlserver'
59 dev_conf = { 'adapter' => 'sqlserver', 'database' => dev_db_name, 'host' => 'mssqlserver', 'port' => 1433, 'username' => 'jenkins', 'password' => 'jenkins' }
52 dev_conf = {'adapter' => 'sqlserver', 'database' => dev_db_name, 'host' => 'mssqlserver', 'port' => 1433, 'username' => 'jenkins', 'password' => 'jenkins'}
60 test_conf = { 'adapter' => 'sqlserver', 'database' => test_db_name, 'host' => 'mssqlserver', 'port' => 1433, 'username' => 'jenkins', 'password' => 'jenkins' }
53 test_conf = dev_conf.merge('database' => test_db_name)
61 else
54 else
62 raise "Unknown database"
55 abort "Unknown database"
63 end
56 end
64
57
65 File.open(path, 'w') do |f|
58 File.open('config/database.yml', 'w') do |f|
66 f.write YAML.dump({'development' => dev_conf, 'test' => test_conf})
59 f.write YAML.dump({'development' => dev_conf, 'test' => test_conf})
67 end
60 end
68 end
61 end
69 end
70
71 desc "Dump the environment information to a BUILD_ENVIRONMENT ENV variable for debugging"
72 task :dump_environment do
73
74 ENV['BUILD_ENVIRONMENT'] = ['ruby -v', 'gem -v', 'gem list'].collect do |command|
75 result = `#{command}`
76 "$ #{command}\n#{result}"
77 end.join("\n")
78
79 end
80 end
81
@@ -1,110 +1,111
1 ### From http://svn.geekdaily.org/public/rails/plugins/generally_useful/tasks/coverage_via_rcov.rake
1 ### From http://svn.geekdaily.org/public/rails/plugins/generally_useful/tasks/coverage_via_rcov.rake
2
2
3 namespace :test do
3 namespace :test do
4 desc 'Measures test coverage'
4 desc 'Measures test coverage'
5 task :coverage do
5 task :coverage do
6 rm_f "coverage"
6 rm_f "coverage"
7 rm_f "coverage.data"
7 rm_f "coverage.data"
8 rcov = "rcov --rails --aggregate coverage.data --text-summary -Ilib --html --exclude gems/"
8 rcov = "rcov --rails --aggregate coverage.data --text-summary -Ilib --html --exclude gems/"
9 files = %w(unit functional integration).map {|dir| Dir.glob("test/#{dir}/**/*_test.rb")}.flatten.join(" ")
9 files = %w(unit functional integration).map {|dir| Dir.glob("test/#{dir}/**/*_test.rb")}.flatten.join(" ")
10 system("#{rcov} #{files}")
10 system("#{rcov} #{files}")
11 end
11 end
12
12
13 desc 'Run unit and functional scm tests'
13 desc 'Run unit and functional scm tests'
14 task :scm do
14 task :scm do
15 errors = %w(test:scm:units test:scm:functionals).collect do |task|
15 errors = %w(test:scm:units test:scm:functionals).collect do |task|
16 begin
16 begin
17 Rake::Task[task].invoke
17 Rake::Task[task].invoke
18 nil
18 nil
19 rescue => e
19 rescue => e
20 task
20 task
21 end
21 end
22 end.compact
22 end.compact
23 abort "Errors running #{errors.to_sentence(:locale => :en)}!" if errors.any?
23 abort "Errors running #{errors.to_sentence(:locale => :en)}!" if errors.any?
24 end
24 end
25
25
26 namespace :scm do
26 namespace :scm do
27 namespace :setup do
27 namespace :setup do
28 desc "Creates directory for test repositories"
28 desc "Creates directory for test repositories"
29 task :create_dir do
29 task :create_dir do
30 FileUtils.mkdir_p Rails.root + '/tmp/test'
30 FileUtils.mkdir_p Rails.root + '/tmp/test'
31 end
31 end
32
32
33 supported_scms = [:subversion, :cvs, :bazaar, :mercurial, :git, :darcs, :filesystem]
33 supported_scms = [:subversion, :cvs, :bazaar, :mercurial, :git, :darcs, :filesystem]
34
34
35 desc "Creates a test subversion repository"
35 desc "Creates a test subversion repository"
36 task :subversion => :create_dir do
36 task :subversion => :create_dir do
37 repo_path = "tmp/test/subversion_repository"
37 repo_path = "tmp/test/subversion_repository"
38 unless File.exists?(repo_path)
38 unless File.exists?(repo_path)
39 system "svnadmin create #{repo_path}"
39 system "svnadmin create #{repo_path}"
40 system "gunzip < test/fixtures/repositories/subversion_repository.dump.gz | svnadmin load #{repo_path}"
40 system "gunzip < test/fixtures/repositories/subversion_repository.dump.gz | svnadmin load #{repo_path}"
41 end
41 end
42 end
42 end
43
43
44 desc "Creates a test mercurial repository"
44 desc "Creates a test mercurial repository"
45 task :mercurial => :create_dir do
45 task :mercurial => :create_dir do
46 repo_path = "tmp/test/mercurial_repository"
46 repo_path = "tmp/test/mercurial_repository"
47 unless File.exists?(repo_path)
47 unless File.exists?(repo_path)
48 bundle_path = "test/fixtures/repositories/mercurial_repository.hg"
48 bundle_path = "test/fixtures/repositories/mercurial_repository.hg"
49 system "hg init #{repo_path}"
49 system "hg init #{repo_path}"
50 system "hg -R #{repo_path} pull #{bundle_path}"
50 system "hg -R #{repo_path} pull #{bundle_path}"
51 end
51 end
52 end
52 end
53
53
54 (supported_scms - [:subversion, :mercurial]).each do |scm|
54 (supported_scms - [:subversion, :mercurial]).each do |scm|
55 desc "Creates a test #{scm} repository"
55 desc "Creates a test #{scm} repository"
56 task scm => :create_dir do
56 task scm => :create_dir do
57 unless File.exists?("tmp/test/#{scm}_repository")
57 unless File.exists?("tmp/test/#{scm}_repository")
58 # system "gunzip < test/fixtures/repositories/#{scm}_repository.tar.gz | tar -xv -C tmp/test"
58 # system "gunzip < test/fixtures/repositories/#{scm}_repository.tar.gz | tar -xv -C tmp/test"
59 system "tar -xvz -C tmp/test -f test/fixtures/repositories/#{scm}_repository.tar.gz"
59 system "tar -xvz -C tmp/test -f test/fixtures/repositories/#{scm}_repository.tar.gz"
60 end
60 end
61 end
61 end
62 end
62 end
63
63
64 desc "Creates all test repositories"
64 desc "Creates all test repositories"
65 task :all => supported_scms
65 task :all => supported_scms
66 end
66 end
67
67
68 desc "Updates installed test repositories"
68 desc "Updates installed test repositories"
69 task :update do
69 task :update do
70 require 'fileutils'
70 require 'fileutils'
71 Dir.glob("tmp/test/*_repository").each do |dir|
71 Dir.glob("tmp/test/*_repository").each do |dir|
72 next unless File.basename(dir) =~ %r{^(.+)_repository$} && File.directory?(dir)
72 next unless File.basename(dir) =~ %r{^(.+)_repository$} && File.directory?(dir)
73 scm = $1
73 scm = $1
74 next unless fixture = Dir.glob("test/fixtures/repositories/#{scm}_repository.*").first
74 next unless fixture = Dir.glob("test/fixtures/repositories/#{scm}_repository.*").first
75 next if File.stat(dir).ctime > File.stat(fixture).mtime
75 next if File.stat(dir).ctime > File.stat(fixture).mtime
76
76
77 FileUtils.rm_rf dir
77 FileUtils.rm_rf dir
78 Rake::Task["test:scm:setup:#{scm}"].execute
78 Rake::Task["test:scm:setup:#{scm}"].execute
79 end
79 end
80 end
80 end
81
81
82 Rake::TestTask.new(:units => "db:test:prepare") do |t|
82 Rake::TestTask.new(:units => "db:test:prepare") do |t|
83 t.libs << "test"
83 t.libs << "test"
84 t.verbose = true
84 t.verbose = true
85 t.test_files = FileList['test/unit/repository*_test.rb'] + FileList['test/unit/lib/redmine/scm/**/*_test.rb']
85 t.test_files = FileList['test/unit/repository*_test.rb'] + FileList['test/unit/lib/redmine/scm/**/*_test.rb']
86 end
86 end
87 Rake::Task['test:scm:units'].comment = "Run the scm unit tests"
87 Rake::Task['test:scm:units'].comment = "Run the scm unit tests"
88
88
89 Rake::TestTask.new(:functionals => "db:test:prepare") do |t|
89 Rake::TestTask.new(:functionals => "db:test:prepare") do |t|
90 t.libs << "test"
90 t.libs << "test"
91 t.verbose = true
91 t.verbose = true
92 t.test_files = FileList['test/functional/repositories*_test.rb']
92 t.test_files = FileList['test/functional/repositories*_test.rb']
93 end
93 end
94 Rake::Task['test:scm:functionals'].comment = "Run the scm functional tests"
94 Rake::Task['test:scm:functionals'].comment = "Run the scm functional tests"
95 end
95 end
96
96
97 Rake::TestTask.new(:rdm_routing) do |t|
97 Rake::TestTask.new(:rdm_routing) do |t|
98 t.libs << "test"
98 t.libs << "test"
99 t.verbose = true
99 t.verbose = true
100 t.test_files = FileList['test/integration/routing/*_test.rb']
100 t.test_files = FileList['test/integration/routing/*_test.rb']
101 end
101 end
102 Rake::Task['test:rdm_routing'].comment = "Run the routing tests"
102 Rake::Task['test:rdm_routing'].comment = "Run the routing tests"
103
103
104 Rake::TestTask.new(:ui => "db:test:prepare") do |t|
104 Rake::TestTask.new(:ui => "db:test:prepare") do |t|
105 abort "ruby1.9 is required to run test:ui" if RUBY_VERSION < '1.9'
105 t.libs << "test"
106 t.libs << "test"
106 t.verbose = true
107 t.verbose = true
107 t.test_files = FileList['test/ui/**/*_test.rb']
108 t.test_files = FileList['test/ui/**/*_test.rb']
108 end
109 end
109 Rake::Task['test:ui'].comment = "Run the UI tests with Capybara (PhantomJS listening on port 4444 is required)"
110 Rake::Task['test:ui'].comment = "Run the UI tests with Capybara (PhantomJS listening on port 4444 is required)"
110 end
111 end
General Comments 0
You need to be logged in to leave comments. Login now