Skip to content

Commit 8dbb07b

Browse files
committed
feat: fail the build when a GHCR push fails
Previously post_build_processing errors (notably 'One or more GHCR pushes failed') were only warn-logged, so a successful compile with a failed push still exited 0 and CI reported success. Track post-build failure in a dedicated flag and exit non-zero (and set GHA_BUILD_FAILED in CI) so push failures are surfaced. Build/fail counts are left unchanged since the build itself did succeed.
1 parent 86ddef5 commit 8dbb07b

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

sbuild/src/commands/build.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{
33
path::{Path, PathBuf},
44
sync::{
55
self,
6-
atomic::{AtomicUsize, Ordering},
6+
atomic::{AtomicBool, AtomicUsize, Ordering},
77
Arc,
88
},
99
thread,
@@ -127,6 +127,9 @@ pub async fn run(args: BuildArgs, soar_env: Option<SoarEnv>) -> Result<(), Strin
127127
let now = Instant::now();
128128
let success = Arc::new(AtomicUsize::new(0));
129129
let fail = Arc::new(AtomicUsize::new(0));
130+
// A build can succeed while its GHCR push fails; track that separately so
131+
// the build count stays accurate but the process still exits non-zero.
132+
let post_build_failed = Arc::new(AtomicBool::new(false));
130133

131134
let (tx, rx) = sync::mpsc::channel();
132135
let log_manager = LogManager::new(tx.clone());
@@ -228,7 +231,11 @@ pub async fn run(args: BuildArgs, soar_env: Option<SoarEnv>) -> Result<(), Strin
228231
if let Err(e) =
229232
post_build_processing(&build_outdir, &args, recipe_url, pkg_name.as_deref()).await
230233
{
231-
warn!("Post-build processing failed: {}", e);
234+
error!("Post-build processing failed: {}", e);
235+
post_build_failed.store(true, Ordering::SeqCst);
236+
if args.ci {
237+
write_github_env("GHA_BUILD_FAILED", "YES");
238+
}
232239
}
233240
} else {
234241
fail.fetch_add(1, Ordering::SeqCst);
@@ -270,7 +277,15 @@ pub async fn run(args: BuildArgs, soar_env: Option<SoarEnv>) -> Result<(), Strin
270277
write_github_output("fail_count", &fail_count.to_string());
271278
}
272279

273-
if fail_count > 0 {
280+
let push_failed = post_build_failed.load(Ordering::SeqCst);
281+
if push_failed {
282+
println!(
283+
"[{}] Post-build processing (e.g. GHCR push) failed",
284+
"-".bright_red().bold()
285+
);
286+
}
287+
288+
if fail_count > 0 || push_failed {
274289
std::process::exit(1);
275290
}
276291

0 commit comments

Comments
 (0)