Today is the day I’ve started using GitHub Actions. I found the following two resources really helpful:

GitHub Actions allow you to create workflows that will execute tasks on a certain action, like pushing changes onto GitHub.

Each time you complete an action (push changes to your repository), the workflow will be executed. For example, today I’ve added a workflow (Quickstart Continuous Integration workflow) to my basicPlotteR package, which does the following:

  • Boots up a mac OS computer
  • Checks R is installed
  • Installs two packages:
  • Installs my basicPlotteR package
  • Runs rcmdcheck() from the rcmdcheck package, which:
    • Checks all the function documentation
    • Runs all the examples for the functions to check they work
    • Checks all functions dependencies
    • Checks the R package structure
    • And many more!!

With this workflow in place, every time I edit the code for my basicPlotteR package, the above checks will be run and I’ll know straight away if I have caused any problems!

GitHub Actions require a YAML formatted file to define the workflow. The Quickstart Continuous Integration workflow (available here) looks like this:

# Define when the action is to be triggered
on:
  push:
    branches:
      - main
      - master
  pull_request:
    branches:
      - main
      - master

name: R-CMD-check

jobs:
  R-CMD-check: # Name of job
    runs-on: macOS-latest # Define OS you want to run action on, you can have multiple!
    steps:

      # Checkout (download) repository 
      - uses: actions/checkout@v2

      # Install R
      - uses: r-lib/actions/setup-r@v1
      
      # Install required packages
      - name: Install dependencies
        run: |
          install.packages(c("remotes", "rcmdcheck"))
          remotes::install_deps(dependencies = TRUE)
        shell: Rscript {0}
      
      # Run the rcmdcheck function on R package repository
      - name: Check
        run: rcmdcheck::rcmdcheck(args = "--no-manual", error_on = "error")
        shell: Rscript {0}

I saved the above YAML code in a file called .github/workflows/R-CMD-check.yaml in my basicPlotteR repository. Note, that I had to create the .github and workflows folders and explicitely push them onto GitHub using git add .github/workflows/R-CMD-check.yaml.

With the workflow pushed online, GitHub automatically started running the workflow!

actions

As the above screenshot shows, the code for my basicPlotteR package needed some tidying up to get it to pass the rcmdcheck() checks! 😨

But I got there in the end!!! 🎉

actions

I added the status badge to the repository README.md using the following markdown code in the top line:

[![R build status](https://github.com/JosephCrispell/basicPlotteR/workflows/R-CMD-check/badge.svg)](https://github.com/JosephCrispell/basicPlotteR/actions?workflow=R-CMD-check)

The path to the badge.svg file is in my repository but you’ll find no trace of it - I am not sure why this is but the badge is working, so I’ll not question it! 🤔

Well, I’ve been amazed by the power of GitHub Actions and I’ve only just started! I can’t wait to introduce more complex checks and add workflows to all my repositories!!!

Oh, and Happy Halloween!!! 🧡