Continuous Integration (and Deployment)

Continuous Integration (CI) and Continuous Deployment (CD)

  • *CI: runs all tests and checks on changes to the codebase
    • e.g., run our unit tests on any change to the code base
  • CD: builds and deploys any artifact (usually after all checks pass)
    • rebuild the documentation when everything passess

Github Actions

  • Tool and service for automating software development tasks
    • GitHub Actions makes it easier to work with GitHub repositories
  • Other related services: Travis, Circle CI, Jenkins, etc.

Key Terms

Specific wording for GitHub Actions

  • Action: Individual tasks you want to perform.
  • Workflow: A collection of actions (specified together in one file).
  • Event: Something that triggers the running of a workflow.
  • Runner: A machine that can run the Github Action(s).
  • Job: A set of steps executed on the same runner.
  • Step: A set of commands or actions which a job executes.

Create a workflow

In your github repository:

  1. Click on the Actions tab
  2. Click on New workflow on the left
  3. Click on Set up a workflow yourself

Example actions workflow

name: CI Example

on: [push, pull_request, workflow_dispatch]

jobs:
  my_steps:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - name: Run a one-line script
        run: echo Hello, world!

      - name: Run a multi-line script
        run: |
          echo Add other actions to build,
          echo test, and deploy your project.

Your Turn

The next 5 minutes:

  1. Create and run the simple github action workflow on your repository
  2. save the file into .github/workflows/ci_example.yaml
name: CI Example

on: [push, pull_request, workflow_dispatch]

jobs:
  my_steps:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - name: Run a one-line script
        run: echo Hello, world!

      - name: Run a multi-line script
        run: |
          echo Add other actions to build,
          echo test, and deploy your project.

Automatically check our package

  • Let’s make a new workflow named R-CMD-check
  • We will make sure the check() function passes for our function when we make changes to the repository

check-release.yaml

  • On your computer run: usethis::use_github_action("check-release")
on: [push, pull_request]

name: R-CMD-check

jobs:
  R-CMD-check:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout files from GitHub version control repository
        uses: actions/checkout@v2

      - name: Setup R
        uses: r-lib/actions/setup-r@v2

      - name: Install R packages
        uses: r-lib/actions/setup-r-dependencies@v2
        with:
          extra-packages: any::rcmdcheck
          needs: check

      - name: Checks if R package can be installed
        uses: r-lib/actions/check-r-package@v2

Make installations go faster

  • Many packages install from source on linux
  • Pre-compiled binaries exist for Windows and Mac

You can make the R package install setup faster if you replace the runner

From:

jobs:
  R-CMD-check:
    runs-on: ubuntu-latest

use either windows-latest or macos-latest

List of runners: https://github.com/actions/runner-images

Pkgdown + GitHub Actions

If you want more…

  • Look into the usethis::use_pkgdown_github_pages() function that sets up CD for your documentation site.
  • You may need to change the publishing location of websites to the gh-pages branch

Caution

  • Make sure you’re comfortable with how branches work in git.
  • You will want to re-ignore the docs/ directory so you don’t confuse youself and others.
  • The files you view locally will be in a different location on github.