build-cran-binaries/R/process_cran_updates.R

90 lines
3.2 KiB
R

#' @title Process updated and new CRAN packages
#' @description
#' Packages which got removed from CRAN can be deleted by setting `prune = TRUE`.
#' Argument `interval` allows to specify a range which should be processed.
#'
#' @importFrom dplyr bind_rows
#' @importFrom purrr walk2
#' @examples
#' process_cran_updates(
#' interval = lubridate::interval(lubridate::today() - 2, lubridate::today() - 20),
#' process_updated = FALSE, process_new = FALSE
#' )
#'
#' @export
process_cran_updates <- function(
package_name,
tag,
platform,
local_clone_dir,
interval = lubridate::today(),
build_for_minor = FALSE,
codename = NULL,
r_minor_version = NULL,
local_build_root = ".",
endpoint = "https://s3.eu-central-003.backblazeb2.com",
region = "eu-central-003",
bucket = "devxy-arm64-r-binaries",
process_updated = TRUE,
process_new = TRUE,
process_removed = TRUE) {
# Get list of updated and new packages for a specific day
updated_pkgs <- get_updated_cran_packages(interval)
new_pkgs <- get_new_cran_packages(interval)
all_pkgs <- dplyr::bind_rows(updated_pkgs, new_pkgs)
if (any(c(process_updated, process_new))) {
cli::cli_alert_success("{.fun process_cran_updates}: Updated packages:")
print(updated_pkgs)
cli::cli_alert_success("{.fun process_cran_updates}: New packages:")
print(new_pkgs)
purrr::walk2(all_pkgs$name, all_pkgs$version, ~ {
build_binary_package(.x, .y, platform = platform)
archive_package(.x)
})
}
if (process_removed) {
removed_pkgs <- get_removed_cran_packages(interval)
cli::cli_alert_success("{.fun process_cran_updates}: Removed packages:")
print(removed_pkgs)
s3fs::s3_file_system(
aws_access_key_id = Sys.getenv("AWS_ACCESS_KEY_ID"),
aws_secret_access_key = Sys.getenv("AWS_SECRET_ACCESS_KEY"),
endpoint = endpoint,
region_name = region,
)
codename <- set_codename(codename)
local_arch = Sys.info()[["machine"]]
if (grepl("arm64", local_arch) || grepl("aarch64", local_arch)) {
arch <- "arm64"
} else if (grepl("amd64", local_arch) || grepl("x86_64", local_arch)) {
arch <- "amd64"
}
if (!build_for_minor) {
local_bin_dir <- set_bin_path(r_minor_version, build_for_minor, local_build_root, codename)
remote_bin_dir <- sprintf("%s/%s/%s/latest/src/contrib", bucket, arch, codename)
} else {
dir_out_bin <- set_bin_path(r_minor_version, build_for_minor, local_build_root, codename)
remote_bin_dir <- sprintf("%s/%s/%s/%s/latest/src/contrib", bucket, arch, codename, r_minor_version)
}
files <- s3fs::s3_dir_ls(remote_bin_dir)
foo <- lapply(removed_pkgs$name, function(.x) {
cli::cli_alert("{.fun process_cran_updates}: Removing package {.pkg {.x}} from S3.")
files_filtered <- grep(sprintf("/%s_", .x), files, value = TRUE)
if (length(files_filtered) > 0) {
s3fs::s3_file_delete(files_filtered)
cli::cli_alert_success("{.fun process_cran_updates}: Successfully removed {.pkg {basename(files_filtered)}} from S3.")
} else {
cli::cli_alert("{.fun process_cran_updates}: No tarballs found for package {.pkg {.x}} - already removed?")
}
})
}
}