add upload function
This commit is contained in:
parent
d983f391fb
commit
2aed996280
1 changed files with 119 additions and 46 deletions
61
R/upload.R
Normal file
61
R/upload.R
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
#' @importFrom paws.storage s3
|
||||
upload_single_binary_to_s3 <- function(
|
||||
endpoint = "https://s3.eu-central-003.backblazeb2.com",
|
||||
region = "eu-central-003",
|
||||
local_build_root = "/root", codename = NULL,
|
||||
package_name, tag,
|
||||
r_version_minor = NULL, build_for_minor = TRUE,
|
||||
force = FALSE,
|
||||
debug = FALSE) {
|
||||
|
||||
codename <- set_codename(codename)
|
||||
|
||||
if (is.null(r_version_minor)) {
|
||||
r_version_minor <- sub("R version (\\d+\\.\\d+).*", "\\1", R.Version()$version.string)
|
||||
}
|
||||
|
||||
# create directory structure
|
||||
if (is.null(r_version_minor) && !build_for_minor) {
|
||||
dir_out_bin <- sprintf(
|
||||
"%s/__linux__/%s/latest/src/contrib",
|
||||
local_build_root, codename
|
||||
)
|
||||
} else {
|
||||
dir_out_bin <- sprintf(
|
||||
"%s/__linux__/%s/%s/latest/src/contrib",
|
||||
local_build_root, codename, r_version_minor
|
||||
)
|
||||
}
|
||||
|
||||
if (debug) {
|
||||
cli::cli_alert_danger("DEBUG: dir_out_bin: {dir_out_bin}, codename: {codename}")
|
||||
cli::cli_alert_danger("DEBUG: Body: {sprintf('%s/%s', dir_out_bin, tarball_name)}")
|
||||
}
|
||||
|
||||
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 = "https://s3.eu-central-003.backblazeb2.com",
|
||||
region_name = "eu-central-003",
|
||||
)
|
||||
|
||||
tarball_name <- sprintf("%s_%s.tar.gz", package_name, tag)
|
||||
exists <- s3fs::s3_file_exists(sprintf("devxy-arm64-r-binaries/__linux__/%s/%s/latest/src/contrib/%s", codename, r_version_minor, tarball_name))
|
||||
|
||||
if (!exists && !force) {
|
||||
cli::cli_alert_info("{.fun build_single_tag}: 5. Uploading {.pkg {package_name}} {.strong {tag}} to S3.")
|
||||
s3fs::s3_file_upload(
|
||||
sprintf("%s/%s", dir_out_bin, tarball_name),
|
||||
sprintf("devxy-arm64-r-binaries/__linux__/%s/%s/latest/src/contrib/%s", codename, r_version_minor, tarball_name)
|
||||
)
|
||||
} else if (exists && force) {
|
||||
cli::cli_alert_info("{.fun upload_to_s3}: Force uploading package {.pkg {package_name}} {.path {tag}} because force = TRUE was set.")
|
||||
s3fs::s3_file_upload(
|
||||
sprintf("%s/%s", dir_out_bin, tarball_name),
|
||||
sprintf("devxy-arm64-r-binaries/__linux__/%s/%s/latest/src/contrib/%s", codename, r_version_minor, tarball_name),
|
||||
overwrite = TRUE
|
||||
)
|
||||
} else if (exists && !force) {
|
||||
cli::cli_alert_info("{.fun upload_to_s3}: Package {.pkg {package_name}} {.path {tag}} already exists in S3. Skipping upload.")
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue