Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 57 additions & 4 deletions .github/workflows/check-all-examples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,64 @@ jobs:
ivprobit=?ignore-before-r=100.0.0
local::.

# Deprecation warnings fail the check. Other warnings, which some examples
# raise on purpose, show up as annotations and do not fail it.
- name: Run examples
run: |
options(
crayon.enabled = TRUE,
warn = 2L
options(crayon.enabled = TRUE)

# base R and lifecycle deprecations have their own classes; easystats'
# own (insight::format_warning()) can only be told apart by their text,
# which says "deprecated" or, once removed, "defunct"
is_deprecation <- function(w) {
inherits(w, c("deprecatedWarning", "lifecycle_warning_deprecated")) ||
grepl("deprecated|defunct", conditionMessage(w), ignore.case = TRUE)
}

# the Rd file whose examples are running
current_rd <- function() {
for (i in rev(seq_len(sys.nframe()))) {
if (identical(sys.function(i), pkgload::run_example)) {
return(basename(get("path", envir = sys.frame(i))))
}
}
"examples"
}

annotate <- function(level, title, msg) {
msg <- gsub("\033\\[[0-9;]*m", "", msg)
msg <- gsub("%", "%25", msg, fixed = TRUE)
msg <- gsub("\r", "%0D", msg, fixed = TRUE)
msg <- gsub("\n", "%0A", msg, fixed = TRUE)
cat("\n::", level, " title=", title, "::", msg, "\n", sep = "")
}

deprecations <- character()
result <- tryCatch(
withCallingHandlers(
devtools::run_examples(run_dontrun = TRUE, run_donttest = TRUE, document = FALSE),
warning = function(w) {
rd <- current_rd()
if (is_deprecation(w)) {
deprecations <<- c(deprecations, rd)
annotate("error", paste("Deprecation warning in", rd), conditionMessage(w))
} else {
annotate("warning", paste("Warning in", rd), conditionMessage(w))
}
tryInvokeRestart("muffleWarning")
}
),
error = function(e) e
)
devtools::run_examples(run_dontrun = TRUE, run_donttest = TRUE, document = FALSE)

if (inherits(result, "error")) {
stop(result)
}
if (length(deprecations) > 0) {
stop(
"Deprecation warnings in the examples of: ",
toString(unique(deprecations)),
call. = FALSE
)
}
shell: Rscript {0}
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ name: test-coverage
| test-coverage-examples.yaml | Checks code coverage via examples in the manual and vignettes |
| test-coverage.yaml | Checks code coverage via tests |
| check-random-test-order.yaml | Randomizes the order in which test files are run to check that tests are self-contained. |
| check-all-examples.yaml | Runs *all* examples and checks that they execute successfully and without warnings |
| check-all-examples.yaml | Runs *all* examples and checks that they run without errors or deprecation warnings |
| check-link-rot.yaml | Checks that there are no outdated links (using `{urlchecker}`) |
| check-readme.yaml | Checks that the README can be properly rendered |
| check-spelling.yaml | Checks for spelling mistakes (using `{spelling}`) |
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ name: test-coverage
| test-coverage-examples.yaml | Checks code coverage via examples in the manual and vignettes |
| test-coverage.yaml | Checks code coverage via tests |
| check-random-test-order.yaml | Randomizes the order in which test files are run to check that tests are self-contained. |
| check-all-examples.yaml | Runs *all* examples and checks that they execute successfully and without warnings |
| check-all-examples.yaml | Runs *all* examples and checks that they run without errors or deprecation warnings |
| check-link-rot.yaml | Checks that there are no outdated links (using `{urlchecker}`) |
| check-readme.yaml | Checks that the README can be properly rendered |
| check-spelling.yaml | Checks for spelling mistakes (using `{spelling}`) |
Expand Down