diff --git a/.github/workflows/check-all-examples.yaml b/.github/workflows/check-all-examples.yaml index 969bb93..524f1c5 100644 --- a/.github/workflows/check-all-examples.yaml +++ b/.github/workflows/check-all-examples.yaml @@ -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} diff --git a/README.Rmd b/README.Rmd index d896bcf..c2c56e3 100644 --- a/README.Rmd +++ b/README.Rmd @@ -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}`) | diff --git a/README.md b/README.md index 3438890..9eb83d5 100644 --- a/README.md +++ b/README.md @@ -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}`) |