CI/CD
R packages
Shiny
Foundations series · part 5

CI with GitHub Actions

R CMD check on every PR, with least privilege, pinned runtimes and no surprises

Run R CMD check, tests, and link validation automatically on clean GitHub Actions runners with pinned dependencies.
Published

2026-09-26

Modified

2026-09-27

The idea

Continuous integration means every PR is built and checked on a clean machine, the same way every time, before it can merge. For an R package that’s R CMD check. For a Shiny app it’s tests plus a deploy check. For a Quarto site it’s a render plus a link check. “Works on my machine” stops being an argument.

Anatomy of a workflow

name: ci
on:
  pull_request:
  push:
    branches: [main]

permissions:
  contents: read              # least privilege: read the code, nothing else

concurrency:
  group: ci-${{ github.ref }} # a new push to the same PR cancels the old run
  cancel-in-progress: true

jobs:
  check:
    runs-on: ubuntu-26.04     # pinned runner: avoids surprise moves when ubuntu-latest rolls
    steps:
      - uses: actions/checkout@v7
      - uses: actions/setup-node@v7
        with:
          node-version-file: .nvmrc   # runtime version comes from the repo
          cache: npm
      - run: npm ci                   # exact versions from the lockfile
      - run: npx biome ci             # lint + format
      - run: npm run typecheck
      - run: npm test
      - run: npm run build

Five habits that carry over to any language:

Habit Why R equivalent
permissions: contents: read A compromised step can’t push or open releases Same YAML
concurrency + cancel-in-progress No wasted minutes on stale pushes Same YAML
Runtime version read from the repo CI and laptops agree setup-r with r-version: renv reads renv.lock
Install from the lockfile Reproducible dependencies setup-renv, or setup-r-dependencies
Fail fast, cheapest check first Quick feedback lint → test → check

When one step fails, the later steps are skipped. We saw this with a deliberate type error: Typecheck: failure, then Unit tests: skipped, Build: skipped.

The R way: r-lib/actions

usethis copies the maintained examples from r-lib/actions:

usethis::use_github_action("check-standard")  # R CMD check: macOS, Windows, Ubuntu (devel/release/oldrel-1)
usethis::use_github_action("test-coverage")   # covr
usethis::use_github_action("pkgdown")         # build and deploy the package site
usethis::use_github_action("lint")            # lintr (see hooks, formatting & linting)
usethis::use_github_action("shiny-deploy")    # deploy a Shiny app with rsconnect

The core of check-standard:

- uses: r-lib/actions/setup-pandoc@v2
- uses: r-lib/actions/setup-r@v2
  with:
    r-version: ${{ matrix.config.r }}     # or 'renv' to use the lockfile's version
- uses: r-lib/actions/setup-r-dependencies@v2
  with:
    extra-packages: any::rcmdcheck
    needs: check
- uses: r-lib/actions/check-r-package@v2
  with:
    upload-snapshots: true                # testthat/shinytest2 snapshots on failure

Two cheap hardening edits to the stock example: it ships with permissions: read-all, which you can narrow to permissions: contents: read, and it has no concurrency block, so add one.

Shiny apps: shinytest2 tests live in tests/testthat/, so they run inside R CMD check (for app-in-a-package) or with testthat::test_dir(). Failed snapshots are uploaded as artifacts.

Quarto sites: use quarto-dev/quarto-actions/setup and .../render, pin the Quarto version, and add a link checker. This playbook’s own .github/workflows/quarto.yml is a worked example. It renders, checks internal links with lychee, and deploys a preview per PR.

Pinning: how tightly?

Style Example Trade-off
Major tag r-lib/actions/setup-r@v2 Gets fixes automatically; trusts the maintainer
Exact tag @v2.14.0 Reproducible; you must bump it
Commit SHA @<40-char sha> Immutable, best supply-chain safety; unreadable without comments

Major tags plus Dependabot for github-actions (dependency updates & vetting) is a sensible default. Regulated production pipelines may justify SHA pinning.

Also pin the runner image if stability matters. ubuntu-latest moves over time: GitHub moves ubuntu-latest to Ubuntu 26.04 in a rollout that starts on 19 October 2026. On 2026-09-27, we moved the pinned runners in this repository to runs-on: ubuntu-26.04 deliberately ahead of the rollout, rather than waiting for ubuntu-latest to transition underneath us.

Pitfalls

  • Generated files must be generated in CI. Our Next.js typecheck failed on a fresh checkout until CI ran next typegen first. The R version of this is an out-of-date NAMESPACE: run devtools::document() and commit the result, or check it in CI.
  • Secrets in PRs from forks aren’t available (by design). Design deploy steps to skip cleanly.
  • Don’t continue-on-error your way to green. A check that can’t fail isn’t a check.
  • Watch the matrix size. Five OS/R combinations per push adds up on private repos, where Actions minutes are billed against your plan’s quota.

Sources

GitHub Actions

R package documentation

NoteUpdates
  • 2026-09-26: Removed the end-of-post checklist.
  • 2026-09-26: Pinned runs-on: ubuntu-24.04 across all GitHub Actions workflows in both repositories ahead of GitHub’s scheduled ubuntu-latest transition to Ubuntu 26 (19 October 2026), deferring the runner upgrade until we validate it deliberately.
  • 2026-09-27: Added a Sources section.
  • 2026-09-27: Moved the pinned runners from ubuntu-24.04 to ubuntu-26.04, ahead of the ubuntu-latest rollout.