The weekly audit matched the existing "### <arch>" issue subsection by its
bare header ("### arm64") while writing headers with a
" (N missing, M to rebuild)" suffix. The equality test never matched, so every
run appended a fresh block instead of replacing the old one. Issue bodies
accumulated dozens of stale subsections (alpine-323 had 38 where 2 are
expected), and fetch-rebuild-packages-from-issue.R read the *first* block,
feeding the rebuild a months-old list while the genuinely-missing packages were
never rebuilt.
- Match arch subsections by prefix and drop all blocks for the arch before
writing one fresh block, so accumulation self-heals each run.
- Add local/dedupe-audit-issue.R to collapse the already-accumulated
duplicates in the existing issues (keeps the freshest block per arch).
- Make fetch-rebuild-packages-from-issue.R prefer the audit's freshly-written
RDS, falling back to issue parsing when it is absent.
140 lines
3.8 KiB
R
140 lines
3.8 KiB
R
library(httr2, quietly = TRUE)
|
|
|
|
forgejo_base <- "https://git.devxy.io/api/v1"
|
|
repo <- "devxy/build-cran-binaries"
|
|
platform <- Sys.getenv("PLATFORM")
|
|
arch <- Sys.getenv("ARCH")
|
|
output_file <- Sys.getenv("REBUILD_PKG_LIST", "/tmp/rebuild_pkgs.txt")
|
|
|
|
if (nchar(platform) == 0) {
|
|
stop("PLATFORM env var is not set")
|
|
}
|
|
if (nchar(arch) == 0) {
|
|
stop("ARCH env var is not set")
|
|
}
|
|
|
|
# Prefer the audit's freshly-written RDS. The audit overwrites it each run
|
|
# (saveRDS), so unlike the Forgejo issue body it is never subject to the
|
|
# duplicate-subsection accumulation bug. Fall back to parsing the issue when the
|
|
# RDS is absent (e.g. a fresh runner with no shared cache).
|
|
rds_file <- file.path(
|
|
Sys.getenv("REBUILD_PKG_RDS_DIR", "/mnt/cache/packages"),
|
|
sprintf("weekly_rebuild_%s_%s.rds", platform, arch)
|
|
)
|
|
if (file.exists(rds_file)) {
|
|
pkgs <- tryCatch(as.character(readRDS(rds_file)), error = function(e) NULL)
|
|
if (!is.null(pkgs) && length(pkgs) > 0) {
|
|
cat(sprintf(
|
|
"Using audit RDS %s: %d rebuildable packages for %s/%s\n",
|
|
rds_file,
|
|
length(pkgs),
|
|
platform,
|
|
arch
|
|
))
|
|
writeLines(pkgs, output_file)
|
|
cat(sprintf("Wrote package list to %s\n", output_file))
|
|
q("no")
|
|
}
|
|
cat(sprintf(
|
|
"RDS %s present but empty/unreadable -- falling back to issue\n",
|
|
rds_file
|
|
))
|
|
}
|
|
|
|
token <- Sys.getenv("FORGEJO_TOKEN")
|
|
if (nchar(token) == 0) {
|
|
stop("FORGEJO_TOKEN env var is not set")
|
|
}
|
|
|
|
os_family <- if (grepl("^ubuntu", platform)) {
|
|
"Ubuntu"
|
|
} else if (grepl("^alpine", platform)) {
|
|
"Alpine"
|
|
} else if (grepl("^redhat", platform)) {
|
|
"Red Hat"
|
|
} else {
|
|
platform
|
|
}
|
|
|
|
issue_title <- sprintf(
|
|
"Missing package binaries for latest version (%s)",
|
|
os_family
|
|
)
|
|
cat(sprintf("Searching for issue: %s\n", issue_title))
|
|
|
|
search_url <- sprintf(
|
|
"%s/repos/%s/issues?type=issues&state=open&q=%s&limit=50",
|
|
forgejo_base,
|
|
repo,
|
|
utils::URLencode(issue_title, reserved = TRUE)
|
|
)
|
|
search_resp <- request(search_url) |>
|
|
req_headers(Authorization = paste("token", token)) |>
|
|
req_perform()
|
|
|
|
issues <- resp_body_json(search_resp, simplifyVector = FALSE)
|
|
match_idx <- which(
|
|
vapply(issues, function(x) x$title, character(1)) == issue_title
|
|
)
|
|
|
|
if (length(match_idx) == 0) {
|
|
cat("No matching issue found - nothing to rebuild\n")
|
|
writeLines(character(0), output_file)
|
|
q("no")
|
|
}
|
|
|
|
body <- issues[[match_idx[1]]]$body
|
|
if (is.null(body) || nchar(body) == 0) {
|
|
cat("Issue body is empty - nothing to rebuild\n")
|
|
writeLines(character(0), output_file)
|
|
q("no")
|
|
}
|
|
|
|
lines <- strsplit(body, "\n", fixed = TRUE)[[1]]
|
|
|
|
# Find the platform section (## alpine-322)
|
|
plat_header <- sprintf("## %s", platform)
|
|
plat_idx <- which(lines == plat_header)
|
|
if (length(plat_idx) == 0) {
|
|
cat(sprintf(
|
|
"No section found for platform %s - nothing to rebuild\n",
|
|
platform
|
|
))
|
|
writeLines(character(0), output_file)
|
|
q("no")
|
|
}
|
|
|
|
# Find the arch subsection (### arm64 (...))
|
|
arch_pattern <- sprintf("^### %s ", arch)
|
|
arch_idx <- which(grepl(arch_pattern, lines) & seq_along(lines) > plat_idx[1])
|
|
if (length(arch_idx) == 0) {
|
|
cat(sprintf(
|
|
"No section found for arch %s under %s - nothing to rebuild\n",
|
|
arch,
|
|
platform
|
|
))
|
|
writeLines(character(0), output_file)
|
|
q("no")
|
|
}
|
|
|
|
ai <- arch_idx[1]
|
|
|
|
# Find the end of the rebuildable section: stop at ####, ###, ##, ---, or EOF
|
|
end_idx <- which(grepl("^####|^###|^##|^---", lines) & seq_along(lines) > ai)
|
|
end_idx <- if (length(end_idx) > 0) end_idx[1] - 1 else length(lines)
|
|
|
|
section_lines <- lines[seq(ai + 1, end_idx)]
|
|
|
|
# Extract package names from "- PackageName (Version)" lines
|
|
pkg_lines <- section_lines[grepl("^- ", section_lines)]
|
|
pkgs <- sub("^- ([^ ]+) \\(.*\\)$", "\\1", pkg_lines)
|
|
pkgs <- pkgs[nchar(pkgs) > 0 & pkgs != "_None_"]
|
|
|
|
cat(sprintf(
|
|
"Found %d rebuildable packages for %s/%s\n",
|
|
length(pkgs),
|
|
platform,
|
|
arch
|
|
))
|
|
writeLines(pkgs, output_file)
|
|
cat(sprintf("Wrote package list to %s\n", output_file))
|