-
Notifications
You must be signed in to change notification settings - Fork 186
71 lines (65 loc) · 2.11 KB
/
test-coverage-examples.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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}