diff --git a/NAMESPACE b/NAMESPACE index 350fd4b..d1dc7aa 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,6 +1,7 @@ # Generated by roxygen2: do not edit by hand export(add_to_package_index) +export(archive_package) export(build_binary_package) export(build_single_tag) export(dbcon) diff --git a/R/archive_packages.R b/R/archive_packages.R new file mode 100644 index 0000000..0de4f2b --- /dev/null +++ b/R/archive_packages.R @@ -0,0 +1,64 @@ +#' Archive packages in CRAN-like repositories +#' @export +#' @examples +#' archive_package("AATtools", codename = "rhel9") +#' +archive_package <- function( + package_name, + 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") { + 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) + 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) + + foo <- lapply(package_name, function(.x) { + if (!s3fs::s3_dir_exists(sprintf("%s/Archive/%s", remote_bin_dir, .x))) { + s3fs::s3_dir_create(sprintf("%s/Archive/%s", remote_bin_dir, .x)) + } + all_versions <- grep(sprintf("/%s_", .x), files, value = TRUE) + # only archive if more than one package exists in the root + if (length(all_versions) > 1) { + # get most recent version from CRAN + last_version <- available.packages()[.x, "Version"] + # check if last version is available in repo + if (any(grepl(last_version, all_versions))) { + index <- which(grepl(last_version, all_versions)) + old_versions <- all_versions[-index] + } else { + versions = rev(pak::pkg_history(.x)$Version) + for (i in versions) { + if (any(grepl(i, all_versions))) { + index <- which(grepl(i, all_versions)) + old_versions <- all_versions[-index] + break + } + } + } + cli::cli_alert("{.fun archive_package}: Archiving {.field {basename(old_versions)}}, keeping {.field {basename(all_versions[index])}}.") + s3fs::s3_file_move(old_versions, sprintf("%s/Archive/%s/%s", remote_bin_dir, .x, basename(old_versions)), overwrite = TRUE) + cli::cli_alert_success("{.fun archive_package}: Successfully archived package {.pkg {.x}}.") + } + cli::cli_alert("{.fun archive_package}: Skipping {.pkg {.x}} as only one package versions exists.") + }) + + return(invisible(TRUE)) +} diff --git a/R/helpers.R b/R/helpers.R index ae791a7..97a4464 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -29,6 +29,8 @@ set_codename <- function(codename) { } } return(codename) + } else { + return(codename) } } diff --git a/R/process_cran_updates.R b/R/process_cran_updates.R index 8e57b7e..c13ad00 100644 --- a/R/process_cran_updates.R +++ b/R/process_cran_updates.R @@ -31,7 +31,11 @@ process_cran_updates <- function( all_pkgs <- dplyr::bind_rows(updated_pkgs, new_pkgs) - purrr::walk2(all_pkgs$name, all_pkgs$version, ~ build_binary_package(.x, .y, platform = platform)) + purrr::walk2(all_pkgs$name, all_pkgs$version, ~ { + build_binary_package(.x, .y, platform = platform) + archive_package(.x) + } + ) if (prune) { removed_pkgs <- get_removed_cran_packages(interval) @@ -57,7 +61,7 @@ process_cran_updates <- function( purrr::walk(removed_pkgs$name, ~ { cli::cli_alert("{.fun process_cran_updates}: Removing package {.pkg {.x}} from S3.") - files_filtered <- grep(sprintf("%s_", .x), files, value = TRUE) + 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.") diff --git a/man/archive_package.Rd b/man/archive_package.Rd new file mode 100644 index 0000000..a38cca6 --- /dev/null +++ b/man/archive_package.Rd @@ -0,0 +1,24 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/archive_packages.R +\name{archive_package} +\alias{archive_package} +\title{Archive packages in CRAN-like repositories} +\usage{ +archive_package( + package_name, + 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" +) +} +\description{ +Archive packages in CRAN-like repositories +} +\examples{ +archive_package("AATtools", codename = "rhel9") + +} diff --git a/man/build_binary_package.Rd b/man/build_binary_package.Rd index 953cd5c..7d62971 100644 --- a/man/build_binary_package.Rd +++ b/man/build_binary_package.Rd @@ -9,7 +9,7 @@ build_binary_package( tag = NULL, codename = NULL, r_minor_version = NULL, - build_for_minor = TRUE, + build_for_minor = FALSE, local_build_root = "/root", local_clone_dir = "/tmp", platform = NULL, diff --git a/man/process_cran_updates.Rd b/man/process_cran_updates.Rd index 41f8547..d6e4f02 100644 --- a/man/process_cran_updates.Rd +++ b/man/process_cran_updates.Rd @@ -7,7 +7,7 @@ process_cran_updates( package_name, tag, - platform = platform, + platform, local_clone_dir, interval = lubridate::today(), prune = TRUE,