Skip to content

Commit

Permalink
Automatically set log code and warnings when debuging a failing GHA r…
Browse files Browse the repository at this point in the history
…un (#193)

Fixes #175
  • Loading branch information
hadley authored Jul 2, 2024
1 parent 1109e0e commit 30ed781
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# evaluate (development version)

* Setting `ACTIONS_STEP_DEBUG=1` (as in a failing GHA workflow) will automatically set `log_echo` and `log_warning` to `TRUE` (#175).
* New `local_reproducible_output()` helper that sets various options and env vars to help ensure consistency of output across environments.
* The `source` output handler is now passed the entire top-level expression, not just the first component.
* `evaluate()` will now terminate on the first error in a top-level expression. This matches R's own behaviour more closely.
Expand Down
8 changes: 8 additions & 0 deletions R/eval.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
#' force these arguments to be set to `NA`.
#' @param log_echo,log_warning If `TRUE`, will immediately log code and
#' warnings (respectively) to `stderr`.
#'
#' This will be force to `TRUE` if env var `ACTIONS_STEP_DEBUG` is
#' `true`, as when debugging a failing GitHub Actions workflow.
#' @param new_device if `TRUE`, will open a new graphics device and
#' automatically close it after completion. This prevents evaluation from
#' interfering with your existing graphics environment.
Expand Down Expand Up @@ -68,6 +71,11 @@ evaluate <- function(input,
keep_message <- NA
keep_warning <- NA
}
if (env_var_is_true("ACTIONS_STEP_DEBUG")) {
log_warning <- TRUE
log_echo <- TRUE
}

on_message <- check_keep(keep_message, "keep_message")
on_warning <- check_keep(keep_warning, "keep_warning", log_warning)

Expand Down
5 changes: 4 additions & 1 deletion man/evaluate.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions tests/testthat/test-eval.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ test_that("log_echo causes output to be immediately written to stderr()", {
expect_equal(res[[1]]$src, "f()")
})

test_that("ACTIONS_STEP_DEBUG forces log_warning and log_echo to TRUE", {
f <- function() {
1
warning("abc")
}
out <- local({
withr::local_envvar(ACTIONS_STEP_DEBUG = "true")
capture.output(expect_warning(evaluate("f()"), "abc"), type = "message")
})
expect_equal(out, "f()")
})

test_that("data sets loaded", {
skip_if_not_installed("lattice")

Expand Down

0 comments on commit 30ed781

Please sign in to comment.