Skip to content

Commit

Permalink
Merge pull request #1313 from googlefonts/crater-store-input-sha
Browse files Browse the repository at this point in the history
[crater] Store input sha instead of filename
  • Loading branch information
cmyr authored Feb 28, 2025
2 parents ae569a1 + f5a2cdc commit e66c51a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
17 changes: 7 additions & 10 deletions fontc_crater/src/ci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ struct RunSummary {
results_file: PathBuf,
// the name of the file listing targets used by this run.
// it is intended that when this list is updated, the filename is changed.
input_file: PathBuf,
#[serde(alias = "input_file")]
input_file_sha: String,
stats: super::ttx_diff_runner::Summary,
}

Expand Down Expand Up @@ -84,24 +85,25 @@ fn run_crater_and_save_results(args: &CiArgs) -> Result<(), Error> {
}

log_if_auth_or_not();
// do this now so we error if the input file doesn't exist
let inputs: Vec<RepoInfo> = super::try_read_json(&args.to_run)?;

let summary_file = args.out_dir.join(SUMMARY_FILE);
let mut prev_runs: Vec<RunSummary> = load_json_if_exists_else_default(&summary_file)?;
// todo: fontc_repo should be checked out by us, and have a known path
let fontc_rev = super::get_git_rev(None).unwrap();
let pip_freeze_sha = super::pip_freeze_sha();
let input_file_sha = super::get_input_sha(&args.to_run);
if let Some(last_run) = prev_runs.last() {
if last_run.fontc_rev == fontc_rev
&& Some(last_run.input_file.as_os_str()) == args.to_run.file_name()
&& input_file_sha == last_run.input_file_sha
&& pip_freeze_sha == last_run.pip_freeze_sha
{
log::info!("no changes since last run, skipping");
return Ok(());
}
}

let inputs: Vec<RepoInfo> = super::try_read_json(&args.to_run)?;

let out_file = result_path_for_current_date();
let out_path = args.out_dir.join(&out_file);
// for now we are going to be cloning each repo freshly
Expand Down Expand Up @@ -146,19 +148,14 @@ fn run_crater_and_save_results(args: &CiArgs) -> Result<(), Error> {
log::info!("output identical to last run, skipping");
return Ok(());
}
let input_file = args
.to_run
.file_name()
.map(PathBuf::from)
.unwrap_or_else(|| args.to_run.clone());

let summary = RunSummary {
began,
finished,
fontc_rev,
pip_freeze_sha,
results_file: out_file.into(),
input_file,
input_file_sha,
stats: summary,
};

Expand Down
11 changes: 11 additions & 0 deletions fontc_crater/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,17 @@ fn pip_freeze_sha() -> String {
.to_owned()
}

fn get_input_sha(path: &Path) -> String {
let output = Command::new("shasum")
.arg(path)
.output()
.expect("shasum should be installed everywhere");
std::str::from_utf8(&output.stdout)
.expect("shasum output always ascii")
.trim()
.to_owned()
}

impl<T, E> FromIterator<(Target, RunResult<T, E>)> for Results<T, E> {
fn from_iter<I: IntoIterator<Item = (Target, RunResult<T, E>)>>(iter: I) -> Self {
let mut out = Results::default();
Expand Down

0 comments on commit e66c51a

Please sign in to comment.