Skip to content

Commit 426fb3c

Browse files
committed
Automatically run checks when deploying
1 parent 8b3b913 commit 426fb3c

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

src/main.rs

+43-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ struct Opts {
4040
#[clap(short, long)]
4141
result_path: Option<String>,
4242

43+
/// Skip the automatic pre-build checks
44+
#[clap(short, long)]
45+
skip_checks: bool,
46+
4347
/// Override the SSH user with the given value
4448
#[clap(long)]
4549
ssh_user: Option<String>,
@@ -197,8 +201,42 @@ async fn test_flake_support() -> Result<bool, Box<dyn std::error::Error>> {
197201
.success())
198202
}
199203

204+
async fn check_deployment(supports_flakes: bool, repo: &str, extra_build_args: &[String]) -> () {
205+
let mut c = match supports_flakes {
206+
true => Command::new("nix"),
207+
false => Command::new("nix-build"),
208+
};
209+
210+
let mut check_command = match supports_flakes {
211+
true => {
212+
c.arg("flake")
213+
.arg("check")
214+
.arg(repo)
215+
}
216+
false => {
217+
c.arg("-E")
218+
.arg("--no-out-link")
219+
.arg(format!("let r = import {}/.; in (if builtins.isFunction r then (r {{}}) else r).checks.${{builtins.currentSystem}}", repo))
220+
}
221+
};
222+
223+
for extra_arg in extra_build_args {
224+
check_command = check_command.arg(extra_arg);
225+
}
226+
227+
let check_status = match check_command.status().await {
228+
Ok(x) => x,
229+
Err(err) => good_panic!("Error running checks for the given flake repo: {:?}", err),
230+
};
231+
232+
if !check_status.success() {
233+
good_panic!("Checks failed for the given flake repo");
234+
}
235+
236+
()
237+
}
238+
200239
/// Evaluates the Nix in the given `repo` and return the processed Data from it
201-
#[inline]
202240
async fn get_deployment_data(
203241
supports_flakes: bool,
204242
repo: &str,
@@ -374,6 +412,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
374412
warn!("A Nix version without flakes support was detected, support for this is work in progress");
375413
}
376414

415+
if !opts.skip_checks {
416+
check_deployment(supports_flakes, deploy_flake.repo, &opts.extra_build_args).await;
417+
}
418+
377419
let data =
378420
get_deployment_data(supports_flakes, deploy_flake.repo, &opts.extra_build_args).await?;
379421

0 commit comments

Comments
 (0)