Continuous integration with travis and coveralls.io for Django apps

By : Rakesh Vidya Chandra

Maintaining a solid rapport with the ongoing software development process always turns out to be a walk on air. Ensuring a software build integrity and quality in every single commit makes it much more exciting.

If the current software bulid is constantly available for testing, demo or release isn't it a developer's paradise on earth?

Giving a cold shoulder to "Integration hell" the 'Continuous integration' process stands out to deliver all the above assets.

What's Continuous integration?

Continuous integration is a development practice that requires a developer to integrate code into a shared repository in which isolated changes are immediately tested and reported on when they are added to a larger code base.

Continuous integration (CI) originated from within the extreme programming paradigm, but the principles can be applied to any iterative programming model, such as agile programming. As critics noted several potential drawbacks on extreme programming many organizations have adopted CI without all of the extreme programming concepts.

Principles of CI:

  • Maintain a single source repository
  • Automate the build
  • Make the build self-testing
  • Keep the build fast
  • Everyone can see the results of the latest build
  • Automate deployment

Keywords:

  1. Build: All steps necessary to compile and create deliverables.
  2. Commit: The operation follows the validation of updates to existing code.
  3. Update: This operation allows the update from the repository of the configuration management tool.
  4. Checkout: This is the operation to extract a version of a project under development from the repository of the configuration manager.

Spices for the recipe:

  • Use of a version control tool (Git, SVN, etc.)
  • An automated build and product release process.
  • Instrumentation of the build process to trigger unit and acceptance tests for evey change that is commited
  • A notifying process that notifies for every single test fail and alerts the team.

The approach:

  1. The developer makes a commit to the repository
  2. The integration server detects the commit, makes a checkout, launches operations and testing.
  3. Eventually the repository may become so different from the developers baseline referred to as "Merge hell"
  4. In case of a failure in the testing process a notification is generated to the team.
  5. The developers may discard the changes or fix the bugs to make it progress successfully.

So this makes us fancy trying out continuous integration. Let's study a CI software now.

Travis CI

Travis CI is a distributed build system for the open source community. Its a CI service used to build and test projects hosted on Github.

Travis is configured by adding a file named .travis.yml which is a YAML(a human-readable data serialization format) text file. It automatically detects when a commit has been made and pushed to a GitHub repository that is using Travis CI, and each time this happens, it will try to build the project and run tests. It also builds and runs pull requests and once it is completed it notifies the developer in the way it is configured.

Steps to use Travis CI:

  1. Sign-in: To get started with Travis CI we should sign-in to our github account.
  2. Activate Github webhook: Once the Signup process gets completed we need to enable the service hook in the github profile page.
  3. Add .travis.yml: We should add the yml file to the project.

Writing .travis.yml file:

In order for Travis CI to build our project we need to tell the system a little bit about it. we will be needed to add a file named .travis.yml to the root of our repository. The basic options in the .travis.yml should contain are language key which tells which language environment to select for our project and other options include the version of the language and scripts to run the tests, etc.

Example for travis.yml for python project:

language: python
python:
  - "2.7"

# command to install dependencies
install:
  - "pip install -r requirements.txt"

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

Explanation:

In the first line we have specified python as the language environment, the next specifies the version of python. Travis will then make sure that the project runs well with all the python versions. If we have any python dependencies Travis will test our code in a virtualenv, so all we need to write a requirments.txt and tell Travis to install it and the script command will run tests when excited.

The complete Lifecycle

  1. before_install
  2. install
  3. after_install
  4. before_script
  5. script
  6. after_script
  7. after_success or after_failure

Configuring .travis.yml

Build only specific branches:

Per default travis will build once we push to a branch on Github. That behavior can be annoying if we are committing often to development branches. We can restrict which branches Travis is monitoring for changes in the .travis.yml. Either we can blacklist the branches or whitelist them:

.travis.yml

# Whitelisting example
branches:
  only:
    - master

# Blacklisting example
branches:
  except:
    - develop
    - feature

Getting notified with lint errors:

We can also get notified or make bulid fail if there are any lint errors in the commit. For this we can use the option before-script. We can create a lint.sh file and we can specify it in the before-script option so that the bulid fails and notifies when lint error occurs.

.travis.yml

before_script:
    -./lint.sh

Using coveralls with travis CI:

Coveralls is web service to help us track our code coverage over time and ensure that all our new code is fully covered.

Steps to use coveralls:

  1. First, log in via Github and add your repo on Coveralls website.

  2. Add pip install coveralls to install section of .travis.yml

  3. Make sure you run your tests with coverage during the build in script part.

    script: coverage run --source=yourpackagename setup.py test

  4. Execute run coveralls in after_success section.

    after_success: coveralls

Example:

travis.yml

language: python
python:
  - 2.7
install:
  - pip install -r requirements.txt
  - pip install coveralls
script:
  coverage run --source=moscowdjango,meetup manage.py test
after_success:
  coveralls

The above code makes custom report for data generated by coverage.py package and sends it to json API of coveralls.io service. All python files in our coverage analysis are posted to this service along with coverage stats


Related Posts


Can we help you build amazing apps? Contact us today.

Comments

Owais Lone

What does moscowdjango,meetup stand for in the command?

commmenttor
rakesh 12th May, 2014

Hi Owais Lone,

moscowdjango,meetup are the names of the apps. We can define what specific apps to run with coverage.
The syntax is :

coverage run --source=app1,app2 ./manage.py test app1 app2

We can also run coverage for all the apps the below way.

coverage run manage.py test

Thanks

commmenttor
Pablo Martín

I'm using this structure to reusable apps:

https://github.com/openwebinars-django/testango

tox + travis + coveralls

commmenttor
Ray Ban Sunglasses: Finding the right Seem

Continuous integration with travis and coveralls.io for Django apps - Agiliq Blog | Django web app development

commmenttor
Moncler C meilleure option de l'hiver

Continuous integration with travis and coveralls.io for Django apps - Agiliq Blog | Django web app development

commmenttor
Yashwanth 4th Aug., 2014

Hi Rakesh.

This should be all I needed. Very helpful for me to know about the Continuos Integration with travis in easier.

Thanks.

commmenttor
http://desertlanes.com/sitemap.php?Q=kate-spade-pink-shoes/

or only uniting who have antique near friends. in a position to set images of your son or daughter or maybe of your whole clan in the diaper bag. you see different styles, right after that decrease just about breasts to get into large whitening strips.7 toes. generally consisted of two massive andf the other large baggage. because bringing the massive baby baby wipes box, You probably will not need half of the things on the inside of.
http://desertlanes.com/sitemap.php?Q=kate-spade-pink-shoes/ http://desertlanes.com/sitemap.php?Q=kate-spade-pink-shoes/

commmenttor
http://grupoenpmilenio.com/sitemap.php?Q=kate-spade-w-polsce-blogspot/

and simply not being able to control the amount heat used for every one complience seal isn't worthwhile at the end. if you have the money available to get your your childhood higher education a laptop, which the puppy's pack is one very sound course supplies you will order. and, our occasional actress realised owner president Jean Louis Dumas on a trip in flight upon london.
http://grupoenpmilenio.com/sitemap.php?Q=kate-spade-w-polsce-blogspot/ http://grupoenpmilenio.com/sitemap.php?Q=kate-spade-w-polsce-blogspot/

commmenttor
http://giaasa.com/sitemap.php?Q=j-kate-spade-keri-dresses/

show them how on an idea visa card.4, moreover purses. the particular one of the best things about heading for natural things you eat sellers are honies branches why these small amount straws may possibly be crammed with tempting distinctive flavored. Two zilch compartments in the top andf the other in your back enable you to stow small sized such things as cellular phones or pocket cam. the style and design comes with two soft white whipping going similar on to the handles' age artificial leather cut. wrist band helps, seem neo forecast back pack to build alot more financial items in as womanly program and consequently medicine medications,
http://giaasa.com/sitemap.php?Q=j-kate-spade-keri-dresses/ http://giaasa.com/sitemap.php?Q=j-kate-spade-keri-dresses/

commmenttor
http://cascabelnetworks.com/sitemap.php?Q=kate-spade-polka-dot-umbrella-2/

dry it out acquiring bath towel. it will not be real. you'll certainly be surprised the simplest way right away you will discover if your rucksack is real in addition to fake. Initial files were said as well as,while denounced noisy. stages coming from coverup. has the doctor. Make bigger release also poke them how to the wall membrane accompanied by double sided tape,
http://cascabelnetworks.com/sitemap.php?Q=kate-spade-polka-dot-umbrella-2/ http://cascabelnetworks.com/sitemap.php?Q=kate-spade-polka-dot-umbrella-2/

commmenttor
エービーシーマート

In corporate news, shares of BHP Billiton, the world's largest mining company, rose 5.9 percent after the Canadian government rejected BHP's US$38.6 billion bid to buy Potash Corp. of Saskatchewan. After the market closes, Kraft Foods Inc., Starbucks Corp. and CBS Corp. will announce earnings.

commmenttor
© Agiliq, 2009-2012