Created
January 23, 2024 07:14
-
-
Save amoeba/2b0596fc513669167efed059ed6e1bae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Get a list of git tags | |
#' | |
#' @param pattern | |
#' | |
#' @return | |
#' | |
#' @examples | |
get_tags <- function(pattern=NULL) { | |
all_tags <- system2("git", c("tag", "--sort=taggerdate"), stdout = TRUE) | |
if (is.null(pattern)) { | |
return(all_tags) | |
} | |
all_tags[grepl(tag_pattern, all_tags, perl = TRUE)] | |
} | |
#' Get the latest release within a major series | |
#' | |
#' @param tags | |
#' @param major | |
#' @param tag_prefix | |
#' | |
#' @return | |
#' | |
#' @examples | |
latest_release_for_major <- function(tags, major, tag_prefix) { | |
releases_in_major <- tags[grep(paste0(tag_prefix, major), tags)] | |
sub(tag_prefix, "", releases_in_major[length(releases_in_major)]) | |
} | |
#' Get the major version from a git tag | |
#' | |
#' @param tag | |
#' @param tag_prefix | |
#' | |
#' @return | |
#' | |
#' @examples | |
major_from_tag <- function(tag, tag_prefix) { | |
tag_version <- package_version(sub(tag_prefix, "", tag)) | |
tag_version$major | |
} | |
#' Get the latest release in one or more major release series | |
#' | |
#' @param n | |
#' @param tag_prefix | |
#' @param tag_pattern | |
#' | |
#' @return | |
#' | |
#' @examples | |
last_n_releases_for_majors <- function(n, | |
tag_prefix="apache-arrow-", | |
tag_pattern="apache-arrow-[\\d\\.]+$") { | |
tags <- get_tags(tag_pattern) | |
latest_tag <- tags[length(tags)] | |
latest_major <- major_from_tag(latest_tag, tag_prefix) | |
target_majors <- rev(latest_major - 0:2) | |
vapply( | |
target_majors, | |
function(major) { | |
latest_release_for_major(tags, major, tag_prefix) | |
}, | |
"" | |
) | |
} | |
last_n_releases_for_majors(3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment