Skip to content

Commit

Permalink
Automatically run checks when deploying
Browse files Browse the repository at this point in the history
  • Loading branch information
notgne2 committed Oct 26, 2020
1 parent 8b3b913 commit 426fb3c
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ struct Opts {
#[clap(short, long)]
result_path: Option<String>,

/// Skip the automatic pre-build checks
#[clap(short, long)]
skip_checks: bool,

/// Override the SSH user with the given value
#[clap(long)]
ssh_user: Option<String>,
Expand Down Expand Up @@ -197,8 +201,42 @@ async fn test_flake_support() -> Result<bool, Box<dyn std::error::Error>> {
.success())
}

async fn check_deployment(supports_flakes: bool, repo: &str, extra_build_args: &[String]) -> () {
let mut c = match supports_flakes {
true => Command::new("nix"),
false => Command::new("nix-build"),
};

let mut check_command = match supports_flakes {
true => {
c.arg("flake")
.arg("check")
.arg(repo)
}
false => {
c.arg("-E")
.arg("--no-out-link")
.arg(format!("let r = import {}/.; in (if builtins.isFunction r then (r {{}}) else r).checks.${{builtins.currentSystem}}", repo))
}
};

for extra_arg in extra_build_args {
check_command = check_command.arg(extra_arg);
}

let check_status = match check_command.status().await {
Ok(x) => x,
Err(err) => good_panic!("Error running checks for the given flake repo: {:?}", err),
};

if !check_status.success() {
good_panic!("Checks failed for the given flake repo");
}

()
}

/// Evaluates the Nix in the given `repo` and return the processed Data from it
#[inline]
async fn get_deployment_data(
supports_flakes: bool,
repo: &str,
Expand Down Expand Up @@ -374,6 +412,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
warn!("A Nix version without flakes support was detected, support for this is work in progress");
}

if !opts.skip_checks {
check_deployment(supports_flakes, deploy_flake.repo, &opts.extra_build_args).await;
}

let data =
get_deployment_data(supports_flakes, deploy_flake.repo, &opts.extra_build_args).await?;

Expand Down

0 comments on commit 426fb3c

Please sign in to comment.