KevCaz's Website

As explained on GitHub:

GitHub Actions makes it easy to automate all your software workflows, now with world-class CI/CD. Build, test, and deploy your code right from GitHub. Make code reviews, branch management, and issue triaging work the way you want.

I’ve heard about this feature and I decided to give it a first go yesterday as I wanted to deploy a notebook for the McCann Lab’s Theory Club built with bookdown. As it uses the form of an R package, I figured the easiest approach was to google “github actions R” and this is how I learned about the R package ghactions. This package generates the file you need to set up your GitHub Actions workflow, i.e. a YAML file in .github/workflows. Given that the notebook I was deploying was a static website I opted for website() as a workflow:

1
2
R> library(ghactions)
R> use_ghactions(workflow = website())

With this first file in hand, I then examined the the documentation as well as three GitHub repositories where I found valuable examples:

and tweaked the file based on these! Below is the final version of my workflow (see the file on GitHub):

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
name: Render and deploy GitBook
'on':
  - push
  - pull_request
jobs:
  build:
    runs-on: ubuntu-18.04
    container: rocker/verse:latest
    steps:
      - name: Checkout Repository
        uses: actions/checkout@master
      - name: Install Dependencies
        run: |-
          Rscript -e "install.packages(c('remotes', 'bookdown'), repos = 'https://muug.ca/mirror/cran/')"
          Rscript -e "remotes::install_deps(dependencies = TRUE, repos = 'https://muug.ca/mirror/cran/')"          
      - name: Build GitBook
        run: |-
          Rscript -e "bookdown::render_book('index.Rmd', 'bookdown::gitbook')"          
      - name: Deploy GitBook to GitHub Pages
        uses: peaceiris/actions-gh-pages@v2.5.0
        env:
          ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }}
          PUBLISH_BRANCH: gh-pages
          PUBLISH_DIR: ./_book

which worked well:

After ~3min, the job was completed and the website deployed 🎉.

Something that is worth noticing is that it is designed to work with Docker which makes GitHub Actions quite powerful because setting up an environment becomes almost trivial! In my case, I basically needed Linux + R + publishing stuff, and this only required the following two lines (thanks to the great work of the Rocker team 👏):

1
2
runs-on: ubuntu-18.04
container: rocker/verse:latest

The remaining steps are self explanatory. Note that to better understand how to deploy the website, I followed the guidelines available on the README of the repository actions-gh-pages maintained by peaceiris, that are very well laid-out1. The last step was to add the badge, I used ghactions2 once more:

R> ghactions::use_ghactions_badge()

to generate the following badge3:

1
[![Actions Status](https://github.com/McCannLab/TheoryClub/workflows/Render%20and%20deploy%20GitBook/badge.svg)](https://github.com/McCannLab/TheoryClub/actions)

The workflow and the website are available in the repository of the theory club and if you want to learn more about it, you should have a look at the documentation, there are also several blogposts introducing this feature (e.g. one by Paul Czarkowski, another by Austin Roy)!


  1. And I used peaceiris/actions-hugo for this website. ↩︎

  2. By the way, some R users may have noticed that this package uses the same semantic as the other usethis) functions 😏! ↩︎

  3. I simply edited the URL. ↩︎