test-coverage.yml

Measure R-package test coverage with {covr} and upload the Cobertura report to Codecov. Adapts the r-lib/actions test-coverage.yaml example into the repo’s composite-plus-wrapper shape.

Set examples-coverage: true for an optional second job that measures coverage from examples and vignettes. \dontrun{} does not run under R CMD check by default (only with --run-dontrun, which --as-cran does not imply). \donttest{} is skipped unless --as-cran or --run-donttest. That job does not upload to Codecov, produce a JUnit report, or apply min-coverage. On failure it uploads its covr install tree as examples-coverage-test-failures. The percent appears in the job log and the step summary. Enabling it adds a second check named <caller job> / Examples and vignettes coverage. A min-coverage input can fail the tests job when coverage falls below a chosen percent. It defaults to no threshold and does not apply to the examples job, which measures a different execution path.

Inputs

Input Type Default Description
path string '.' Path to the R package root (the directory holding DESCRIPTION).
install-quarto boolean false Install Quarto when setting up R dependencies.
extra-packages string '' Extra R packages for the coverage run (covr and xml2 are always installed).
fail-ci-if-error string 'auto' Whether a Codecov upload error fails the job. 'auto' applies the r-lib heuristic (fail on non-PR events, and on pull requests only when a token is set); 'true' or 'false' force it.
upload-test-results boolean true Also generate a JUnit test-results report (testthat::JunitReporter) and upload it to Codecov Test Analytics (failed/flaky-test reporting), separate from the Cobertura line-coverage upload.
examples-coverage boolean false Run a second job that measures coverage from examples and vignettes (covr type = c("examples", "vignettes"), commentDonttest/commentDontrun both FALSE). Off by default.
min-coverage string '' Minimum percent coverage required to pass the tests job (covr::percent_coverage()). Empty defaults to no threshold. Does not apply to the examples/vignettes job.

Secrets

Secret Required Description
CODECOV_TOKEN No Codecov upload token. Optional for public repos, but recommended – tokenless uploads are rate-limited and unreliable from pull requests.

Permissions

Only contents: read (the default), so no permissions: block is needed.

Example

# Copy to .github/workflows/test-coverage.yml in your repo.
name: Test coverage

on:
  push:
    branches:
      - main
  pull_request:
  workflow_dispatch:

jobs:
  test-coverage:
    uses: Morrison-Lab/gha/.github/workflows/test-coverage.yml@v2
    secrets:
      CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
    # with:
    #   path: '.'                    # package root, if not the repo root
    #   install-quarto: false        # set true if vignettes need Quarto to build
    #   extra-packages: ''           # extra R packages for the coverage run
    #   fail-ci-if-error: 'auto'     # 'true'/'false' to force; 'auto' applies the r-lib heuristic
    #   upload-test-results: true    # JUnit report to Codecov Test Analytics (default true)
    #   examples-coverage: false     # second job: examples + vignettes, including \donttest/\dontrun
    #   min-coverage: ''             # fail the tests job when coverage falls below this percent; empty disables

See the examples/ directory for the full caller stub (test-coverage.yml).