Setting up Travis CI to test R and Python scripts in MacOS and Ubuntu
Publish date: 28 May 2020
Last updated: 10 Jul 2020
Last updated: 10 Jul 2020
A colleague and I configured Travis CI to run the tests of a project that relies on R and Python scripts. This project supports both macOS and Linux, so it was essential to test it in both environments. After some trial and error, we got this working with the travis.yaml
file below. Our deployment manages the following project requirements: MySQL, Python 3.7, miniconda with a virtual environment, R and a cached virtual environment with renv, and slack notifications.
For Linux (Ubuntu 16.04) we do:
- Install brew, linuxbrew-wrapper and linuxbrew/xorg
- Install R using brew
- Install miniconda using their provided script installer
- Restore our conda virtual env
- Cache renv‘s library. We use renv to keep a reproducible R environment with 161 packages; however, renv had to build them from source in Ubuntu 16.04 and our travis build was timing out. The solution we implemented was building the renv library (and therefore the travis’ cache) in three steps, first committing a small renv.lock with 40 packages, then 100, then all 161.
For MacOS (10.14.4)
- Set up the OS image with
osx_image: xcode11.3
andlanguage: generic
- Install MySQL, R and miniconda using brew (brew and Python 3.7 are already installed)
- Restore our conda virtual env
- Cache renv’s library. We faced and solved the same problem we had in Linux with renv’s building times timing out our travis build (see above). In addition, in MacOS, renv’s library path contains a space
~/Library/Application Support/renv
which was causing issues with travis’ cache mechanism, as a quick fix we disabled renv’s global cacheR -e 'renv::settings$use.cache(FALSE)'
for both Linux and MacOS (for consistency) and cached our project’s renv library folder$TRAVIS_BUILD_DIR/renv/library
as it now contains the actual packages instead of symbolic links.
UPDATE Recently r
tap dependency on gcc changed from 9 to 10 and that broke our renv
library cache. To force travis to use gcc 9 and r 4.0.0 use this updated file:
No comments