Skip to content

Commit

Permalink
feat: Release package as soon as it's available on PPM
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr committed Oct 27, 2023
1 parent f251284 commit 157ee3d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 64 deletions.
76 changes: 15 additions & 61 deletions R/auto.R
Original file line number Diff line number Diff line change
Expand Up @@ -707,82 +707,36 @@ create_pull_request <- function(release_branch, main_branch, remote_name, force)
usethis::pr_view()
}

# FIXME: Align with new-style release
release_after_cran_built_binaries <- function() {
# look for PR branch
remote <- "origin"
github_info <- github_info(remote)

prs <- gh(
"GET /repos/:owner/:repo/pulls",
owner = github_info[["owner"]][["login"]],
repo = github_info[["name"]],
.limit = Inf
)
cran_pr <- purrr::keep(
prs,
~ any(grepl("^cran release", tolower(purrr::map_chr(.x[["labels"]], "name"))))
)

if (length(cran_pr) == 0) {
if (fledge_chatty()) {
cli::cli_alert_info("Can't find a 'CRAN release'-labelled PR")
}
return(invisible(FALSE))
}

if (length(cran_pr) > 1) {
if (fledge_chatty()) {
cli::cli_abort("Found {length(cran_pr)} 'CRAN release'-labelled PRs")
}
}

cran_pr <- cran_pr[[1]]
gert::git_branch_checkout(cran_pr[["head"]][["ref"]])

# get info from CRAN page ----

pkg <- read_package()

temp_file <- withr::local_tempfile()

curl::curl_download(
sprintf("https://cran.r-project.org/package=%s", pkg),
temp_file
last_release_tag <- get_last_tag_impl(
pattern = "^v[0-9]+[.][0-9]+[.][0-9]+(?:[.-][0-9]{1,3})?$"
)

pkg_cran_page <- xml2::read_html(temp_file)
pkg_version <- extract_version_pr(cran_pr[["title"]])
last_release_version <- as.package_version(gsub("^v", "", last_release_tag$name))

# treat binaries link
tibblify_binary_link <- function(link) {
rematch2::re_match(
link,
"/bin/(?<flavor>.+)/contrib/(?<r_version>[^/]+)/[^_]+_(?<binary_version>[-0-9.]+)[.][a-z]+$"
)
}
ppm_packages <- utils::available.packages(repos = "https://packagemanager.posit.co/cran/latest")

# binaries
binaries <- xml2::xml_find_all(
pkg_cran_page,
".//a[starts-with(@href, '../../../bin/')]"
) %>%
xml2::xml_attr("href") %>%
map_dfr(tibblify_binary_link)

# put it together
binaries[["up_to_date"]] <- (binaries[["binary_version"]] == pkg_version)
if (!(pkg %in% rownames(ppm_packages))) {
if (fledge_chatty()) {
cli_alert_info("Package not found on PPM.")
}
return(invisible())
}

all_ok <- all(binaries[["up_to_date"]])
ppm_version <- ppm_packages[pkg, "Version"]

if (all_ok) {
if (ppm_version == last_release_version) {
if (fledge_chatty()) {
cli_alert_info("All binaries match the most recent version, releasing.")
cli_alert_info("PPM version matches the most recent version, releasing.")
}
post_release()
return(invisible(TRUE))
} else {
if (fledge_chatty()) {
cli_alert_info("Some binaries don't match the most recent version.")
cli_alert_info("PPM version {.val {ppm_version}} don't match the most recent version {.val {last_release_version}}.")
}
return(invisible(FALSE))
}
Expand Down
13 changes: 10 additions & 3 deletions R/commits.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ get_parent_since <- function(all_parents, since) {
purrr::detect(all_parents, ~ gert::git_ahead_behind(since, .x)$behind == 0)
}

get_last_tag_impl <- function(ref = "HEAD") {
get_last_tag_impl <- function(ref = "HEAD", pattern = NULL) {
repo_head <- gert::git_log(ref, max = 1)

all_tags <- gert::git_tag_list()
Expand All @@ -60,8 +60,15 @@ get_last_tag_impl <- function(ref = "HEAD") {
return(NULL)
}

tags_ab <- map(all_tags$name, ~ gert::git_ahead_behind(upstream = repo_head$commit, ref = .x))
names(tags_ab) <- all_tags$name
tag_names <- all_tags$name
if (!is.null(pattern)) {
tag_names <- grep(pattern, tag_names, value = TRUE, perl = TRUE)
}

tags_ab <- map(
set_names(tag_names),
~ gert::git_ahead_behind(upstream = repo_head$commit, ref = .x)
)
tags_only_b <- discard(tags_ab, ~ .[[1]] > 0)
tags_b <- map_int(tags_only_b, 2)
names(tags_b) <- names(tags_only_b)
Expand Down

0 comments on commit 157ee3d

Please sign in to comment.