Skip to content

Commit 8435fe8

Browse files
authored
Rollup merge of #142231 - Kobzol:master-cache-ci, r=marcoieni
Run `calculate_matrix` job on `master` to cache citool builds As discussed in https://rust-lang.zulipchat.com/#narrow/channel/242791-t-infra/topic/PR.20ci.20seems.20much.20to.20slow/with/523028903, the current `rust-cache` solution for `citool` doesn't work, because we don't ever write to the cache from `master`, so the cache is empty on PR CI jobs. This PR runs the `calculate_matrix` job on `master`, with the only motivation to actually prime the cache. r? `@marcoieni`
2 parents 60a2adb + 54ed1b9 commit 8435fe8

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
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: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,31 @@ 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 {
49-
let output = Command::new("cargo")
50-
.args(["run", "-q", "calculate-job-matrix", "--jobs-file", TEST_JOBS_YML_PATH])
58+
let path = std::env::var("PATH");
59+
let mut cmd = Command::new("cargo");
60+
cmd.args(["run", "-q", "calculate-job-matrix", "--jobs-file", TEST_JOBS_YML_PATH])
61+
.env_clear()
5162
.env("GITHUB_EVENT_NAME", event_name)
5263
.env("COMMIT_MESSAGE", commit_msg)
5364
.env("GITHUB_REF", branch_ref)
5465
.env("GITHUB_RUN_ID", "123")
5566
.env("GITHUB_RUN_ATTEMPT", "1")
56-
.stdout(Stdio::piped())
57-
.output()
58-
.expect("Failed to execute command");
67+
.stdout(Stdio::piped());
68+
if let Ok(path) = path {
69+
cmd.env("PATH", path);
70+
}
71+
72+
let output = cmd.output().expect("Failed to execute command");
5973

6074
let stdout = String::from_utf8(output.stdout).unwrap();
6175
let stderr = String::from_utf8(output.stderr).unwrap();

0 commit comments

Comments
 (0)