-
Notifications
You must be signed in to change notification settings - Fork 756
/
check-win.R
149 lines (125 loc) · 4.58 KB
/
check-win.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#' Check a package on Windows
#'
#' This function first bundles a source package, then uploads it to
#' <https://win-builder.r-project.org/>. Once the service has built and checked
#' the package, an email is sent to address of the maintainer listed in
#' `DESCRIPTION`. This usually takes around 30 minutes. The email contains a
#' link to a directory with the package binary and check logs, which will be
#' deleted after a couple of days.
#'
#' @template devtools
#' @inheritParams pkgbuild::build
#' @param manual Should the manual be built?
#' @param email An alternative email address to use. If `NULL`, the default is
#' to use the package maintainer's email.
#' @param quiet If `TRUE`, suppresses output.
#' @param ... Additional arguments passed to [pkgbuild::build()].
#' @family build functions
#' @name check_win
NULL
#' @describeIn check_win Check package on the development version of R.
#' @export
check_win_devel <- function(pkg = ".", args = NULL, manual = TRUE, email = NULL, quiet = FALSE, ...) {
check_dots_used(action = getOption("devtools.ellipsis_action", rlang::warn))
check_win(
pkg = pkg, version = "R-devel", args = args, manual = manual,
email = email, quiet = quiet, ...
)
}
#' @describeIn check_win Check package on the released version of R.
#' @export
check_win_release <- function(pkg = ".", args = NULL, manual = TRUE, email = NULL, quiet = FALSE, ...) {
check_dots_used(action = getOption("devtools.ellipsis_action", rlang::warn))
check_win(
pkg = pkg, version = "R-release", args = args, manual = manual,
email = email, quiet = quiet, ...
)
}
#' @describeIn check_win Check package on the previous major release version of R.
#' @export
check_win_oldrelease <- function(pkg = ".", args = NULL, manual = TRUE, email = NULL, quiet = FALSE, ...) {
check_dots_used(action = getOption("devtools.ellipsis_action", rlang::warn))
check_win(
pkg = pkg, version = "R-oldrelease", args = args, manual = manual,
email = email, quiet = quiet, ...
)
}
check_win <- function(pkg = ".", version = c("R-devel", "R-release", "R-oldrelease"),
args = NULL, manual = TRUE, email = NULL, quiet = FALSE, ...) {
pkg <- as.package(pkg)
if (!is.null(email)) {
desc_file <- path(pkg$path, "DESCRIPTION")
backup <- file_temp()
file_copy(desc_file, backup)
on.exit(file_move(backup, desc_file), add = TRUE)
change_maintainer_email(desc_file, email, call = parent.frame())
pkg <- as.package(pkg$path)
}
version <- match.arg(version, several.ok = TRUE)
if (!quiet) {
cli::cli_inform(c(
"Building windows version of {.pkg {pkg$package}} ({pkg$version})",
i = "Using {paste(version, collapse = ', ')} with win-builder.r-project.org."
))
email <- maintainer(pkg)$email
if (interactive() && yesno("Email results to {.strong {email}}?")) {
return(invisible())
}
}
built_path <- pkgbuild::build(pkg$path, tempdir(),
args = args,
manual = manual, quiet = quiet, ...
)
on.exit(file_delete(built_path), add = TRUE)
url <- paste0(
"ftp://win-builder.r-project.org/", version, "/",
path_file(built_path)
)
lapply(url, upload_ftp, file = built_path)
if (!quiet) {
time <- strftime(Sys.time() + 30 * 60, "%I:%M %p")
email <- maintainer(pkg)$email
cli::cat_rule(col = "cyan")
cli::cli_inform(c(
i = "Check <{.email {email}}> for the results in 15-30 mins (~{time})."
))
}
invisible()
}
change_maintainer_email <- function(path, email, call = parent.frame()) {
desc <- desc::desc(file = path)
if (!desc$has_fields("Authors@R")) {
cli::cli_abort(
"DESCRIPTION must use {.field Authors@R} field when changing {.arg email}",
call = call
)
}
if (desc$has_fields("Maintainer")) {
cli::cli_abort(
"DESCRIPTION can't use {.field Maintainer} field when changing {.arg email}",
call = call
)
}
aut <- desc$get_authors()
roles <- aut$role
## Broken person() API, vector for 1 author, list otherwise...
if (!is.list(roles)) {
roles <- list(roles)
}
is_maintainer <- vapply(roles, function(r) all("cre" %in% r), logical(1))
aut[is_maintainer]$email <- email
desc$set_authors(aut)
desc$write()
}
upload_ftp <- function(file, url, verbose = FALSE) {
rlang::check_installed("curl")
stopifnot(file_exists(file))
stopifnot(is.character(url))
con <- file(file, open = "rb")
on.exit(close(con), add = TRUE)
h <- curl::new_handle(upload = TRUE, filetime = FALSE)
curl::handle_setopt(h, readfunction = function(n) {
readBin(con, raw(), n = n)
}, verbose = verbose)
curl::curl_fetch_memory(url, handle = h)
}