Local Continuous Integration with Integrity
Integrity is ace. I’m a huge fan of working under the ever watchful eye of a Continuous Integration server. I’m also becoming more and more of a fan of Git, and GitHub, for my personal projects. At work we run CruiseControl and it does it’s job well, but locally I only use it for larger projects. It comes with a little overhead and if I’m just hacking on the train I rarely check on it’s status.
Integrity is an unashamedly lightweight and straightforward continuous integration server written in Ruby. It comes with Git integration as well as a nifty notifications framework. There are already notification plugins available for jabber, IRC and email. If I get time and inclination I’d love to hack together a webhooks plugin too. It’s a simple app to get up and running with and you can always browse the code if something isn’t clear. All in all it’s perfect for my type of smaller project.
So, with a local CI server up and running you’re left with one problem; having to click the _Manual Build” button whenever you want a build. Now Integrity comes with a mechanism to allow pushes to GitHub to trigger a build. But this only works when you have an internet connection and are using GitHub and are pushing frequently. Personally I often make lots of local commits and then push at a later date. Also not all of my projects are on GitHub for various reasons.
Well it turns out that all the build button does is sent an empty HTTPpost request to a URL of the following format:
http://{integrity-url}:8910/{project-name}/builds
That means with a little bit of Git magic we can have our integration server run a new build whenever we commit our code. All we need to do is write a very simple post-commit git hook script. I’ve written the script in Python but you could write it in anything. This script is from a real project so adjust the server address and path as needed.
#! /usr/bin/env python
import httplib
conn = httplib.HTTPConnection("localhost:8910")
conn.request("POST", "/appengine-books/builds")
All you need to do is drop this script in your .git/hooks folder as post-commit. Make sure you set the executable bit with chmod +x as well, otherwise you’ll be wondering why it’s not working and probably blaming me.
Comments
It is also possible to use curl or wget to do the POST-request.
Antti Rasinen - 29th December 2008
Well, this is not as simple as your solution, but is more complete if you want later to do more complex stuff:
http://github.com/metajack/notify-webhook/tree/master
A implementation of GitHub hooks in Python ;)
Alcides Fonseca - 29th December 2008
@Antti I used Curl to check whether this worked or not before creating the hook script. I guess the script itself could just be a bash script using Curl come to think of it.
@Alcides nice project. I’ll be having a play with that as the need arises.
Gareth Rushgrove - 29th December 2008
Great writeup!
Regarding the post-receive hook, that’s a neat hack =) We actually have a script that mimics github’s behavior (passing the refs committed in the push, etc), but for some reason I’ve been lazy about putting it on the repo. (Mostly because I haven’t used integrity outside of githubland yet)
Grab it from here: https://gist.github.com/e431699c726fd17fb06a
Lemme know how it works :)
Nicolás Sanguinetti - 30th December 2008
Very Useful.
I want to try this soon. It seems similar to ZenTest with testing all the time.
@Nicolás
Nice script.
I like RestClient for get, post, etc. calls.
http://rest-client.heroku.com/rdoc/
Michael Barton - 31st December 2008
Finally, a CI server for rails that doesn’t suck! We won’t be running this locally, but we will be running it on a remote CI server that sends out emails when tests fail.
Brad Gessler - 9th January 2009
Leave a comments