From 22ae18f5e7577113cc789f371da3820d68d59869 Mon Sep 17 00:00:00 2001 From: Zhaofeng Li Date: Mon, 24 May 2021 00:15:38 -0700 Subject: [PATCH] Exit with non-zero code if any node fails to deploy The exit codes are in flux and should not be relied upon. Fixes #28. --- src/command/apply.rs | 10 +++++++--- src/command/apply_local.rs | 6 +++++- src/nix/deployment.rs | 13 +++++++++++-- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/command/apply.rs b/src/command/apply.rs index 29d631e..6aadda5 100644 --- a/src/command/apply.rs +++ b/src/command/apply.rs @@ -233,9 +233,13 @@ pub async fn run(_global_args: &ArgMatches<'_>, local_args: &ArgMatches<'_>) { let deployment = Arc::new(deployment); - if goal_arg == "keys" { - deployment.upload_keys().await; + let success = if goal_arg == "keys" { + deployment.upload_keys().await } else { - deployment.execute().await; + deployment.execute().await + }; + + if !success { + quit::with_code(10); } } diff --git a/src/command/apply_local.rs b/src/command/apply_local.rs index dc1d18d..d7a3af0 100644 --- a/src/command/apply_local.rs +++ b/src/command/apply_local.rs @@ -126,7 +126,11 @@ pub async fn run(_global_args: &ArgMatches<'_>, local_args: &ArgMatches<'_>) { deployment.set_options(options); let deployment = Arc::new(deployment); - deployment.execute().await; + let success = deployment.execute().await; + + if !success { + quit::with_code(10); + } } async fn escalate(sudo: &str) -> ! { diff --git a/src/nix/deployment.rs b/src/nix/deployment.rs index aed4b2d..1e5b38a 100644 --- a/src/nix/deployment.rs +++ b/src/nix/deployment.rs @@ -255,7 +255,7 @@ impl Deployment { } /// Uploads keys only (user-facing) - pub async fn upload_keys(self: Arc) { + pub async fn upload_keys(self: Arc) -> bool { let progress = { let mut progress = Progress::default(); progress.set_label_width(self.label_width); @@ -306,12 +306,14 @@ impl Deployment { } arc_self.print_logs().await; + + arc_self.all_successful().await } /// Executes the deployment (user-facing) /// /// Self must be wrapped inside an Arc. - pub async fn execute(self: Arc) { + pub async fn execute(self: Arc) -> bool { let progress = { let mut progress = if !self.options.progress_bar { Progress::with_style(OutputStyle::Plain) @@ -429,6 +431,13 @@ impl Deployment { } arc_self.print_logs().await; + + arc_self.all_successful().await + } + + async fn all_successful(&self) -> bool { + let results = self.results.lock().await; + results.iter().filter(|r| !r.is_successful()).count() == 0 } async fn print_logs(&self) {