Search code examples
rtravis-cibookdown

Build book on Travis and push back to GitHub pages


I am writing a book using bookdown which is hosted on GitHub and one frustration is I keep forgetting to build the book before I push my changes back to GitHub. So one solution I came up with was to use Travis to build and deploy my book to the gh-pages branch. I am using htmlproofer to check the links in my book so I need my Travis build to use the ruby language and not R. I cannot see how to access the Rscript command, however, since it is not installed on the environment. My current .travis.yml is

language: ruby
rvm:
  - 2.3.3
before_script:
  - chmod +x ./scripts/cibuild.sh
script:
  - ./scripts/cibuild.sh
deploy:
  provider: pages
  skip_cleanup: true
  github_token: $GITHUB_TOKEN # Set in travis-ci.org dashboard
  local_dir: docs
  on:
    branch: master
env:
  global:
    - NOKOGIRI_USE_SYSTEM_LIBRARIES=true
notifications:
  email: false
sudo: false

Where cibuild is just a bash script containing

#!/bin/sh

Rscript -e "bookdown::render_book('index.Rmd', 'bookdown::gitbook')"
htmlproofer ./docs

I tried using a sudo apt-get install r-base but this gave me R version 2.14.1 which is far too old...

Any ideas?


Solution

  • In order to solve this, I switched to a language: R build since this also comes with Ruby. The answer is detailed here