Skip to content

Commit 54ed1b9

Browse files
committed
Run calculate_matrix job on the master branch
This allows us to reuse its cache on PR CI jobs.
1 parent 7614592 commit 54ed1b9

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ name: CI
1111
on:
1212
push:
1313
branches:
14+
# CI on master only serves for caching citool builds for the `calculate_matrix` job.
15+
# In order to use GHA cache on PR CI (and auto/try) jobs, we need to write to it
16+
# from the default branch.
17+
- master
1418
- auto
1519
- try
1620
- try-perf

src/ci/citool/src/jobs.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ pub enum RunType {
161161
TryJob { job_patterns: Option<Vec<String>> },
162162
/// Merge attempt workflow
163163
AutoJob,
164+
/// Fake job only used for sharing Github Actions cache.
165+
MasterJob,
164166
}
165167

166168
/// Maximum number of custom try jobs that can be requested in a single
@@ -210,6 +212,7 @@ fn calculate_jobs(
210212
(jobs, "try", &db.envs.try_env)
211213
}
212214
RunType::AutoJob => (db.auto_jobs.clone(), "auto", &db.envs.auto_env),
215+
RunType::MasterJob => return Ok(vec![]),
213216
};
214217
let jobs = substitute_github_vars(jobs.clone())
215218
.context("Failed to substitute GitHub context variables in jobs")?;
@@ -262,14 +265,15 @@ pub fn calculate_job_matrix(
262265
eprintln!("Run type: {run_type:?}");
263266

264267
let jobs = calculate_jobs(&run_type, &db, channel)?;
265-
if jobs.is_empty() {
268+
if jobs.is_empty() && !matches!(run_type, RunType::MasterJob) {
266269
return Err(anyhow::anyhow!("Computed job list is empty"));
267270
}
268271

269272
let run_type = match run_type {
270273
RunType::PullRequest => "pr",
271274
RunType::TryJob { .. } => "try",
272275
RunType::AutoJob => "auto",
276+
RunType::MasterJob => "master",
273277
};
274278

275279
eprintln!("Output");

src/ci/citool/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ impl GitHubContext {
4747
Some(RunType::TryJob { job_patterns: patterns })
4848
}
4949
("push", "refs/heads/auto") => Some(RunType::AutoJob),
50+
("push", "refs/heads/master") => Some(RunType::MasterJob),
5051
_ => None,
5152
}
5253
}

src/ci/citool/tests/jobs.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ fn pr_jobs() {
4545
"#);
4646
}
4747

48+
#[test]
49+
fn master_jobs() {
50+
let stdout = get_matrix("push", "commit", "refs/heads/master");
51+
insta::assert_snapshot!(stdout, @r#"
52+
jobs=[]
53+
run_type=master
54+
"#);
55+
}
56+
4857
fn get_matrix(event_name: &str, commit_msg: &str, branch_ref: &str) -> String {
4958
let path = std::env::var("PATH");
5059
let mut cmd = Command::new("cargo");

0 commit comments

Comments
 (0)