Skip to content

test-coverage-examples #24

test-coverage-examples

test-coverage-examples #24

on:
schedule:
# * is a special character in YAML so you have to quote this string
# Trigger once a month at 10:00 on the first day of every month
- cron: "00 10 1 * *"
name: test-coverage-examples
jobs:
test-coverage-examples:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v4
- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: |
any::covr
local::.
- name: Test example coverage
run: |
options(crayon.enabled = TRUE)
library(covr)
files_to_exclude <- c(
# examples present but not run
"R/lint.R",
"R/use_lintr.R",
# mostly internal utilities
"R/actions.R",
"R/cache.R",
"R/deprecated.R",
"R/exclude.R",
"R/extract.R",
"R/ids_with_token.R",
"R/lintr-deprecated.R",
"R/make_linter_from_regex.R",
"R/make_linter_from_xpath.R",
"R/namespace.R",
"R/methods.R",
"R/settings.R",
"R/shared_constants.R",
"R/with.R",
"R/with_id.R",
"R/zzz.R"
)
coverage <- covr::package_coverage(
type = "examples",
quiet = TRUE,
commentDonttest = FALSE,
commentDontrun = FALSE,
line_exclusions = files_to_exclude
)
print(coverage)
percent_coverage <- as.integer(covr::percent_coverage(coverage))
threshold <- 90
cli::cli_rule()
if (percent_coverage < threshold) {
cli::cli_abort("Code coverage using examples ({percent_coverage}%) is below the required threshold ({threshold}%).")
} else {
cli::cli_alert_success("Code coverage using examples ({percent_coverage}%) is above the required threshold ({threshold}%).")
}
cli::cli_rule()
shell: Rscript {0}