Friday, July 11, 2014

Continuous integration using Travis CI

It has been tough keeping the frameworks functionality working after the basic prototype. The prototype is great - it has most basic features. But adding new feature or fixing bugs was breaking functionality here and there. So, instead of coding new functionality I have added about 21 tests. Most of them are functional tests at this moment. And while writing them design and functionality bugs were revealed and fixed. I strongly feel we need more tests before adding any more functionality, but for now the tests are covering most of the code path and can fix remaining bugs and start writing unit tests.

I have added the project to Travis CI which is great free tool to build and integration test. The following image shows current status of build/ test run:

Build Status

It runs every time a new push is made to the Github repository. This image is actually dynamic and shows current status of Cosmos Framework. If you can not see it look here.

Setting up TravisCI is easy. First login to https://travis-ci.org/ using your Github account and Travis CI will show the list of public repositories. Now enable any repository Travis should track. Then we need to add a file named .travis.yml at the root of the repository. This file contains basic settings like language and script to run. For cosmos we need MongoDB which can also be added usnder required services. Here is the first version of the configuration file being currently used to run build and tests:


language: python
python:
  - "2.7"
# command to install dependencies
install:
  - pip install tornado
  - pip install motor
  - pip install mongolog
  - pip install mock
  - pip install requests

services:
  - mongodb

before_script:
#This mongodb command should not have a newline in real file
- mongo 127.0.0.1/cosmos --eval 'db.cosmos.users.insert(
     {
         "username":"admin",
         "roles": ["43425097-e630-41ea-88eb-17b339339706"],
         "email":"admin@cosmosframework.com",
         "password":"hmac:1ddb4e6b0b810f59018babbb5dc0eed4"
     });'

# command to run tests
script: python setup.py test

We are installing the required python packages and adding mongodb as required service. Before running script we want to add our admin user to mongodb which is done in before_script section.

When we add this file, commit and push the change to Github, Travis gets notification using webhook about the change and start deploying a system and run tests. It shows the status using an image (as shown above) that changes based on the build/test result.

This is a very nice free service which you may use for your opensource project and for each change it will run your tests and report if anything is broken.

No comments:

Post a Comment