Using Travis CI to test firmware? [SOLVED: use expect]

Hello everyone.

I am trying to use Travis CI to test my firmware, so that I can have the neat little “build passing” badge on my repository.

I know that the Travis CI virtual machine will not be able to run the Particle tool chain, (or will it?), so I am trying to get Travis CI to compile using the Particle API. I can get Travis to download particle-cli, but it can not run the compile command, because particle-cli needs me to log into the Particle cloud.

Here is my current .travis.yml

install:
  - npm install -g particle-cli

script:
  - particle compile photon firmware/

I checked the Docs, and I was not able to find a command for the REST API to compile and download binary from the cloud, not compile and flash to a device.

Is there a way to compile and download with the REST API, or is there a way to compile in particle-cli without logging in?

I do not want to have to put my account credentials into .travis.yml (that would be dumb), but I want to be able to compile within Travis CI.

I am fine with creating an access token for Travis to use, and I hope there is a solution for my problem.

1 Like

If anyone is interested, here is the Travis Log:

@mdma @jgoggins or @Dave, do you guys have any suggestions?

Hey @nrobinson2000 , I’m definitely interested in this.

We had this working on the firmware .travis.yml setup repo for a while.

The key piece you need to get this to work is to render ~/.particle/particle.config.json using travis encrypted env vars (or set them in settings in the pointy clicky travis-ci interface associated with the project). Here is an example of how the firmware repo used to do it (when it was still the spark-cli). This script can get called early in the travis bootstrap process via something like this. This approach makes subsequent authenticated particle calls will now not prompt for interactive login and your test can do it’s thing.

I just read an article on how to use the expect command, but this would still require me to put my credentials in a plaintext file. http://www.thegeekstuff.com/2010/10/expect-examples/

Thanks for the help, I will do this.

Hey @jgoggins, I put my variables in the Travis settings, but then Travis does not want to read them from my expect script. I am certain that I wrote it correctly.

$ ./travis-helper.sh

spawn /home/travis/.nvm/v0.10.36/bin/particle cloud login

? Please enter your email address: 

can't read "email": no such variable    
while executing"send "$(echo $email)""  
  
(file "./travis-helper.sh" line 7)

The command "./travis-helper.sh" exited with 1.

Any ideas?
Here is the log. https://travis-ci.org/nrobinson2000/sparkbot-default

UPDATE:
I’ll try making it run travis-helper.sh as sudo. (This just made more problems :frowning:)

Nevermind, I got my expect script to work, and now Travis logs into particle-cli and compiles. :smile:

#!/usr/bin/expect

set timeout 10

set user [lindex $argv 0]

set password [lindex $argv 1]

spawn /home/travis/.nvm/v0.10.36/bin/particle cloud login
expect "? Please enter your email address: "
send "$user\r"

expect "? Please enter your password: "
send "$password\r"

interact

yay :smile:

2 Likes

This is awesome @nrobinson2000 , I love the approach. expect is such a handy linux tool, and this is better than my approach which assumes something about this internal behavior of the CLI (the .json file), whereas expect does not. Nice! Thanks for sharing!

3 Likes

You are renewing(*) my faith in the youth of today, buddy :slight_smile:

(*) It was never really shaken, just liked the way the phrase sounded.

3 Likes