Recently I struggled a bit with our continuous integration system. We had broken tests for several weeks and everybody knows that in this such a situation a continuous integration system is as useful as ladder for a moth. So we obviously had do something against it. After fixing all the tests again I tweaked my Rake cruise task a little bit. The result looks like this:
desc "Task to run all required tasks to perform continuos integration with CruiseControl."
task :cruise => ["db:migrate", "db:test:prepare"] do
build_path = ENV['CC_BUILD_ARTIFACTS']
mkdir_p build_path unless File.directory? build_path if build_path
Rake::Task["log:clear"].invoke
Rake::Task["test:test:clobber_rcov"].invoke
ENV['RCOV_PARAMS'] = "--html --exclude boot.rb"
ENV['SHOW_ONLY'] = 'models,lib,helpers'
Rake::Task["test:units:rcov"].invoke
mv 'coverage/units', "#{build_path}/unit_test_coverage" if build_path
ENV['SHOW_ONLY'] = 'controllers'
Rake::Task["test:functionals:rcov"].invoke
mv 'coverage/functionals', "#{build_path}/functional_test_coverage" if build_path
Rake::Task["test:integration"].invoke
Rake::Task["doc:app"].invoke
mv 'doc/app', "#{build_path}/api_doc" if build_path
end
It is designed to work with CruiseControl.rb. It clears out the log and the rcov results from the previous run and runs the tests using rcov. Because I want to run rcov only against our unit and functional tests the integration suit is run without rcov. Finally it builds the API documentation of the application.
As you can see everything is copied the CruiseControls artifacts directory which makes the artifacts available via the CruiseControl.rb dashboard.
In addition to this task you need the rails_rcov plugin by Coda Hale:
./script/plugin install http://svn.codahale.com/rails_rcov
Acknowledgment: This task is inspired by CruiseControl.rb very owns task to build the tests.
Ah, one more thing. If you are interested in the task for building the documentation, here you go:
namespace :doc do
desc "Generate documentation for the Schwacke Service Application."
Rake::RDocTask.new("app") do |rdoc|
rdoc.rdoc_dir = 'doc/app'
rdoc.template = 'doc/jamis.rb'
rdoc.title = "Schwacke Service Application Documentation"
rdoc.options << '--line-numbers' << '--inline-source'
rdoc.options << '--charset' << 'utf-8'
rdoc.rdoc_files.include('doc/README_FOR_APP')
rdoc.rdoc_files.include('app/**/*.rb')
rdoc.rdoc_files.include('lib/**/*.rb')
end
end
I had to overwrite the default task to use another template. I know there should be a way to use this with a simple option, but for my case it refused to use this option. I use Jamis Buck's great template, which you can find here.
And last but not least one more thing. We use email notification with our continuos integration setup and that works OK, but if you are on a Mac and wish a more integrated notification system I can highly recommend CCMenu. This is a super simple Menu Bar application which shows you the current status of your builds and you can even trigger them via the GUI.
I hope this helped some of you.





