-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathdeploy.R
68 lines (60 loc) · 1.71 KB
/
deploy.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
.libPaths("/usr/local/lib/R/site-library")
cat("loading packages from:", paste("\n - ", .libPaths(), collapse = ""), "\n\n")
# use renv to detect and install required packages.
if (file.exists("renv.lock")) {
renv::restore(prompt = FALSE)
} else {
renv::hydrate()
}
# set up some helper functions for fetching environment variables
defined <- function(name) {
!is.null(Sys.getenv(name)) && Sys.getenv(name) != ""
}
required <- function(name) {
if (!defined(name)) {
stop("!!! input or environment variable '", name, "' not set")
}
Sys.getenv(name)
}
optional <- function(name) {
if (!defined(name)) {
return(NULL)
}
Sys.getenv(name)
}
# resolve app dir
# Note that we are likely already executing from the app dir, as
# github sets the working directory to the workspace path on starting
# the docker image.
appDir <- ifelse(
defined("INPUT_APPDIR"),
required("INPUT_APPDIR"),
required("GITHUB_WORKSPACE")
)
# required inputs
appName <- required("INPUT_APPNAME")
accountName <- required("INPUT_ACCOUNTNAME")
accountToken <- required("INPUT_ACCOUNTTOKEN")
accountSecret <- required("INPUT_ACCOUNTSECRET")
# optional inputs
appFiles <- optional("INPUT_APPFILES")
appFileManifest <- optional("INPUT_APPFILEMANIFEST")
appTitle <- optional("INPUT_APPTITLE")
logLevel <- optional("INPUT_LOGLEVEL")
# process appFiles
if (!is.null(appFiles)) {
appFiles <- unlist(strsplit(appFiles, ",", TRUE))
}
# set up account
cat("checking account info...")
rsconnect::setAccountInfo(accountName, accountToken, accountSecret)
cat(" [OK]\n")
# deploy application
rsconnect::deployApp(
appDir = appDir,
appFiles = appFiles,
appFileManifest = appFileManifest,
appName = appName,
appTitle = appTitle,
account = accountName
)