-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreport-generator.R
executable file
·66 lines (57 loc) · 2.04 KB
/
report-generator.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
#!/usr/bin/env Rscript
# Location
cat(sprintf("Current dir is: '%s'", getwd()))
# CVE-2022-24765 exception
git_safe_dir <- system(
sprintf("git config --global --add safe.directory '%s'", getwd())
)
# Get the action inputs from preset env vars
pkg_dir <- normalizePath(Sys.getenv("INPUT_REPORT_PKG_DIR", "."))
template_path <- Sys.getenv("INPUT_REPORT_TEMPLATE_PATH", "/template.Rmd")
report_format <- Sys.getenv("INPUT_REPORT_RMARKDOWN_FORMAT", "all")
report_output_prefix <- Sys.getenv("INPUT_REPORT_OUTPUT_PREFIX", "")
disable_install_dev_deps <- tolower(
Sys.getenv("DISABLE_INSTALL_DEV_DEPS")
) %in% c("yes", "y", "t", "true")
# fail with meaningful message if REPORT_PKG_DIR does not appear to be a package
desc_file <- file.path(pkg_dir, "DESCRIPTION")
if (!file.exists(desc_file)) {
stop(sprintf(
paste(sep = "\n",
"Could not find package at '%s'",
" ",
" Specify a directory by definining environment variable:",
" INPUT_REPORT_PKG_DIR=<repository subdirectory>",
" "
),
pkg_dir
))
}
# Install package dependencies
if (!disable_install_dev_deps) {
options("remotes.git_credentials" = git2r::cred_user_pass(
username = "token",
password = remotes:::github_pat()
))
devtools::install_dev_deps(pkg_dir, upgrade = "never")
}
# Set the output file name
if (report_output_prefix == "") {
desc <- read.dcf(desc_file)
pkg_name <- toString(desc[, "Package"])
pkg_version <- toString(desc[, "Version"])
report_output_prefix <- paste0(
pkg_name, "-", pkg_version, "-validation-report"
)
}
# allow rmarkdown to choose appropriate file extension for output format
report_file_path <- rmarkdown::render(
template_path,
output_dir = getwd(), # create report wherever R script was called
output_file = report_output_prefix,
output_format = report_format,
params = list(pkg_dir = pkg_dir)
)
# Create a tmp file which contains the final report filename
writeLines(report_file_path, "/tmp/report_file_path.txt")
cat(sprintf("Created report at: '%s'\n\n", report_file_path))