Automate Arduino ESP8266 Testing with TravisCI
This is one thing I’ve been meaning to do for a long time for my little ESP8266 library and finally got around to doing it.
Continuous Integration automated builds using Travis CI. For Arduino. For ESP8266
It works, it’s nice, it’s an extra assurance that things will not go tits up, it works for Arduino builds, it works for ESP8266 builds based on Arduino IDE. It’s not even all that hard to setup once you ve done it once, and for Open Source Software it’s completely free.
It works for a lot of other languages as well, and there is a ton of information on the internet. I will concentrate on test building a library for ESP8266, as information was rather scarce in this direction.
In my case, I am testing every commit to WiFiManager, my library for wifi connection management for ESP8266.
Travis CI takes each commit from Github, installs Arduino IDE, installs ESP8266 board support, fetches any dependencies and finally builds all the examples of the library against this whole setup. If it fails, I get an email. It really is great.
If I have bored you to tears already, here is my ESP8266 TravisCI configuration.
Jump in and knock yourself out.
For the one or two other of you reading this that wants to know more, keep on reading.
Now, if you are not familiar at all with this, it s worth mentioning that the prerequisites for this are a github account, a github repo of what you want to test and of course a TravisCI account. The setup after that is amazingly simple, they really did a great job of integrating everything.
To start testing, you need to add a .travis.yml file to the root of one of your repositories (mine), and turn off building for that particular repo in Travis.
I won’t go into details about Travis CI as that s been blogged about again and again, but rather the particularities of building ESP8266 for Arduino IDE code. The code itself is quite self explanatory, and I’ve mixed and matched bits from quite a few sources. I will keep refining it, but as it is, it works.
First, there are multiple ways of getting Arduino, you could get a certain release or nightly builds. For stability I chose to use one of the releases.
At the time of writing this, I had to use Arduino IDE 1.6.5, because it looks like 1.6.7 and the new 1.6.8 have some issue with passing a boards url to them and won’t compile.
Next is how you install the ESP8266 board support. I wanted to install through the official boards manager url, the stable release, hence me having to use Arduino IDE 1.6.5. You could fetch it from github (like here), then you could use a newer Arduino IDE.
Another thing that this time seems missing, this time in Arduino IDE 1.6.5, is ability to install dependencies like so
arduino --install-library "ArduinoJson". This one works fine in 1.6.7 and 1.6.8 but it forced me to fetching my dependencies straight from github, rather than using the library manager.
One other thing to mention is that
build_examples is a function in the bash script located under travis/common.sh. It loops and builds each of the examples. This happens on each commit and pull request.
I am sure there are better and cleaner ways of doing it all, but so far so good. Having a starting place, knowing the above caveats (silly random errors from arduino), you can set it up in 5 minutes and enjoy automated testing builds forever 😀
Future plans would be testing against multiple versions of arduino and multiple versions of the ESP8266 core, to insure compatibility.
If you ve done everything, you should be seeing a nice little build passing badge on your github’s project folder and a very nice, all green status on your Travis CI dashboard.