-
Notifications
You must be signed in to change notification settings - Fork 0
/
rhub-check.R
116 lines (94 loc) · 3.63 KB
/
rhub-check.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
### * Description
# This script can be used to check the package on various platforms using the rhub package.
# See: https://cran.r-project.org/web/packages/rhub/vignettes/rhub.html
### * Setup
library(here)
library(crayon)
library(rhub)
# The first time rhub is used on your machine, you should validate your email
# with:
# validate_email()
EMAIL <- "[email protected]"
### * Functions
### ** start_report()
#' Open a file for report writing
#' @param name File name to which a timestamp and the ".md" extension are appended.
#' @return A file descriptor to the file `name`, located in the project root directory.
start_report <- function(name = "rhub-report") {
name <- paste0(name, "_", format(Sys.time(), "%Y-%m-%d-%H%M%S"), ".md")
file <- file(here::here(name), open = "w")
cat("# Rhub check report, started on", format(Sys.time()), "\n", file = file)
return(file)
}
### ** check_and_report()
#' Run a rhub check for one platform and save the report to an open file
check_and_report <- function(platform, file) {
run <- check_and_wait(platform = platform)
cat("\n## Check for", platform, "\n", file = file)
write_report(run = run, file = file)
}
### ** close_report()
#' Close report file
close_report <- function(file) {
cat("\n# End of report,", format(Sys.time()), "\n", file = file)
close(file)
}
### ** check_and_wait()
#' Submit a check to rhub and wait for the run to complete
#'
#' @return Output from `check_for_cran()`
check_and_wait <- function(platform) {
env_vars <- c("_R_CHECK_FORCE_SUGGESTS_" = "true",
"_R_CHECK_CRAN_INCOMING_USE_ASPELL_" = "true")
if (grepl("macos", platform)) {
warning("Spell check turned off for r-hub check on MacOS.",
"See https://github.com/r-hub/rhub/issues/472")
env_vars["_R_CHECK_CRAN_INCOMING_USE_ASPELL_"] <- "false"
}
run <- check_for_cran(platform = platform, email = EMAIL, env_vars = env_vars,
show_status = FALSE)
completed <- FALSE
Sys.sleep(15)
while (!completed) {
completed <- tryCatch(run$cran_summary(),
error = function(e) {
if (grepl("At least one of the builds has not finished yet", e$message)) {
message("Results not ready yet, pausing for 60 seconds.")
Sys.sleep(60)
return(FALSE)
} else if (grepl("Timeout was reached", e$message)) {
message("Timeout issue, pausing for 60 seconds.")
Sys.sleep(60)
return(FALSE)
} else {
return(TRUE)
}})
if (typeof(completed) == "environment") {
completed <- TRUE
}
}
return(run)
}
### ** write_report()
#' Write report for one check
write_report <- function(run, file) {
z <- run$cran_summary()
cat(crayon::strip_style(capture.output(z$print())),
file = file, sep = "\n")
}
### * Check
# List platforms
platforms()
# Platforms selected for check
targets <- c("fedora-clang-devel",
"windows-x86_64-devel",
"macos-highsierra-release",
"ubuntu-gcc-release")
report <- start_report()
for (x in targets) {
check_and_report(platform = x, file = report)
}
close_report(report)
### * Alternative check on Windows
# For an alternative check on windows, one can run:
# devtools::check_win_devel(email = EMAIL)