Skip to content

Commit

Permalink
Merge pull request #966 from googlefonts/crater-cache
Browse files Browse the repository at this point in the history
[crater] Support caching git checkouts in ci
  • Loading branch information
cmyr authored Sep 17, 2024
2 parents 691837b + 7c3a32a commit 218f877
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions fontc_crater/src/ci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ mod html;
static SUMMARY_FILE: &str = "summary.json";
static SOURCES_FILE: &str = "sources.json";

// this env var can be set by the runner in order to reuse git checkouts
// between runs.
static GIT_CACHE_DIR_VAR: &str = "CRATER_GIT_CACHE";

type DiffResults = Results<DiffOutput, DiffError>;

/// A summary of a single CI run
Expand Down Expand Up @@ -93,14 +97,22 @@ fn run_crater_and_save_results(args: &CiArgs) -> Result<(), Error> {
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
let cache_dir = tempfile::tempdir().unwrap();
let temp_dir = tempfile::tempdir().unwrap();
let user_cache_dir = std::env::var_os(GIT_CACHE_DIR_VAR).map(PathBuf::from);

if let Some(user_cache_dir) = user_cache_dir.as_ref() {
if !user_cache_dir.exists() {
super::try_create_dir(user_cache_dir)?;
}
}
let cache_dir = user_cache_dir
.as_ref()
.map(Path::new)
.unwrap_or(temp_dir.path());
eprintln!("using working dir {}", cache_dir.display());

let began = Utc::now();
let results = super::run_all(
&inputs,
cache_dir.path(),
super::ttx_diff_runner::run_ttx_diff,
)?;
let results = super::run_all(&inputs, cache_dir, super::ttx_diff_runner::run_ttx_diff)?;
let finished = Utc::now();

super::try_write_json(&results, &out_path)?;
Expand Down

0 comments on commit 218f877

Please sign in to comment.