I wrote about Continuous Integration with Ruby on Rails and Subversion before and I finally installed it for a current project. This is indented to be a short HOWTO for it.
CIA, the Continuous Integration Automater, is currently only available through svn. You can get it from http://dev.rubyonrails.com/browser/tools/cia/trunk/.
For those who do not know what CIA is, have a look at the README:
A continuous integration server has a hook into the version control system (Subversion in case of CIA) and when a commit is made it…
1. Find a project that was matched by at least one of the checked in files
2. Checkout that entire project to a temporary directory
3. Run all unit and functional tests on the freshly checked out application
4. Send an email describing the errors if any occurred during the test run
CIA itself is a Rails application that needs to reside on the same machine as the subversion repository. In the CIA application you configure which repositories and which paths of the repositories to use. Test errors will be send by mail and are available in the web-interface.
The following steps will guide you through the setup of CIA.
First checkout CIA to your repository machine. In my case all my web-projects reside under /usr/local/www, so I place CIA there:
# cd /usr/local/www
# svn co http://dev.rubyonrails.org/svn/rails/tools/cia/trunk cia
# cd cia
Now you have to configure CIA like a normal Rails application. CIA needs its own database for managing the projects that should be tested and the build errors.
You can use every supported database like MySQL or PostgreSQL but SQLite seems like a perfect fit for this needs.
The README already has information for creating the CIA-database:
# sqlite db/cia.sqlite # creates and loads the database
sqlite> .read db/sqlite.sql # creates the necessary tables
sqlite> .quit
The default config/database.yml reflects this settings only in production modus. Either change the development environment settings also or make sure that CIA will always use the production settings (like by editing config/environment.rb and set RAILS_ENV = ENV[‘RAILS_ENV’] || ‘production’).
Now configure CIA to use your repository. So start the CIA webapplication. The easiest way is with WEBrick:
# ruby script/server -e production
Point your browser to localhost:3000 and create a new project. The repository has to point to the subversion repository on the server. In my case /home/svn/repos/myproject is a repository created by
# svnadmin create /home/svn/repos/myproject
The path is the branch inside the repository that you want to be checked out and tested like trunk, tags/1.0 or branches/STABLE. Make sure to not use a leading slash.
Now the last thing to do is to configure the subversion post-commit hook so that CIA is called after each commit. Doing so is very easy. Subversion searches the hooks directory inside the repository for scripts that follow a special scheme and calls them with arguments like which repository is used and the revision number.
In my case these scripts are in /home/svn/repos/myproject/hooks:
# ls -laslFh /home/svn/repos/myproject/hooks
2rw-r-r— 1 jw wheel 2.0K Sep 17 23:10 post-commit.tmpl
2rw-r-r— 1 jw wheel 1.6K Sep 17 23:10 post-lock.tmpl
4rw-r-r— 1 jw wheel 2.2K Sep 17 23:10 post-revprop-change.tmpl
2rw-r-r— 1 jw wheel 1.5K Sep 17 23:10 post-unlock.tmpl
4rw-r-r— 1 jw wheel 2.9K Sep 17 23:10 pre-commit.tmpl
2rw-r-r— 1 jw wheel 2.0K Sep 17 23:10 pre-lock.tmpl
4rw-r-r— 1 jw wheel 2.7K Sep 17 23:10 pre-revprop-change.tmpl
2rw-r-r— 1 jw wheel 1.9K Sep 17 23:10 pre-unlock.tmpl
4rw-r-r— 1 jw wheel 2.1K Sep 17 23:10 start-commit.tmpl
The scheme should be obvious. To enable a hook just delete the .tmpl extension or include you own script that uses one of these names.
# mv post-commit.tmpl post-commit
The default post-commit script looks like this:
# grep -v # post-commit
REPOS=”$1”
REV=”$2”
commit-email.pl ”$REPOS” ”$REV” commit-watchers@example.org
log-commit.py—repository ”$REPOS”—revision ”$REV”
Just comment out the last two lines and include this line:
/path/to/cia/script/runner “Agent.build(\”$REPOS\”, $REV)”
In my case it is:
/usr/local/www/cia/script/runner “Agent.build(\”$REPOS\”, $REV)”
This will check out the given revision, repository, and path into the cia/data directory (/usr/local/www/cia/data in my case) as the current commiting user and run all tests.
Beware that the commiting user (the webserver-user if you use mod_dav_svn) must have the permission to write into this directory.
Now every time a new revision gets commited, CIA gets called, checks out the current revision, runs all tests and reports failure or success to the given email addresses.
