KevCaz's Website

This is another note about deploying a pkgdown1 website with Travis on gh-pages. I had previously used the package travis but I was recently interested in doing so manually. Fortunately, I found this very helpful walk-through by Gábor Csárdi2. I used it and it worked well for a while, but at some point I had an issue with the deployment part (still not sure why), so I changed it. Instead of using the following config3

1
2
3
4
5
6
deploy:
  provider: script
  script: Rscript -e 'pkgdown::deploy_site_github()'
  skip_cleanup: true
  on:
    all_branches: true

I now use

1
2
3
4
5
6
7
8
deploy:
  provider: pages
  skip_cleanup: true
  keep_history: true
  github_token: $GITHUB_TOKEN
  on:
    all_branches: master
  local_dir: docs

where the environment variable $GITHUB_TOKEN is a token created on GitHub that I have added in the Travis settings of my package. This works well, BUT it does not allow to keep the two versions of the pkgdown website (development + release). This is because a new ./docs folder is produced during every build and when its content is pushed to the gh-pages branch, only one version of the website is pushed. To overcome this, I have used (and this thread was quite helpful).

1
2
3
4
after_success:
  - mkdir docs
  - git fetch origin gh-pages:gh-pages
  - git --work-tree=docs checkout gh-pages -- .

Briefly:

  1. mkdir docs creates the directory docs;
  2. git fetch origin gh-pages:gh-pages gets the remote gh-pages branch;
  3. git --work-tree=docs checkout gh-pages -- . put the content of gh-pages in ./docs.

If you want to see this config in action, it is currently used for inSilecoMisc and so both the release website and the development website are available!

Template

To conclude this note, below is the entire .travis.yaml template I intend to use for my future packages.


  1. a static website builder for R packages. ↩︎

  2. an important I don’t mention here is actually to create the gh-pages branch↩︎

  3. par ot the .travis.yaml of my package. ↩︎