Never miss a build failure again

Posted

Our integration setup

At Teamwork.com, we’ve chosen to use Codeship as our continuous integration platform. Codeship hooks up to Github and allows you to write custom scripts that execute if tests succeed. That means every time you commit code changes, it runs the integration tests, reports the results of our tests, and, if they were successful, publishes your code to production. You still need to write useful and informative tests to get the best results, but having the continuous integration helps stop any broken code from unknowingly slipping into the repository and production.

There are a few different ways that we can view the results of the Codeship tests: There’s a Google Chrome plugin, the Codeship website, and a badge that we’ve included in the repository’s README on Github. However, sometimes you commit the code, close your browser, open Sublime text, and start working on the next great feature before waiting to see the results of the tests so it might take hours (or the appearance an angry co-worker!) before you find out your last commit broke the source code.

Last summer, Adam and I attended NodeConf.eu and, much to our surprise, there was a full day of talks focused on using Node.js with hardware. I decided to try some of the stuff we’d learnt and set out to build a physical device that would let me know the state of our repositories without having to be in the browser.

Using Arduino and Node.js

Why use Node.js with Arduino? Well, Teamwork Chat uses Node.js primarily in our server development so in the interest of not having to learn C and to get the application up and running as quickly as possible this seemed like a good choice.

(If you have some time, you should check out what other languages we use. There is some pretty interesting stuff going on there. )

Johnny-five seemed like a good choice to communicate with the Arduino, it allows your Node service to send information to the Arduino, turn on an LED for example, and to retrieve information, such as when a button is pressed.

This example taken from the johnny-five examples page really shows just how easy it is to interact with the Arduino

 

The Codeship API

The Codeship API is short and sweet. It allows you to query the health of your projects and trigger a run of the integration tests.

The Codeship documentation has the details, but here’s a quick overview:

There are two values you need to use the API and both are readily available on your Codeship account:

  1. An API key
  2. The project ID

Making a simple GET request to the following url will give you all the information about the integration tests running on your project.

A handy little tip that isn’t mentioned in the documentation is that you can also filter by branch. This means you can report on all the branches or choose specific ones, like master and develop!

Putting it all together

So, now that we know how to use the Codeship API and how to use Node to communicate with the Arduino, all that’s left is to work out how to put them together.

The hardware

This was probably the hardest part. Wow, working out how to construct a circuit that makes sense is confusing! In the end, the circuit turned out to be pretty simple, but there was a lot of changing random wires around to try and figure out why it wasn’t working. The circuit I used consisted of:

  • 3 LEDs connected to 3 different ports on the Arudino. In the image they’re connected to 11, 12 and 13.
  • 1 switch connected to port 2.

This layout just works for one project or branch. By duplicating the setup, you can report the status of multiple projects/branches.

The code

To get going, we start by requiring johnny-five and setting our board as seen in the example above. Then we put the following code in board.on ready:

Conclusion

This was my first time manipulating hardware. It was definitely an interesting and eye-opening experience. Initially, it was pretty daunting thinking about working with hardware, but it turned out to be nowhere near as difficult as I had thought it would be. Johnny-five handled all the interactions with the board and the rest was just writing code as normal.

If anyone has any ideas on projects related to Codeship or Arduino, it would be awesome to hear about them in the comments.