Setting up a CI environment for iPhone/iPad Development
I'm a fan of Git. I use Git for iPhone development. I'm also a fan of Agile, but I've never gotten around to using Agile and CI (Continuous Integration) for my iPhone development. Last week I attended the Philly Emerging Tech in Enterprise conference and it (specifically the talk by Brian Marick @marick on Mock) motivated me to see if I could set up a CI environment for my iPhone/iPad development. I've never done any Mock stuff, so that was the learning curve. I was able to fairly quickly set up a CI environment on my miniMac server. Here are the steps and requirements:
Requirement:
1- A local drive or personal server/cloud (everyone has one nowadays, right? I use my miniMac as server.)
2- Set up a remote Git environment/repository.
3- Set up Hudson (a Java-based remote build environment.)
4- Here's the hard part. You need to download a script that converts OCUnit (Objective C unit tests) to JUnit which is what Hudson uses.
5- Start Hudson
6- Configure your iPhone/iPad XCode projects in Hudson.
1 - Ok, you can either use a local drive, or use a server you may have.
2 - a - To set up a remote git repository, you need to install git on the machine you plan to use. I cheated and used the pre-built installer from : http://code.google.com/p/git-osx-installer/ You can build from source if you're that type of person. You install this on your remote machine. (Install it on your local machine too if it isn't already installed).
2 - b - Once installed you need to create a repository:
2 - b - a - Start terminal, cd to a new directory and enter:
git --bare init
That's it. The directory you are in will now have a git repository that will hold your projects.
3 - Download Hudson from: http://code.google.com/p/git-osx-installer/ Hudson is a Java war file. You can run it locally (see the Hudson docs--easy) or you can set it up as a Java servlet (its a war file). I use Catslapper http://www.fivesquaresoftware.com/catslapper/ to manage Tomcat and web servlet environments on my Mac OSX machines.
4- You need to get this script. It took a while to find something that worked, but this does the job:--use git to clone: git://github.com/ciryon/OCUnit2JUnit.git This will pull a script down that interfaces the OSX OCUnit to JUnit. This is a Ruby script (latest versions of OS X have Ruby pre-installed). Move this file to /usr/local/bin/ and make sure its executable.
5 - Start Hudson. I do this with CatSlapper. Once Hudson is running you can go to the configured URL (default port 8080): http://localhost:8080/hudson
6 - Configure your projects. This was the other hard part (well not hard, once you know how.).
6 - a - get into Hudon.
6 - b - Tap new project. Name it whatever you want. Make it a Freestyle software project. Tap save.
6 - c -1 - Name the project.
6 - c - 2 - Make the Source Code Management git (obviously)
6 - c- 3 - Set the URL of Repostiory field to the directory of the empty Git repository you created in step 2-b-a.
6 - c - 4 - In the Build Triggers check Poll SCM and enter 5 * seperated by spaces * * * * * (this will poll every 10 seconds or so for changes.)
6 - c - 5 - Select Build Step - Execute Shell
6 - c- 6 - Enter:
xcodebuild -target <unit tests target name in XCode> -sdk /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/<version of iPhoneSDK here>/ -configuration "Debug" | /usr/local/bin/ocunit2junit.rb
6 - c - 7 - In Post-build Actions, select "Publish JUnit test result report".
6 - c- 8 - Enter **/test-reports/*.xml in the Test Reports XML
That's it. Now any time you push your project into git Hudson will kick off a rebuild of your test units and generate a report that you can view from the Hudson dashboard link. You can also configure Hudson to send you emails (for failed build, etc) if you have Postfix enabled on your Mac machine (CatSlapper does this for you.) If you don't use OCUnit in your XCode projects, nothing will show up in Hudson, so this setup is really targeted to unit-testing using the SenTest (built into the iPhone SDK now).
I'm not an expert in Hudson, but it seems to work and do what it's supposed to with an easy setup.