build-cran-binaries/R/update-packages.R
2024-08-26 17:02:19 +02:00

59 lines
2.1 KiB
R

#' 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
#' @export
update_packages <- function(
package_name,
tag,
platform = platform,
local_clone_dir,
interval = lubridate::today(),
prune = TRUE,
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") {
# Get list of updated and new packages for a specific day
updated_pkgs <- get_updated_cran_packages()
new_pkgs <- get_new_cran_packages()
all_pkgs <- dplyr::bind_rows(updated_pkgs, new_pkgs)
purrr::walk2(all_pkgs$name, all_pkgs$version, ~ build_binary_package(.x, .y))
if (prune) {
removed_pkgs <- get_removed_cran_packages(interval)
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,
)
if (!build_for_minor) {
local_bin_dir <- sprintf("%s/arm64/%s/latest/src/contrib", local_build_root, codename)
remote_bin_dir <- sprintf("%s/arm64/%s/latest/src/contrib", bucket, codename)
} else {
dir_out_bin <- sprintf("%s/arm64/%s/%s/latest/src/contrib", local_build_root, codename, r_minor_version)
remote_bin_dir <- sprintf("%s/arm64/%s/%s/latest/src/contrib", bucket, codename, r_minor_version)
}
files <- s3fs::s3_dir_ls(remote_bin_dir)
purrr::walk(removed_pkgs$name, ~ {
cli::cli_alert("{.fun update_packages}: Removing package {.pkg {.x}} from S3.")
files_filtered <- grep("bold_", files, value = TRUE)
s3fs::s3_file_delete_async(files_filtered)
cli::cli_alert_success("{.fun update_packages}: Successfully removed {.pkg {basename(files_filtered)}} from S3.")
})
}
}