In the past I have used jenkins for CI in my projects with little success. I think it was mainly because of my own sloppy setup.
However this time I wanted to do CI in the most simple way. I did some research and found this good post http://blog.javabien.net/2009/12/01/serverless-ci-with-git/. The following setup is different that the one in the above blog post, but the idea is the same, have your CI run on your local machine rather than have a server for it.
I have used pre-commit
hooks in the past. It sounds nice till you want to do a quick commit and you use --no-verify
and once you do that you start doing the same for subsequent commits.
For this I use a post-commit
hook which triggers our CI build in the background logging all the info to /tmp/ci.log
. This avoids unnecessary friction. So, when I commit it doesn’t take forever, it happens instantly. The commit gets recorded. And then, in a background process my railsci
script runs all the tests.
This is the post-commit
hook. I tried to keep it minimal so as to make the setup easy and maintainable across different projects.
1 |
|
The railsci
script too is pretty straightforward,
- It tags your commit as
processing-#{buildid}
, where buildid is a random hex id. - Creates a folder called
/tmp/#{buildid}
, and clones your git repo there. - Creates a new unique test database with a name
app_name_test_#{buildid}
. - Runs all your tests and tags your commit as
failed-#{buildid}
if the tests fail. - Removes the
processing..
tag
1 |
|
All of this runs behind the scenes without you even noticing it, if everything is good. You would find a failed-#{buildid}
tag only if the tests fail. It’s working great for me. Hope it helps you guys :)
Update: Fixed redirection in git hook and added a way to notify when the tests are executed