-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8ccfe22
commit e95f9d6
Showing
7 changed files
with
209 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
use bundle::RunResult; | ||
use clap::Args; | ||
use codeowners::CodeOwners; | ||
use constants::EXIT_FAILURE; | ||
use context::repo::BundleRepo; | ||
|
||
use crate::{ | ||
api_client::ApiClient, | ||
runner::{run_quarantine, run_test_command, JunitSpec}, | ||
upload::{run_upload, UploadArgs}, | ||
}; | ||
|
||
#[derive(Args, Clone, Debug)] | ||
pub struct TestArgs { | ||
#[command(flatten)] | ||
upload_args: UploadArgs, | ||
#[arg( | ||
required = true, | ||
allow_hyphen_values = true, | ||
trailing_var_arg = true, | ||
help = "Test command to invoke." | ||
)] | ||
command: Vec<String>, | ||
} | ||
|
||
pub async fn run_test(test_args: TestArgs) -> anyhow::Result<i32> { | ||
let TestArgs { | ||
command, | ||
upload_args, | ||
} = test_args; | ||
let UploadArgs { | ||
junit_paths, | ||
bazel_bep_path, | ||
org_url_slug, | ||
token, | ||
repo_root, | ||
repo_url, | ||
repo_head_sha, | ||
repo_head_branch, | ||
repo_head_commit_epoch, | ||
use_quarantining, | ||
team, | ||
codeowners_path, | ||
.. | ||
} = &upload_args; | ||
|
||
let repo = BundleRepo::new( | ||
repo_root.clone(), | ||
repo_url.clone(), | ||
repo_head_sha.clone(), | ||
repo_head_branch.clone(), | ||
repo_head_commit_epoch.clone(), | ||
)?; | ||
|
||
if junit_paths.is_empty() && bazel_bep_path.is_none() { | ||
return Err(anyhow::anyhow!("No junit paths provided.")); | ||
} | ||
|
||
let api_client = ApiClient::new(String::from(token))?; | ||
|
||
let codeowners = CodeOwners::find_file(&repo.repo_root, codeowners_path); | ||
let junit_spec = if !junit_paths.is_empty() { | ||
JunitSpec::Paths(junit_paths.clone()) | ||
} else { | ||
JunitSpec::BazelBep(bazel_bep_path.as_deref().unwrap_or_default().to_string()) | ||
}; | ||
|
||
log::info!("running command: {:?}", command); | ||
let run_result = run_test_command( | ||
&repo, | ||
org_url_slug, | ||
command.first().unwrap(), | ||
command.iter().skip(1).collect(), | ||
junit_spec, | ||
team.clone(), | ||
&codeowners, | ||
) | ||
.await | ||
.unwrap_or_else(|e| { | ||
log::error!("Test command failed to run: {}", e); | ||
RunResult { | ||
exit_code: EXIT_FAILURE, | ||
failures: Vec::new(), | ||
exec_start: None, | ||
} | ||
}); | ||
|
||
let run_exit_code = run_result.exit_code; | ||
let failures = run_result.failures; | ||
|
||
let quarantine_run_result = if *use_quarantining { | ||
Some( | ||
run_quarantine( | ||
&api_client, | ||
&api::GetQuarantineBulkTestStatusRequest { | ||
repo: repo.repo, | ||
org_url_slug: org_url_slug.clone(), | ||
test_identifiers: failures.clone(), | ||
}, | ||
failures, | ||
run_exit_code, | ||
) | ||
.await, | ||
) | ||
} else { | ||
None | ||
}; | ||
|
||
let exit_code = quarantine_run_result | ||
.as_ref() | ||
.map(|r| r.exit_code) | ||
.unwrap_or(run_exit_code); | ||
|
||
let exec_start = run_result.exec_start; | ||
if let Err(e) = run_upload( | ||
upload_args, | ||
Some(command.join(" ")), | ||
None, // don't re-run quarantine checks | ||
codeowners, | ||
exec_start, | ||
) | ||
.await | ||
{ | ||
log::error!("Error uploading test results: {:?}", e) | ||
}; | ||
|
||
Ok(exit_code) | ||
} |
Oops, something went wrong.