fix metadata overwrite logic

This commit is contained in:
Patrick Schratz 2024-07-31 13:07:04 +02:00
commit 14cf69331d
Signed by: pat-s
GPG key ID: 3C6318841EF78925
2 changed files with 23 additions and 32 deletions

View file

@ -93,12 +93,11 @@ build_binary_package <- function(package_name, tag = NULL, codename = NULL,
tryCatch(
{
p()
dump <- build_single_tag(x, y, dir_out_bin, local_clone_dir, platform = platform, debug = debug)
dump <- build_single_tag(x, y, dir_out_bin, local_clone_dir, platform = platform, debug = debug, force = force)
# if for some reason an underlying error didnt' get caught in the tryCatch calls, we check again here for the existence of the binary file on disk and mark the build as failed if it is not found
tarball_name <- sprintf("%s_%s.tar.gz", x, y)
if (fs::file_exists(sprintf("%s/%s", local_bin_path, tarball_name))) {
store_build_metadata(x, y, platform, error_occurred = FALSE, force = force)
cli::cli_alert_success("Successfully built package {.pkg {x}} with tag {.field {y}}.")
} else {
cli::cli_alert_warning("Error in building package {.pkg {x}} with tag {.field {y}}: Uncommon/unspecific error during build.")
@ -147,7 +146,8 @@ build_single_tag <- function(
platform,
dir_out_bin,
local_clone_dir,
debug = FALSE) {
debug = FALSE,
force = FALSE) {
cli::cli_alert("{.fun build_single_tag}: (1/3) Cloning package {.pkg {package_name}} with tag {.field {tag}}.")
local_clone_dir_single <- sprintf("%s/%s_%s", local_clone_dir, package_name, tag)
@ -213,19 +213,9 @@ build_single_tag <- function(
cli::cli_alert_warning("DEBUG: file_size: {file_size}")
}
# skip DB connection if package already exists
if (file.exists(sprintf("%s/%s_%s.tar.gz", dir_out_bin, package_name, tag))) {
con <- DBI::dbConnect(RPostgres::Postgres(),
dbname = "build_metadata", host = "postgres-arm-binaries-r.devxy.io",
port = 15432, user = "arm_binaries", password = Sys.getenv("PGPASS")
)
dbExecute(con,
"UPDATE single_builds SET build_duration = $1, size = $2 WHERE package_name = $3 and platform = $4 and tag = $5",
params = list(
total_build_time, file_size, package_name, platform, tag
)
)
dbDisconnect(con)
tarball_name <- sprintf("%s_%s.tar.gz", package_name, tag)
if (fs::file_exists(sprintf("%s/%s", dir_out_bin, tarball_name))) {
store_build_metadata(package_name, tag, platform, error_occurred = FALSE, force = force, build_duration = total_build_time, size = file_size)
}
}

View file

@ -2,7 +2,7 @@
#' @importFrom DBI dbConnect dbDisconnect dbWriteTable dbGetQuery dbExecute
store_build_metadata <- function(
package_name, tag, platform, error_occurred,
force = FALSE, error = NA) {
force = FALSE, error = NA, build_duration = NA, size = NA) {
con <- DBI::dbConnect(RPostgres::Postgres(),
dbname = "build_metadata", host = "postgres-arm-binaries-r.devxy.io",
port = 15432, user = "arm_binaries", password = Sys.getenv("PGPASS")
@ -19,8 +19,8 @@ store_build_metadata <- function(
} else if (nrow(existing_entries) >= 1 && force) {
cli::cli_alert_info("{.fun store_build_metadata}: Force overwriting build metadata for {.pkg {package_name}} {.field {tag}} because {.code force = TRUE} was set.")
DBI::dbExecute(con, "UPDATE single_builds SET build_timestamp = $1, error_occurred = $2, error = $3, WHERE package_name = $5 and tag = $6 and platform = $7",
params = list(format(Sys.time(), "%Y-%m-%d %H:%M:%S"), error_occurred, error, package_name, tag, platform)
DBI::dbExecute(con, "UPDATE single_builds SET build_timestamp = $1, error_occurred = $2, error = $3, build_duration = $4, size = $5 WHERE package_name = $6 and tag = $7 and platform = $8",
params = list(format(Sys.time(), "%Y-%m-%d %H:%M:%S"), error_occurred, error, build_duration, size, package_name, tag, platform)
)
} else if (nrow(existing_entries) == 0) {
cli::cli_alert("{.fun store_build_metadata}: Storing build metadata for {.pkg {package_name}} {.field {tag}}.")
@ -32,7 +32,8 @@ store_build_metadata <- function(
error_occurred = error_occurred,
error = error,
build_timestamp = format(Sys.time(), "%Y-%m-%d %H:%M:%S"),
build_duration = NA
build_duration = build_duration,
size = size
)
# Write the data frame to the SQLite database
dbWriteTable(con, "single_builds", metadata, append = TRUE)