-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GHA workflow to compute code coverage via examples (#1785)
* Create test-coverage-examples.yaml closes #1675 * Update test-coverage-examples.yaml * Update test-coverage-examples.yaml * Update test-coverage-examples.yaml * Update test-coverage-examples.yaml * add a list of exclusions * include observed coverage in examples as well * show integer value * more exceptions; one more example * Update test-coverage-examples.yaml * Update test-coverage-examples.yaml * Update test-coverage-examples.yaml * Update test-coverage-examples.yaml * exclude exclude * Update test-coverage-examples.yaml * run on a monthly basis
- Loading branch information
1 parent
e97be9b
commit ea1685b
Showing
6 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.