Skip to content

Commit

Permalink
Show error message as GHA annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroen committed Nov 29, 2024
1 parent 4ca5297 commit 4273f99
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ COPY entrypoint.sh /entrypoint.sh

RUN installr -d -t "openssl-dev libgit2-dev" -a "openssl libgit2 git" rlang local::/pkg

RUN echo 'options(error=rlang::entrace)' >> "$(R RHOME)/etc/Rprofile.site"
RUN echo 'rlang::global_entrace()' >> "$(R RHOME)/etc/Rprofile.site"

ENTRYPOINT ["sh","/entrypoint.sh"]
18 changes: 11 additions & 7 deletions R/monorepos.R
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ sync_from_registry <- function(monorepo_url = Sys.getenv('MONOREPO_URL')){
}
check_new_release_tags()
skiplist <- submodules_up_to_date(skip_broken = FALSE)
print_message("Submodules up-to-date:\n %s", paste(skiplist, collapse = '\n '))
print_message("Submodules up-to-date:\n %d", length(skiplist))
dirty <- Filter(function(x){is.na(match(x$package, skiplist))}, registry[!registry_dups])
results1 <- lapply(dirty, try_update_package, update_pkg_remotes = TRUE)

Expand Down Expand Up @@ -150,7 +150,9 @@ sync_from_registry <- function(monorepo_url = Sys.getenv('MONOREPO_URL')){

if(length(failures) > 0){
pkgs <- vapply(failures, function(x){
message(sprintf("\nERROR updating %s from %s (%s)\n", x$package, x$url, attr(x, 'error')))
errmsg <- sprintf("ERROR updating %s from %s (%s)", x$package, x$url, attr(x, 'error'))
cat(sprintf("::error file=%s::%s\n", x$package, gsub("\\s+", " ", errmsg)))
#message(errmsg)
x$package
}, character(1))
stop("Failed to update packages: ", paste(pkgs, collapse = ', '))
Expand Down Expand Up @@ -223,15 +225,15 @@ update_one_package <- function(x, update_pkg_remotes = FALSE, cleanup_after = FA
if(submodule$status != 0){
print_message("Adding new package '%s' from: %s", pkg_dir, pkg_url)
branch_args <- if(!identical(pkg_branch, 'HEAD')) c('-b', pkg_branch)
sys::exec_wait("git", c("submodule", "add", branch_args, "--force", pkg_url, pkg_dir))
git_cmd_assert("submodule", "add", branch_args, "--force", pkg_url, pkg_dir)
if(pkg_branch == '*release')
pkg_branch <- update_release_branch(pkg_dir, pkg_url)
gert::git_submodule_set_to(submodule = pkg_dir, ref = pkg_branch)
} else {
submodule_head <- sub("^[+-]", "", sys::as_text(submodule$stdout))
if(pkg_branch == '*release')
pkg_branch <- update_release_branch(pkg_dir, pkg_url)
out <- sys::exec_internal('git', c("ls-remote", pkg_url, pkg_branch))
out <- git_cmd_assert("ls-remote", pkg_url, pkg_branch)
if(length(out$stdout)){
remote_head <- strsplit(sys::as_text(out$stdout), '\\W')[[1]][1]
} else {
Expand All @@ -252,8 +254,8 @@ update_one_package <- function(x, update_pkg_remotes = FALSE, cleanup_after = FA
return()
}
print_message("Updating package '%s' from: %s", pkg_dir, pkg_url)
sys::exec_wait("git", c("update-index", "--cacheinfo", "160000", remote_head, pkg_dir))
sys::exec_wait("git", c("submodule", "update", "--init", "--recommend-shallow", pkg_dir))
git_cmd_assert("update-index", "--cacheinfo", "160000", remote_head, pkg_dir)
git_cmd_assert("submodule", "update", "--init", "--recommend-shallow", pkg_dir)
}
gert::git_add(pkg_dir)
if(!any(gert::git_status()$staged)){
Expand Down Expand Up @@ -517,7 +519,9 @@ get_description_data <- function(pkg_dir){
}

read_description_file <- function(path){
desc <- as.list(tools:::.read_description(path))
desc <- tryCatch(as.list(tools:::.read_description(path)), error = function(err){
stop("Failed to read DESCRIPTION: ", err)
})
names(desc) <- tolower(names(desc))
if(!length(desc[['maintainer']]) || identical(tolower(desc$maintainer), 'orphaned')){
authors <- desc[['authors@r']]
Expand Down
16 changes: 16 additions & 0 deletions R/registry.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,22 @@ git_cmd <- function(..., std_err = TRUE, timeout = 60){
sys::exec_wait('git', args = c(...), std_err = std_err, timeout = timeout)
}

git_cmd_assert <- function(..., timeout = 60){
args <- c(...)
res <- sys::exec_internal('git', args = args, timeout = timeout, error = FALSE)
errtxt <- sys::as_text(res$stderr)
lapply(errtxt, cat, file = stderr(), "\n")
if(!identical(res$status, 0L)){
fatal_error <- grep('fatal', errtxt, value = TRUE)
if(length(fatal_error)){
errtxt <- sub("fatal:", "", fatal_error[1])
} else {
}
stop(sprintf('git %s: %s', args[1], paste(errtxt, collapse = "\n")))
}
return(res)
}

git_clone <- function(url, dest = NULL){
for(i in 1:3){
if(!git_cmd('clone', '--depth', '1', url, dest)){
Expand Down

0 comments on commit 4273f99

Please sign in to comment.