Skip to content

Commit

Permalink
update suggest-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pietroalbini committed Oct 24, 2023
1 parent 5a562d9 commit 4a08735
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/bootstrap/src/core/build_steps/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ use crate::core::builder::Builder;

/// Suggests a list of possible `x.py` commands to run based on modified files in branch.
pub fn suggest(builder: &Builder<'_>, run: bool) {
let suggestions =
builder.tool_cmd(Tool::SuggestTests).output().expect("failed to run `suggest-tests` tool");
let git_config = builder.config.git_config();
let suggestions = builder
.tool_cmd(Tool::SuggestTests)
.env("SUGGEST_TESTS_GITHUB_REPOSITORY", git_config.github_repository)
.env("SUGGEST_TESTS_NIGHTLY_BRANCH", git_config.nightly_branch)
.output()
.expect("failed to run `suggest-tests` tool");

if !suggestions.status.success() {
println!("failed to run `suggest-tests` tool ({})", suggestions.status);
Expand Down
21 changes: 19 additions & 2 deletions src/tools/suggest-tests/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
use std::process::ExitCode;

use build_helper::git::get_git_modified_files;
use build_helper::git::{get_git_modified_files, GitConfig};
use suggest_tests::get_suggestions;

fn main() -> ExitCode {
let modified_files = get_git_modified_files(None, &Vec::new());
let modified_files = get_git_modified_files(
&GitConfig {
github_repository: &env("SUGGEST_TESTS_GITHUB_REPOSITORY"),
nightly_branch: &env("SUGGEST_TESTS_NIGHTLY_BRANCH"),
},
None,
&Vec::new(),
);
let modified_files = match modified_files {
Ok(Some(files)) => files,
Ok(None) => {
Expand All @@ -25,3 +32,13 @@ fn main() -> ExitCode {

ExitCode::SUCCESS
}

fn env(key: &str) -> String {
match std::env::var(key) {
Ok(var) => var,
Err(err) => {
eprintln!("suggest-tests: failed to read environment variable {key}: {err}");
std::process::exit(1);
}
}
}

0 comments on commit 4a08735

Please sign in to comment.