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

Add check_pre_release_state() #40

Closed
wants to merge 19 commits into from
Closed
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
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export(update_news)
export(update_version)
import(glue)
import(cli)
import(glue)
import(rlang)
import(usethis)
importFrom(purrr,discard)
Expand Down
30 changes: 19 additions & 11 deletions R/auto.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,11 @@ pre_release_impl <- function(which, force) {

stopifnot(git2r::is_branch(git2r::repository_head()))

# check PAT scopes for PR for early abort
# check PAT scopes for PR for early abort
check_gh_scopes()

# We expect that this branch is pushed already, ok to fail here
remote_name <- get_remote_name()
main_branch <- get_branch_name()
remote_name <- get_remote_name(main_branch)

# Commit ignored files as early as possible
usethis::use_git_ignore("CRAN-RELEASE")
Expand All @@ -52,28 +51,34 @@ pre_release_impl <- function(which, force) {
# bump version on main branch to version set by user
bump_version(which)

# switch to release branch and update cran-comments
release_branch <- create_release_branch(force)
cli_h2("Preparing CRAN release")

release_branch <- create_release_branch()
switch_branch(release_branch)

update_cran_comments()

# push main branch, bump to devel version and push again
push_to_new(remote_name, force)
cli_h2("Pushing branches and bumping version")

push_to_new(remote_name)
switch_branch(main_branch)
# to trigger a run with the release version
push_head(main_branch)

cli_h1("2. Bumping main branch to dev version and updating NEWS")

# manual implementation of bump_version(), it doesn't expose `force` yet
bump_version_to_dev_with_force(force)
push_head(main_branch)

cli_h1("3. Opening Pull Request for release branch")
cli_h1("3. Opening draft pull request with contents from {.file cran-comments.md}.")
# switch to release branch and init pre_release actions
switch_branch(release_branch)

cli_alert("Opening draft pull request with contents from {.file cran-comments.md}.")
create_pull_request(release_branch, main_branch, remote_name, force)

# user action items
cli_h1("4. User Action Items")

cli_div(theme = list(ul = list(color = "magenta")))
cli_ul("Run {.code devtools::check_win_devel()}.")
cli_ul("Check all items in {.file cran-comments.md}.")
Expand Down Expand Up @@ -150,7 +155,7 @@ update_cran_comments <- function() {
)
)

git2r::add(path = "cran-comments.md")
git2r::add(path = "cran-comments.md", force = TRUE)
git2r::commit(message = "Update CRAN comments")
}

Expand Down Expand Up @@ -227,6 +232,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()
Expand Down
14 changes: 14 additions & 0 deletions R/bump-version.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@ bump_version_impl <- function(which) {
edit_news()
cli_ul("Convert the changelog in {.file {news_path}} to release notes.")
}

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)
}

bump_version_to_dev_with_force <- function(force) {
Expand Down
2 changes: 2 additions & 0 deletions R/finalize-version.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ push_head <- function(head) {
push_to_new <- function(remote_name, force) {
branch_name <- get_branch_name()


cli_alert("Pushing {.field {branch_name}} to remote {.field {remote_name}}.")

git2r::push(
git2r::repository(),
name = remote_name,
Expand Down
41 changes: 41 additions & 0 deletions R/state.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
check_release_state <- function(which) {

# 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/"))),
tryCatch(foghorn::cran_details(pkg, src = "website"), error = function(e) {
print("Package not yet on CRAN, skipping {foghorn} checks.")
return(NULL)
})
)
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/"))),
{
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 {
return("running-release-checks")
}
}
13 changes: 13 additions & 0 deletions R/unleash.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Feature: allow to specify a numeric version in `which`
unleash <- function(which, force = FALSE) {

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
)
}
26 changes: 16 additions & 10 deletions R/update-version.R
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
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()
desc <- update_version_helper(which = which)
new_version = desc$get_version()

cli_h2("Updating 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,
Expand All @@ -26,6 +19,19 @@ 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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also allow the user to specify a version in which, in this case we would call desc$set_version(which) .

Maybe in a new PR?


return(desc)
}

date_in_news_headers <- function() {
headers <- get_news_headers()
if (nrow(headers) == 0) {
Expand Down