Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log startup script execution by default #720

Merged
merged 1 commit into from
Mar 1, 2023
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
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idle musing: This isn't a current use case, but we could eventually have a stable environment across all of these user tasks, which might let folks (somehow) build state during the "pre" step that can then get consumed during the "post" step..

}
}
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