From 8bc85ebdbf39669749f6b308552efbf0dcee5cc2 Mon Sep 17 00:00:00 2001 From: pat-s Date: Fri, 17 Jul 2020 07:33:37 +0200 Subject: [PATCH 01/13] add `check_pre_release_state()` --- R/auto.R | 13 +++++++++---- R/state.R | 22 ++++++++++++++++++++++ R/update-version.R | 26 ++++++++++++++++---------- 3 files changed, 47 insertions(+), 14 deletions(-) create mode 100644 R/state.R diff --git a/R/auto.R b/R/auto.R index 832050a55..04e8a8d9d 100644 --- a/R/auto.R +++ b/R/auto.R @@ -14,12 +14,17 @@ #' @inheritParams bump_version #' @name release #' @export -pre_release <- function(which = "patch") { - check_only_modified(character()) +pre_release <- function(which = "patch", force = FALSE) { + + state = check_pre_release_state(which = which, force = force) - stopifnot(which %in% c("patch", "minor", "major")) + if (state) { + check_only_modified(character()) - with_repo(pre_release_impl(which)) + stopifnot(which %in% c("patch", "minor", "major")) + + with_repo(pre_release_impl(which)) + } } pre_release_impl <- function(which) { diff --git a/R/state.R b/R/state.R new file mode 100644 index 000000000..deae30fa3 --- /dev/null +++ b/R/state.R @@ -0,0 +1,22 @@ +check_pre_release_state = function(which, force = FALSE) { + + # check version number + if (length(strsplit(as.character(desc::desc_get_version()), "[.]|-")[[1]]) < 4) { + ui_oops("pre_release(): Package versions needs to indicate a dev version before calling pre_release().") + state = FALSE + return(state) + } else if (file.exists("cran-comments.md")) { + ui_oops("pre_release(): cran-comments.md already exists.") + state = FALSE + return(state) + } else if (file.exists("CRAN-RELEASE")) { + ui_oops("pre_release(): CRAN-RELEASE already exists.") + state = FALSE + return(state) + } else if (git2r::is_branch(sprintf("cran-%s", update_version_helper(which)))) { + ui_oops(sprintf("pre_release(): 'cran-%s' branch already exists.", update_version_helper(which))) + state = FALSE + } else { + state = TRUE + } +} diff --git a/R/update-version.R b/R/update-version.R index d355209de..7aa95412d 100644 --- a/R/update-version.R +++ b/R/update-version.R @@ -1,14 +1,5 @@ update_version_impl <- function(which) { - desc <- desc::desc(file = "DESCRIPTION") - - if (desc$has_fields("Date")) { - desc$set("Date", Sys.Date()) - } - - # https://github.com/r-lib/desc/issues/93 - suppressMessages(desc$bump_version(which)) - - new_version <- desc$get_version() + new_version <- update_version_helper(which = which) ui_done("Package version bumped to {ui_value(new_version)}") @@ -24,6 +15,21 @@ update_version_impl <- function(which) { desc$write() } +update_version_helper <- function(which) { + desc <- desc::desc(file = "DESCRIPTION") + + if (desc$has_fields("Date")) { + desc$set("Date", Sys.Date()) + } + + # https://github.com/r-lib/desc/issues/93 + suppressMessages(desc$bump_version(which)) + + new_version <- desc$get_version() + + return(new_version) +} + date_in_news_headers <- function() { headers <- get_news_headers() if (nrow(headers) == 0) { From 4cef4b0c5fa2c0739d63290ce580cf5d19acb8b7 Mon Sep 17 00:00:00 2001 From: pat-s Date: Fri, 17 Jul 2020 14:07:50 +0200 Subject: [PATCH 02/13] use ui_code() --- R/state.R | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/R/state.R b/R/state.R index deae30fa3..a88eac2cc 100644 --- a/R/state.R +++ b/R/state.R @@ -1,22 +1,29 @@ -check_pre_release_state = function(which, force = FALSE) { +check_pre_release_state <- function(which, force = FALSE) { # check version number if (length(strsplit(as.character(desc::desc_get_version()), "[.]|-")[[1]]) < 4) { - ui_oops("pre_release(): Package versions needs to indicate a dev version before calling pre_release().") - state = FALSE + ui_oops(paste0( + ui_code("pre_release()"), + ": Package versions needs to indicate a dev version before calling ", + ui_code("pre_release()"), "." + )) + state <- FALSE return(state) } else if (file.exists("cran-comments.md")) { - ui_oops("pre_release(): cran-comments.md already exists.") - state = FALSE + ui_oops(paste0(ui_code("pre_release()"), ": cran-comments.md already exists.")) + state <- FALSE return(state) } else if (file.exists("CRAN-RELEASE")) { - ui_oops("pre_release(): CRAN-RELEASE already exists.") - state = FALSE + ui_oops(paste0(ui_code("pre_release()"), ": CRAN-RELEASE already exists.")) + state <- FALSE return(state) } else if (git2r::is_branch(sprintf("cran-%s", update_version_helper(which)))) { - ui_oops(sprintf("pre_release(): 'cran-%s' branch already exists.", update_version_helper(which))) - state = FALSE + ui_oops(sprintf(paste0( + ui_code("pre_release()"), + ": 'cran-%s' branch already exists.", update_version_helper(which) + ))) + state <- FALSE } else { - state = TRUE + state <- TRUE } } From d79dc6fe0892b4defbcbc5259bc18d6631a735f4 Mon Sep 17 00:00:00 2001 From: pat-s Date: Fri, 17 Jul 2020 14:08:03 +0200 Subject: [PATCH 03/13] style --- R/auto.R | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/R/auto.R b/R/auto.R index 04e8a8d9d..aa4a54306 100644 --- a/R/auto.R +++ b/R/auto.R @@ -16,7 +16,7 @@ #' @export pre_release <- function(which = "patch", force = FALSE) { - state = check_pre_release_state(which = which, force = force) + state <- check_pre_release_state(which = which, force = force) if (state) { check_only_modified(character()) @@ -272,14 +272,14 @@ check_post_release <- function() { ui_info("Checking contents of {ui_path('CRAN-RELEASE')}") if (!file.exists("CRAN-RELEASE")) { - abort('File `CRAN-RELEASE` not found. Recreate with `devtools:::flag_release()`.') + abort("File `CRAN-RELEASE` not found. Recreate with `devtools:::flag_release()`.") } release <- paste(readLines("CRAN-RELEASE"), collapse = "\n") rx <- "^.*[(]commit ([0-9a-f]+)[)].*$" commit <- grepl(rx, release) if (!commit) { - abort('Unexpected format of `CRAN-RELEASE` file. Recreate with `devtools:::flag_release()`.') + abort("Unexpected format of `CRAN-RELEASE` file. Recreate with `devtools:::flag_release()`.") } sha <- gsub(rx, "\\1", release) @@ -301,6 +301,8 @@ check_post_release <- function() { gh_scopes <- function() { out <- attr(gh::gh("/user"), "response")$"x-oauth-scopes" - if (out == "") return(character()) + if (out == "") { + return(character()) + } strsplit(out, ", *")[[1]] } From 9566c273c2b06cc9bb343f98022a2870bb4bd459 Mon Sep 17 00:00:00 2001 From: pat-s Date: Fri, 7 Aug 2020 10:30:21 +0200 Subject: [PATCH 04/13] ensure desc object is present --- R/update-version.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/update-version.R b/R/update-version.R index 7aa95412d..3a4a884b2 100644 --- a/R/update-version.R +++ b/R/update-version.R @@ -1,5 +1,6 @@ update_version_impl <- function(which) { new_version <- update_version_helper(which = which) + desc <- desc::desc(file = "DESCRIPTION") ui_done("Package version bumped to {ui_value(new_version)}") From 215d93cba085440b54b9d72d69ca4950bb1cc2d7 Mon Sep 17 00:00:00 2001 From: pat-s Date: Mon, 24 Aug 2020 17:01:22 +0200 Subject: [PATCH 05/13] return modified R6 `desc` object --- R/update-version.R | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/R/update-version.R b/R/update-version.R index 3a4a884b2..496984a50 100644 --- a/R/update-version.R +++ b/R/update-version.R @@ -1,6 +1,6 @@ update_version_impl <- function(which) { - new_version <- update_version_helper(which = which) - desc <- desc::desc(file = "DESCRIPTION") + + desc <- update_version_helper(which = which) ui_done("Package version bumped to {ui_value(new_version)}") @@ -26,9 +26,7 @@ update_version_helper <- function(which) { # https://github.com/r-lib/desc/issues/93 suppressMessages(desc$bump_version(which)) - new_version <- desc$get_version() - - return(new_version) + return(desc) } date_in_news_headers <- function() { From 4d91e6ea516fe67d18209aa1986c36a498e612ac Mon Sep 17 00:00:00 2001 From: pat-s Date: Mon, 24 Aug 2020 17:01:38 +0200 Subject: [PATCH 06/13] refactor check_release_state() --- R/state.R | 57 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/R/state.R b/R/state.R index a88eac2cc..baec22d3d 100644 --- a/R/state.R +++ b/R/state.R @@ -1,29 +1,36 @@ -check_pre_release_state <- function(which, force = FALSE) { +check_release_state <- function(which) { - # check version number - if (length(strsplit(as.character(desc::desc_get_version()), "[.]|-")[[1]]) < 4) { - ui_oops(paste0( - ui_code("pre_release()"), - ": Package versions needs to indicate a dev version before calling ", - ui_code("pre_release()"), "." - )) - state <- FALSE - return(state) - } else if (file.exists("cran-comments.md")) { - ui_oops(paste0(ui_code("pre_release()"), ": cran-comments.md already exists.")) - state <- FALSE - return(state) - } else if (file.exists("CRAN-RELEASE")) { - ui_oops(paste0(ui_code("pre_release()"), ": CRAN-RELEASE already exists.")) - state <- FALSE - return(state) - } else if (git2r::is_branch(sprintf("cran-%s", update_version_helper(which)))) { - ui_oops(sprintf(paste0( - ui_code("pre_release()"), - ": 'cran-%s' branch already exists.", update_version_helper(which) - ))) - state <- FALSE + # meta info + new_version <- update_version_helper(which)$get_version() + pkg <- desc::desc_get_field("Package") + version_components <- length(strsplit(as.character(desc::desc_get_version()), "[.]|-")[[1]]) + # mirrors do not seem to work (due to CRAN vacay?) + cran_details <- withr::with_options( + list(repos = structure(c(CRAN = "https://cloud.r-project.org/"))), + foghorn::cran_details(pkg, src = "website") + ) + cran_version <- as.character(cran_details[1, "version"]) + cran_inc <- withr::with_options( + list(repos = structure(c(CRAN = "https://cloud.r-project.org/"))), + { + incoming <- foghorn::cran_incoming( + pkg, + c("pretest", "inspect", "pending", "publish", "waiting", "recheck") + ) + ifelse(nrow(incoming == 0), FALSE, TRUE) + } + ) + + # determine state + if (version_components == 4) { + return("pre-release") + } else if (new_version == cran_version) { + return("accepted") + } else if (cran_inc) { + return("submitted") + } else if (is_cran_comments_good()) { + return("ready-to-release") } else { - state <- TRUE + return("running-release-checks") } } From 5662a5b5fcd395f79735bc932774e21b4c41db77 Mon Sep 17 00:00:00 2001 From: pat-s Date: Mon, 24 Aug 2020 17:01:54 +0200 Subject: [PATCH 07/13] add unleash.R --- R/unleash.R | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 R/unleash.R diff --git a/R/unleash.R b/R/unleash.R new file mode 100644 index 000000000..e045b4e79 --- /dev/null +++ b/R/unleash.R @@ -0,0 +1,16 @@ +# Feature: allow to specify a numeric version in `which` +unleash <- function(which, force = FALSE) { + + state <- check_release_state() + + switch(state, + "pre-release" = pre_release(which, force), + "ready-to-release" = release(), + "accepted" = post_release(), + "submitted" = TRUE, + "running-release-checks" = TRUE, + + # FIXME: Improve error handling/messages + FALSE = stop("No valid state detected.") + ) +} From a972ec94357dcbd0a52de77987fb78f62de4b986 Mon Sep 17 00:00:00 2001 From: pat-s Date: Fri, 2 Oct 2020 15:13:36 +0200 Subject: [PATCH 08/13] small fixes --- NAMESPACE | 5 +---- R/unleash.R | 7 ++----- man/release.Rd | 2 +- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 2cf611fe5..e14d8236f 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -12,11 +12,8 @@ export(tag_version) export(unbump_version) export(update_news) export(update_version) -<<<<<<< HEAD -import(glue) -======= import(cli) ->>>>>>> master +import(glue) import(rlang) import(usethis) importFrom(purrr,discard) diff --git a/R/unleash.R b/R/unleash.R index e045b4e79..2f5670003 100644 --- a/R/unleash.R +++ b/R/unleash.R @@ -1,16 +1,13 @@ # Feature: allow to specify a numeric version in `which` unleash <- function(which, force = FALSE) { - state <- check_release_state() + state <- check_release_state(which) switch(state, "pre-release" = pre_release(which, force), "ready-to-release" = release(), "accepted" = post_release(), "submitted" = TRUE, - "running-release-checks" = TRUE, - - # FIXME: Improve error handling/messages - FALSE = stop("No valid state detected.") + "running-release-checks" = TRUE ) } diff --git a/man/release.Rd b/man/release.Rd index bf349d875..1444a9cde 100644 --- a/man/release.Rd +++ b/man/release.Rd @@ -6,7 +6,7 @@ \alias{post_release} \title{Automating CRAN release} \usage{ -pre_release(which = "patch") +pre_release(which = "patch", force = FALSE) release() From 712b78af04e1acbe59c179abb8ffd26d7e34f0cc Mon Sep 17 00:00:00 2001 From: pat-s Date: Fri, 2 Oct 2020 15:21:34 +0200 Subject: [PATCH 09/13] fix update_version.R --- R/update-version.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/update-version.R b/R/update-version.R index 1d1f42a35..941f10c4b 100644 --- a/R/update-version.R +++ b/R/update-version.R @@ -1,12 +1,13 @@ update_version_impl <- function(which) { desc <- update_version_helper(which = which) + new_version = desc$get_version() cli_h2("Update Version") cli_alert_success("Package version bumped to {.field {new_version}}.") - cli_alert("Adding header to {.file {news_path}}.") + cli_alert("Adding header to {.file NEWS.md}.") header <- paste0( "# ", desc$get("Package"), " ", new_version, From 5c40a2048d8375d90cee093a0cfc79ca27401b7d Mon Sep 17 00:00:00 2001 From: pat-s Date: Fri, 2 Oct 2020 15:28:27 +0200 Subject: [PATCH 10/13] fixes after first release try --- NAMESPACE | 1 + R/auto.R | 28 +++++++++++++++++----------- R/bump-version.R | 3 +++ R/state.R | 2 +- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index e14d8236f..ccfe6b80e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -8,6 +8,7 @@ export(get_top_level_commits) export(post_release) export(pre_release) export(release) +export(tag_release_candidate) export(tag_version) export(unbump_version) export(update_news) diff --git a/R/auto.R b/R/auto.R index aa4a54306..3eae3ba5f 100644 --- a/R/auto.R +++ b/R/auto.R @@ -16,15 +16,11 @@ #' @export pre_release <- function(which = "patch", force = FALSE) { - state <- check_pre_release_state(which = which, force = force) - - if (state) { - check_only_modified(character()) + check_only_modified(character()) - stopifnot(which %in% c("patch", "minor", "major")) + stopifnot(which %in% c("patch", "minor", "major")) - with_repo(pre_release_impl(which)) - } + with_repo(pre_release_impl(which, force)) } pre_release_impl <- function(which) { @@ -37,15 +33,19 @@ pre_release_impl <- function(which) { bump_version(which) + cli_h2("Preparing CRAN release") + release_branch <- create_release_branch() switch_branch(release_branch) update_cran_comments() - push_to_new(remote_name) + cli_h2("Pushing branches and bumping version") + + push_to_new(remote_name) switch_branch(main_branch) - bump_version() - finalize_version(push = TRUE) + # manual implementation of bump_version(), it doesn't expose `force` yet + bump_version_to_dev_with_force(force) switch_branch(release_branch) usethis::use_git_ignore("CRAN-RELEASE") @@ -81,6 +81,9 @@ switch_branch <- function(name) { } update_cran_comments <- function() { + + cli_h2("Preparing cran-comments.md") + package <- desc::desc_get("Package") crp_date <- get_crp_date() cransplainer <- get_cransplainer(package) @@ -104,7 +107,7 @@ update_cran_comments <- function() { # FIXME: CRP compare # https://github.com/octo-org/wikimania/compare/master@%7B07-22-16%7D...master@%7B08-04-16%7D - git2r::add(path = "cran-comments.md") + git2r::add(path = "cran-comments.md", force = TRUE) git2r::commit(message = "Update CRAN comments") } @@ -164,6 +167,9 @@ release_impl <- function() { stopifnot(is_cran_comments_good()) push_head(get_head_branch()) + + cli_h2("Releasing to CRAN") + # FIXME: Copy code from devtools, silent release devtools::submit_cran() auto_confirm() diff --git a/R/bump-version.R b/R/bump-version.R index fa99cc75c..cb3526507 100644 --- a/R/bump-version.R +++ b/R/bump-version.R @@ -19,4 +19,7 @@ bump_version_impl <- function(which) { cli_alert_warning("After CRAN release, call {.fun fledge::tag_version} and {.fun fledge::bump_version} to re-enter development mode") } + + cli_par() + cli_end() } diff --git a/R/state.R b/R/state.R index baec22d3d..6a5654184 100644 --- a/R/state.R +++ b/R/state.R @@ -17,7 +17,7 @@ check_release_state <- function(which) { pkg, c("pretest", "inspect", "pending", "publish", "waiting", "recheck") ) - ifelse(nrow(incoming == 0), FALSE, TRUE) + ifelse(nrow(incoming) == 0, FALSE, TRUE) } ) From eb66dbbac2dac9225325a6731a0b0d8d15a92ca4 Mon Sep 17 00:00:00 2001 From: pat-s Date: Fri, 2 Oct 2020 16:25:46 +0200 Subject: [PATCH 11/13] re-add bump_version_to_dev_with_force() --- NAMESPACE | 1 - R/bump-version.R | 11 +++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/NAMESPACE b/NAMESPACE index ccfe6b80e..e14d8236f 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -8,7 +8,6 @@ export(get_top_level_commits) export(post_release) export(pre_release) export(release) -export(tag_release_candidate) export(tag_version) export(unbump_version) export(update_news) diff --git a/R/bump-version.R b/R/bump-version.R index cb3526507..549f1784c 100644 --- a/R/bump-version.R +++ b/R/bump-version.R @@ -23,3 +23,14 @@ bump_version_impl <- function(which) { cli_par() cli_end() } + +bump_version_to_dev_with_force <- function(force) { + update_news() + update_version() + + head <- get_head_branch() + force <- commit_version() || force + tag <- tag_version(force) + push_tag(tag) + push_head(head) +} From ae131a07b72d2ca401af990fcd93dd5c56b8144a Mon Sep 17 00:00:00 2001 From: pat-s Date: Wed, 7 Oct 2020 17:08:44 +0200 Subject: [PATCH 12/13] push release version to main branch before bumping to dev again --- R/auto.R | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/R/auto.R b/R/auto.R index 48f75fd28..c101d991e 100644 --- a/R/auto.R +++ b/R/auto.R @@ -28,13 +28,13 @@ pre_release <- function(which = "patch", force = FALSE) { pre_release_impl <- function(which) { stopifnot(git2r::is_branch(git2r::repository_head())) - + # check PAT scopes for PR for early abort check_gh_scopes() - + remote_name <- get_remote_name() main_branch <- get_branch_name() - + # Commit ignored files as early as possible usethis::use_git_ignore("CRAN-RELEASE") usethis::use_build_ignore("CRAN-RELEASE") @@ -56,13 +56,16 @@ pre_release_impl <- function(which) { push_to_new(remote_name) switch_branch(main_branch) + # to trigger a run with the release version + push_head(main_branch) # manual implementation of bump_version(), it doesn't expose `force` yet bump_version_to_dev_with_force(force) + push_head(main_branch) switch_branch(release_branch) usethis::use_git_ignore("CRAN-RELEASE") usethis::use_build_ignore("CRAN-RELEASE") - + ui_todo("Run {ui_code('devtools::check_win_devel()')}") ui_todo("Run {ui_code('rhub::check_for_cran()')}") ui_todo("Check all items in {ui_path('cran-comments.md')}") From 35b97e13ffef004d02eaa333f6b7416bf4b6da5e Mon Sep 17 00:00:00 2001 From: pat-s Date: Fri, 30 Oct 2020 17:27:14 +0100 Subject: [PATCH 13/13] - check_release_state(): escape errors if package is not yet on CRAN --- R/state.R | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/R/state.R b/R/state.R index 6a5654184..03c67c38e 100644 --- a/R/state.R +++ b/R/state.R @@ -7,9 +7,14 @@ check_release_state <- function(which) { # mirrors do not seem to work (due to CRAN vacay?) cran_details <- withr::with_options( list(repos = structure(c(CRAN = "https://cloud.r-project.org/"))), - foghorn::cran_details(pkg, src = "website") + tryCatch(foghorn::cran_details(pkg, src = "website"), error = function(e) { + print("Package not yet on CRAN, skipping {foghorn} checks.") + return(NULL) + }) ) - cran_version <- as.character(cran_details[1, "version"]) + if (!is.null(cran_details)) { + cran_version <- as.character(cran_details[1, "version"]) + } cran_inc <- withr::with_options( list(repos = structure(c(CRAN = "https://cloud.r-project.org/"))), {