# Continuous Integration, Arduino, and You

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/026/174/medium800/maker_business_Screen_Shot_2015-06-29_at_2.59.10_PM.png?1435604377)

Bugs can be introduced into software very easily, and it takes quite a bit of effort to ensure that the 100+ Adafruit Arduino Libraries compile cleanly. Luckily, there is an easy way to verify that your Arduino&nbsp;Libraries compile after every push to GitHub by using [Travis CI](https://travis-ci.org/).

What is Travis CI? Travis CI is an open source [continuous integration](https://en.wikipedia.org/wiki/Continuous_integration)&nbsp;service that automatically tests and builds your GitHub projects. The service&nbsp;is free for open source projects, and the setup is relatively painless.

Travis CI supports a number of languages and platforms, but there currently isn't native support for building Arduino projects. Luckily it's easy to customize builds using a configuration file, so building Arduino projects only requires a few simple&nbsp;modifications to the config. Let's get started.

# Continuous Integration, Arduino, and You

## Travis CI Configuration

The first step you will need to complete is to sign into&nbsp;[Travis CI](https://travis-ci.org/)&nbsp;using your GitHub account. This process&nbsp;requires you to authorize access to your GitHub account so Travis can get&nbsp;a list of your repositories. The Travis CI documentation has a great [getting started page](http://docs.travis-ci.com/user/getting-started/)&nbsp;that will help you with this process if you require more assistance.

# Enable Travis CI for a Repository

You will need to visit your [Travis CI profile](https://travis-ci.org/profile),&nbsp;and enable the service for the repository you wish&nbsp;to build. We will be using the [Adafruit FONA Library](https://github.com/adafruit/Adafruit_FONA_Library)&nbsp;in this example, but this process should work for verifying Arduino sketches in any GitHub repository.

![](https://cdn-learn.adafruit.com/assets/assets/000/026/175/medium800/maker_business_Screen_Shot_2015-06-29_at_3.05.16_PM.png?1435606213)

# Add the Travis CI Configuration File

Now that we have enabled the service, we will need to add a **.travis.yml** to the root of the repository. Make sure you don't miss the first period at the beginning of the **.travis.yml** filename.

Let's take a quick look at the full config file for the FONA library.

```auto
language: c
before_install:
  - "/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_1.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :1 -ac -screen 0 1280x1024x16"
  - sleep 3
  - export DISPLAY=:1.0
  - wget http://downloads.arduino.cc/arduino-1.6.5-linux64.tar.xz
  - tar xf arduino-1.6.5-linux64.tar.xz
  - sudo mv arduino-1.6.5 /usr/local/share/arduino
  - sudo ln -s /usr/local/share/arduino/arduino /usr/local/bin/arduino
install:
  - ln -s $PWD /usr/local/share/arduino/libraries/Adafruit_FONA
  - arduino --install-library "Adafruit SleepyDog Library,Adafruit MQTT Library"
script:
  - arduino --verify --board arduino:avr:uno $PWD/examples/FONAtest/FONAtest.ino
  - arduino --verify --board arduino:avr:uno $PWD/examples/IncomingCall/IncomingCall.ino
  - arduino --verify --board arduino:avr:uno $PWD/examples/AdafruitIO_GPS/AdafruitIO_GPS.ino
notifications:
  email:
    on_success: change
    on_failure: change
```

The **language** section tells Travis that the project is primarily written in **C**. Since we are building using the Arduino IDE, this setting is not critical. The **before\_install** section configures the build environment to run with a virtual display using **xvfb,** and also installs the Arduino IDE.&nbsp;The Arduino IDE CLI currently [requires a graphical user interface to be present](https://github.com/arduino/Arduino/blob/master/build/shared/manpage.adoc#bugs), so this configuration step is necessary for the Arduino IDE to run in the Travis environment. If you would like to read more about **xvfb** configuration for Travis CI, there is&nbsp;a [handy page in the Travis CI documentation](http://docs.travis-ci.com/user/gui-and-headless-browsers/#Using-xvfb-to-Run-Tests-That-Require-GUI-(e.g.-a-Web-browser))&nbsp;with configuration examples.

The **language** and **before\_install** sections should not need to be modified for your Arduino project, so you should be able to copy and paste the text&nbsp;into your **.travis.yml** &nbsp;config file.

```auto
language: c
before_install:
  - "/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_1.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :1 -ac -screen 0 1280x1024x16"
  - sleep 3
  - export DISPLAY=:1.0
  - wget http://downloads.arduino.cc/arduino-1.6.5-linux64.tar.xz
  - tar xf arduino-1.6.5-linux64.tar.xz
  - sudo mv arduino-1.6.5 /usr/local/share/arduino
  - sudo ln -s /usr/local/share/arduino/arduino /usr/local/bin/arduino
```

The **install** section symlinks&nbsp;the FONA library to the Arduino library path so the IDE has access to it when building examples. It also uses the Arduino CLI to install other library dependencies needed when running the included example sketches. If you would like to read more about the Arduino CLI **--install-library** command, you can refer to the [CLI documentation on GitHub](https://github.com/arduino/Arduino/blob/master/build/shared/manpage.adoc#description).

You will need to modify these commands to point to your library, and to install any other library dependecies needed to compile&nbsp;your example sketches. If you do not need to install any dependencies, you can omit&nbsp;that line from your config.

```auto
install:
  - ln -s $PWD /usr/local/share/arduino/libraries/Adafruit_FONA
  - arduino --install-library "Adafruit SleepyDog Library,Adafruit MQTT Library"
```

The **script** section is where the library is built and checked by Travis. We use the Arduino sketches in the **examples&nbsp;** directory to confirm that the FONA library compiles successfully on an Arduino Uno. This is a very simple sanity check to confirm that no regressions have been added by a commit or pull request. _This doesn't check if the&nbsp;code functions as expected, it merely&nbsp;confirms that the code builds successfully._

You will need to modify the **script** &nbsp;section to point to your example sketches. Verifying the examples in a library is the easiest way to check to make sure a library builds properly, but you can use this section to test any Arduino sketch.

```auto
script:
  - arduino --verify --board arduino:avr:uno $PWD/examples/FONAtest/FONAtest.ino
  - arduino --verify --board arduino:avr:uno $PWD/examples/IncomingCall/IncomingCall.ino
  - arduino --verify --board arduino:avr:uno $PWD/examples/AdafruitIO_GPS/AdafruitIO_GPS.ino
```

The **notifications** section of the configuration file tells Travis to only email the author and commiter if the build status changes.&nbsp;The [Travis CI documentation](http://docs.travis-ci.com/user/notifications/#Email-notifications)&nbsp;has more details about the notification options available.

```auto
notifications:
  email:
    on_success: change
    on_failure: change
```

Once you are finished making changes, commit the file to your repo, and push it to GitHub. If everything is working, you will then see your build start on [travis-ci.org](https://travis-ci.org/).

![](https://cdn-learn.adafruit.com/assets/assets/000/026/176/medium800/maker_business_Screen_Shot_2015-06-29_at_4.09.10_PM.png?1435608600)

# Build Status Icon

A quick way to see the current build state of your library is to add the Travis CI build icon for your project to the README. You can do this by clicking on the build status icon next to your project's name on&nbsp;[travis-ci.org](https://travis-ci.org/).

![](https://cdn-learn.adafruit.com/assets/assets/000/026/180/medium800/maker_business_Screen_Shot_2015-06-29_at_4.20.17_PM.png?1435609238)

You will be presented with a modal window that has a few format options for the icon. Select markdown from the dropdown, copy & paste the markdown text into your project's README, and push it up to GitHub.

![](https://cdn-learn.adafruit.com/assets/assets/000/026/178/medium800/maker_business_Screen_Shot_2015-06-29_at_4.13.02_PM.png?1435608932)

You will then be able to easily check the build status of your project without logging into Travis CI.

![](https://cdn-learn.adafruit.com/assets/assets/000/026/179/medium800/maker_business_Screen_Shot_2015-06-29_at_4.16.53_PM.png?1435609035)


## Related Guides

- [Adafruit ATtiny Breakouts with seesaw](https://learn.adafruit.com/adafruit-attiny817-seesaw.md)
- [Adafruit QT Py CH32V203](https://learn.adafruit.com/adafruit-qt-py-ch32v203.md)
- [USB MIDI Host Messenger](https://learn.adafruit.com/usb-midi-host-messenger.md)
- [Adafruit Feather RP2040 with USB Type A Host](https://learn.adafruit.com/adafruit-feather-rp2040-with-usb-type-a-host.md)
- [Guitar Hero MIDI Controller](https://learn.adafruit.com/guitar-hero-midi-controller.md)
- [Adafruit IoT Button with NeoPixel BFF](https://learn.adafruit.com/adafruit-iot-button-with-neopixel-bff.md)
- [Adafruit PCA9548 8-Channel STEMMA QT / Qwiic I2C Multiplexer](https://learn.adafruit.com/adafruit-pca9548-8-channel-stemma-qt-qwiic-i2c-multiplexer.md)
- [Adafruit AS7331 UV / UVA / UVB / UVC Sensor](https://learn.adafruit.com/adafruit-as7331-uv-uva-uvb-uvc-sensor.md)
- [Adafruit QT Py ESP32 Pico](https://learn.adafruit.com/adafruit-qt-py-esp32-pico.md)
- [Adafruit LM73100 Ideal Diode Breakout](https://learn.adafruit.com/adafruit-lm73100-ideal-diode-breakout.md)
- [Neo Trinkey Auto Screen Locker](https://learn.adafruit.com/neo-trinkey-auto-screen-locker.md)
- [How to Choose a Microcontroller](https://learn.adafruit.com/how-to-choose-a-microcontroller.md)
- [Adafruit ADS122C04 24-Bit ADC](https://learn.adafruit.com/adafruit-ads122c04-24-bit-adc.md)
- [Adafruit TCS3430 / TCS34303 Ambient Tri-Stimulus Color Sensor](https://learn.adafruit.com/adafruit-tcs3430-tcs34303-ambient-tri-stimulus-color-sensor.md)
- [Adafruit Feather RP2350 with HSTX](https://learn.adafruit.com/adafruit-feather-rp2350.md)
