Skip to content

Commit

Permalink
Provide way to register extra packages for revdep checks (#1745)
Browse files Browse the repository at this point in the history
Requires r-lib/revdepcheck#352 to work

Fixes #1610
  • Loading branch information
hadley authored Jan 24, 2023
1 parent 61ded87 commit 5ebd15a
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 18 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# usethis (development version)

* `use_release_issue()` now uses internal `release_extra_revdeps()` to
add extra revdep sources. Currently only use for internal Posit tooling,
but we hope to extend to all users in the future (#1610).

* `create_from_github()` will now use an existing `.Rproj` file if it exists
anywhere in the repo, not just the root directory. This is useful if you're
working with repos that contain tools for multiple languages (#1680).
Expand Down
60 changes: 47 additions & 13 deletions R/release.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,18 @@
#' The checklist contains a generic set of steps that we've found to be helpful,
#' based on the type of release ("patch", "minor", or "major"). You're
#' encouraged to edit the issue to customize this list to meet your needs.
#' If you want to consistently add extra bullets for every release, you can
#' include your own custom bullets by providing a (unexported) a
#' `release_bullets()` function that returns a character vector.
#' (For historical reasons, `release_questions()` is also supported).
#'
#' ## Customization
#'
#' * If you want to consistently add extra bullets for every release, you can
#' include your own custom bullets by providing an (unexported)
#' `release_bullets()` function that returns a character vector.
#' (For historical reasons, `release_questions()` is also supported).
#'
#' * If you want to check additional packages in the revdep check process,
#' provide an (unexported) `release_extra_revdeps()` function that
#' returns a character vector. This is currently only supported for
#' Posit internal check tooling.
#'
#' @param version Optional version number for release. If unspecified, you can
#' make an interactive choice.
Expand Down Expand Up @@ -94,13 +102,12 @@ release_checklist <- function(version, on_cran) {
todo("`rhub::check_for_cran()`"),
todo("`rhub::check(platform = 'ubuntu-rchk')`", has_src),
todo("`rhub::check_with_sanitizers()`", has_src),
todo("`revdepcheck::revdep_check(num_workers = 4)`", on_cran && !is_rstudio_pkg),
todo("`revdepcheck::cloud_check()`", on_cran && is_rstudio_pkg),
release_revdepcheck(on_cran, is_rstudio_pkg),
todo("Update `cran-comments.md`", on_cran),
todo("`git push`"),
todo("Draft blog post", type != "patch"),
todo("Slack link to draft blog in #open-source-comms", type != "patch" && is_rstudio_pkg),
release_extra(),
release_extra_bullets(),
"",
"Submit to CRAN:",
"",
Expand All @@ -122,13 +129,33 @@ release_checklist <- function(version, on_cran) {
)
}

release_extra <- function(env = NULL) {
if (is.null(env)) {
env <- tryCatch(
pkg_env(project_name()),
error = function(e) emptyenv()
)
release_revdepcheck <- function(on_cran = TRUE, is_rstudio_pkg = TRUE, env = NULL) {
if (!on_cran) {
return()
}

env <- env %||% safe_pkg_env()
if (env_has(env, "release_extra_revdeps")) {
extra <- env$release_extra_revdeps()
stopifnot(is.character(extra))
} else {
extra <- character()
}

if (is_rstudio_pkg) {
if (length(extra) > 0) {
extra_code <- paste0(deparse(extra), collapse = "")
todo("`revdepcheck::cloud_check(extra_revdeps = {extra_code})`")
} else {
todo("`revdepcheck::cloud_check()`")
}
} else {
todo("`revdepcheck::revdep_check(num_workers = 4)`")
}
}

release_extra_bullets <- function(env = NULL) {
env <- env %||% safe_pkg_env()

if (env_has(env, "release_bullets")) {
paste0("* [ ] ", env$release_bullets())
Expand All @@ -140,6 +167,13 @@ release_extra <- function(env = NULL) {
}
}

safe_pkg_env <- function() {
tryCatch(
ns_env(project_name()),
error = function(e) emptyenv()
)
}

release_type <- function(version) {
x <- unclass(numeric_version(version))[[1]]
n <- length(x)
Expand Down
12 changes: 10 additions & 2 deletions man/use_release_issue.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions tests/testthat/_snaps/release.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,25 @@
* [ ] Tweet
* [ ] Add link to blog post in pkgdown news menu

# construct correct revdep bullet

Code
release_revdepcheck(on_cran = FALSE)
Output
NULL
Code
release_revdepcheck(on_cran = TRUE, is_rstudio_pkg = FALSE)
Output
[1] "* [ ] `revdepcheck::revdep_check(num_workers = 4)`"
Code
release_revdepcheck(on_cran = TRUE, is_rstudio_pkg = TRUE)
Output
[1] "* [ ] `revdepcheck::cloud_check()`"
Code
release_revdepcheck(on_cran = TRUE, is_rstudio_pkg = TRUE, env = env)
Output
[1] "* [ ] `revdepcheck::cloud_check(extra_revdeps = c(\"waldo\", \"testthat\"))`"

# RStudio-ness detection works

Code
Expand Down
18 changes: 15 additions & 3 deletions tests/testthat/test-release.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,25 @@ test_that("release bullets don't change accidentally", {

test_that("get extra news bullets if available", {
env <- env(release_bullets = function() "Extra bullets")
expect_equal(release_extra(env), "* [ ] Extra bullets")
expect_equal(release_extra_bullets(env), "* [ ] Extra bullets")

env <- env(release_questions = function() "Extra bullets")
expect_equal(release_extra(env), "* [ ] Extra bullets")
expect_equal(release_extra_bullets(env), "* [ ] Extra bullets")

env <- env()
expect_equal(release_extra(env), character())
expect_equal(release_extra_bullets(env), character())
})

test_that("construct correct revdep bullet", {
create_local_package()
env <- env(release_extra_revdeps = function() c("waldo", "testthat"))

expect_snapshot({
release_revdepcheck(on_cran = FALSE)
release_revdepcheck(on_cran = TRUE, is_rstudio_pkg = FALSE)
release_revdepcheck(on_cran = TRUE, is_rstudio_pkg = TRUE)
release_revdepcheck(on_cran = TRUE, is_rstudio_pkg = TRUE, env = env)
})
})

test_that("RStudio-ness detection works", {
Expand Down

0 comments on commit 5ebd15a

Please sign in to comment.