Run calculate_matrix job on the master branch

This allows us to reuse its cache on PR CI jobs.
This commit is contained in:
Jakub Beránek 2025-06-09 08:10:55 +02:00
parent 7614592107
commit 54ed1b966f
No known key found for this signature in database
GPG key ID: 909CD0D26483516B
4 changed files with 19 additions and 1 deletions

View file

@ -11,6 +11,10 @@ name: CI
on:
push:
branches:
# CI on master only serves for caching citool builds for the `calculate_matrix` job.
# In order to use GHA cache on PR CI (and auto/try) jobs, we need to write to it
# from the default branch.
- master
- auto
- try
- try-perf

View file

@ -161,6 +161,8 @@ pub enum RunType {
TryJob { job_patterns: Option<Vec<String>> },
/// Merge attempt workflow
AutoJob,
/// Fake job only used for sharing Github Actions cache.
MasterJob,
}
/// Maximum number of custom try jobs that can be requested in a single
@ -210,6 +212,7 @@ fn calculate_jobs(
(jobs, "try", &db.envs.try_env)
}
RunType::AutoJob => (db.auto_jobs.clone(), "auto", &db.envs.auto_env),
RunType::MasterJob => return Ok(vec![]),
};
let jobs = substitute_github_vars(jobs.clone())
.context("Failed to substitute GitHub context variables in jobs")?;
@ -262,7 +265,7 @@ pub fn calculate_job_matrix(
eprintln!("Run type: {run_type:?}");
let jobs = calculate_jobs(&run_type, &db, channel)?;
if jobs.is_empty() {
if jobs.is_empty() && !matches!(run_type, RunType::MasterJob) {
return Err(anyhow::anyhow!("Computed job list is empty"));
}
@ -270,6 +273,7 @@ pub fn calculate_job_matrix(
RunType::PullRequest => "pr",
RunType::TryJob { .. } => "try",
RunType::AutoJob => "auto",
RunType::MasterJob => "master",
};
eprintln!("Output");

View file

@ -47,6 +47,7 @@ impl GitHubContext {
Some(RunType::TryJob { job_patterns: patterns })
}
("push", "refs/heads/auto") => Some(RunType::AutoJob),
("push", "refs/heads/master") => Some(RunType::MasterJob),
_ => None,
}
}

View file

@ -45,6 +45,15 @@ fn pr_jobs() {
"#);
}
#[test]
fn master_jobs() {
let stdout = get_matrix("push", "commit", "refs/heads/master");
insta::assert_snapshot!(stdout, @r#"
jobs=[]
run_type=master
"#);
}
fn get_matrix(event_name: &str, commit_msg: &str, branch_ref: &str) -> String {
let path = std::env::var("PATH");
let mut cmd = Command::new("cargo");