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

Adjust to new RStudio version numbering #2410

Merged
merged 8 commits into from
Feb 23, 2022
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
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# devtools (development version)

* `dev_sitrep()` has been updated for the calendar-based version number scheme adopted by the RStudio IDE in September 2021 (#2397, #2410).

# devtools 2.4.3

* New `check_mac_release()` function to check a package using the macOS builder at https://mac.r-project.org/macbuilder/submit.html (#2375)
Expand Down
30 changes: 26 additions & 4 deletions R/sitrep.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,39 @@
#' @importFrom memoise memoise
NULL

check_for_rstudio_updates <- function(os = tolower(Sys.info()[["sysname"]]), version = rstudioapi::getVersion(), in_rstudio = rstudioapi::isAvailable()) {
rstudio_version_string <- function() {
if (!rstudioapi::isAvailable()) {
return(character())
}
rvi <- rstudioapi::versionInfo()
rvi$long_version %||% as.character(rvi$version)
}

check_for_rstudio_updates <- function(os = tolower(Sys.info()[["sysname"]]),
version = rstudio_version_string(),
in_rstudio = rstudioapi::isAvailable()) {
if (!in_rstudio) {
return()
}

url <- sprintf("https://www.rstudio.org/links/check_for_update?version=%s&os=%s&format=%s", version, os, "kvp")
url <- sprintf(
"https://www.rstudio.org/links/check_for_update?version=%s&os=%s&format=%s&manual=true",
utils::URLencode(version, reserved = TRUE), os, "kvp"
)

tmp <- file_temp()
on.exit(file_delete(tmp))
utils::download.file(url, tmp, quiet = TRUE)
withr::defer(file_exists(tmp) && nzchar(file_delete(tmp)))
suppressWarnings(
download_ok <- tryCatch({
utils::download.file(url, tmp, quiet = TRUE)
TRUE
}, error = function(e) FALSE)
)
if (!download_ok) {
return(
sprintf("Unable to check for RStudio updates (you're using %s).", version)
)
}
result <- readLines(tmp, warn = FALSE)

result <- strsplit(result, "&")[[1]]
Expand Down
39 changes: 39 additions & 0 deletions tests/testthat/_snaps/sitrep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# check_for_rstudio_updates

Code
writeLines(check_for_rstudio_updates("windows", "haha-no-wut", TRUE))
Output
Unable to check for RStudio updates (you're using haha-no-wut).

---

Code
writeLines(check_for_rstudio_updates("darwin", "0.0.1", TRUE))
Output
RStudio {VERSION} is now available (you're using 0.0.1).
Download at: https://www.rstudio.com/products/rstudio/download/

---

Code
writeLines(check_for_rstudio_updates("windows", "1.4.1717", TRUE))
Output
RStudio {VERSION} is now available (you're using 1.4.1717).
Download at: https://www.rstudio.com/products/rstudio/download/

---

Code
writeLines(check_for_rstudio_updates("darwin", "2021.09.1+372", TRUE))
Output
RStudio {VERSION} is now available (you're using 2021.09.1+372).
Download at: https://www.rstudio.com/products/rstudio/download/

---

Code
writeLines(check_for_rstudio_updates("windows", "2021.09.0-daily+328", TRUE))
Output
RStudio {VERSION} is now available (you're using 2021.09.0-daily+328).
Download at: https://www.rstudio.com/products/rstudio/download/

52 changes: 46 additions & 6 deletions tests/testthat/test-sitrep.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,54 @@ test_that("check_for_rstudio_updates", {
skip_if_offline()
skip_on_cran()

# the IDE ends up calling this with `os = "mac"` on macOS, but we would send
# "darwin" in that case, so I test with "darwin"
# also mix in some "windows"

# returns nothing rstudio not available
expect_null(check_for_rstudio_updates("mac", "1.0.0", FALSE))
expect_null(check_for_rstudio_updates("darwin", "1.0.0", FALSE))

# returns nothing if the version is ahead of the current version
expect_null(check_for_rstudio_updates("mac", "1000.0.0", TRUE))
expect_null(check_for_rstudio_updates("windows", "2030.12.0+123", TRUE))

# returns something if ...
local_edition(3)
scrub_current_version <- function(message) {
sub("(?<=^RStudio )[0-9\\.\\+]+", "{VERSION}", message, perl = TRUE)
}

# version is not understood by the service
expect_snapshot(
writeLines(check_for_rstudio_updates("windows", "haha-no-wut", TRUE))
)

# version is behind the current version

# truly ancient
expect_snapshot(
writeLines(check_for_rstudio_updates("darwin", "0.0.1", TRUE)),
transform = scrub_current_version
)

# Juliet Rose, does not have long_version, last before numbering changed
expect_snapshot(
writeLines(check_for_rstudio_updates("windows", "1.4.1717", TRUE)),
transform = scrub_current_version
)

# new scheme, introduced 2021-08
# YYYY.MM.<patch>[-(daily|preview)]+<build number>[.pro<pro suffix>]
# YYY.MM is th expected date of release for dailies and previews

# an out-of-date preview
expect_snapshot(
writeLines(check_for_rstudio_updates("darwin", "2021.09.1+372", TRUE)),
transform = scrub_current_version
)

# returns something if the version is behind of the current version
res <- check_for_rstudio_updates("mac", "0.0.1", TRUE)
expect_match(res, "RStudio .* is now available")
expect_match(res, "Download at")
# an out-of-date daily
expect_snapshot(
writeLines(check_for_rstudio_updates("windows", "2021.09.0-daily+328", TRUE)),
transform = scrub_current_version
)
})