Skip to content

Commit

Permalink
Log startup script execution by default
Browse files Browse the repository at this point in the history
Fixes #542
  • Loading branch information
hadley committed Feb 28, 2023
1 parent 3bea4b7 commit bac9e28
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# rsconnect 0.8.30 (development version)

* `deployApp()` now advertises which startup scripts are run at the normal
`logLevel`, and it evaluates each script in its own environment (#542).

* `deployments()` now formats `when` and `lastSyncTime` as date-times (#714).

* `deployApp()` now derives `appName` from `appDir` and `appPrimaryDoc`,
Expand Down
18 changes: 9 additions & 9 deletions R/deployApp.R
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ deployApp <- function(appDir = getwd(),
displayStatus <- displayStatus(quiet)

# run startup scripts to pick up any user options and establish pre/post deploy hooks
runStartupScripts(appDir, logLevel)
runStartupScripts(appDir, quiet = quiet, verbose = verbose)

# at verbose log level, turn on all tracing options implicitly for the
# duration of the call
Expand Down Expand Up @@ -611,22 +611,22 @@ openURL <- function(client, application, launch.browser, on.failure, deploymentS
# or open no url if things failed
}

runStartupScripts <- function(appDir, logLevel) {
runStartupScripts <- function(appDir, quiet = FALSE, verbose = FALSE) {
scripts <- c(
# the site-wide startup script
file.path(R.home("etc"), "rsconnect.site"),
# the user startup script
path.expand("~/.rsconnect_profile"),
# a startup script specific to this application
file.path(appDir, ".rsconnect_profile"))
file.path(appDir, ".rsconnect_profile")
)
scripts <- scripts[file.exists(scripts)]

# iterate over the startup scripts
for (script in scripts) {
if (file.exists(script)) {
if (logLevel == "verbose") {
cat("----- Sourcing startup script", script, "-----\n")
}
source(file = script, verbose = (logLevel == "verbose"))
}
taskStart(quiet, "Running {script}")

env <- new_environment(parent = globalenv())
source(script, verbose = verbose, local = env)
}
}
7 changes: 7 additions & 0 deletions tests/testthat/_snaps/deployApp.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@
Error in `deployApp()`:
! `appSourceDoc`, "records", does not exist.

# startup scripts are logged by default

Code
runStartupScripts(".")
Message
i Running ./.rsconnect_profile

# deployHook executes function if set

Code
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/test-deployApp.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ test_that("appSourceDoc is deprecated & checks path", {
})
})

test_that("startup scripts are logged by default", {
dir <- local_temp_app()
withr::local_dir(dir)
writeLines("1 + 1", file.path(dir, ".rsconnect_profile"))

expect_snapshot(runStartupScripts("."))
})

# record directory --------------------------------------------------------

test_that("findRecordPath() uses recordDir, then appPrimaryDoc, then appDir", {
Expand Down

0 comments on commit bac9e28

Please sign in to comment.