Skip to content

Commit 9a07698

Browse files
authored
Rollup merge of #143274 - marcoieni:optional-jobs, r=Kobzol
ci: support optional jobs try-job: optional-mingw-check-1
2 parents 932d198 + 311a99c commit 9a07698

File tree

4 files changed

+43
-6
lines changed

4 files changed

+43
-6
lines changed

src/ci/citool/src/jobs.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ pub struct JobDatabase {
6666
pub try_jobs: Vec<Job>,
6767
#[serde(rename = "auto")]
6868
pub auto_jobs: Vec<Job>,
69+
#[serde(rename = "optional")]
70+
pub optional_jobs: Vec<Job>,
6971

7072
/// Shared environments for the individual run types.
7173
envs: JobEnvironments,
@@ -75,9 +77,10 @@ impl JobDatabase {
7577
/// Find `auto` jobs that correspond to the passed `pattern`.
7678
/// Patterns are matched using the glob syntax.
7779
/// For example `dist-*` matches all jobs starting with `dist-`.
78-
fn find_auto_jobs_by_pattern(&self, pattern: &str) -> Vec<Job> {
80+
fn find_auto_or_optional_jobs_by_pattern(&self, pattern: &str) -> Vec<Job> {
7981
self.auto_jobs
8082
.iter()
83+
.chain(self.optional_jobs.iter())
8184
.filter(|j| glob_match::glob_match(pattern, &j.name))
8285
.cloned()
8386
.collect()
@@ -181,7 +184,7 @@ fn calculate_jobs(
181184
let mut jobs: Vec<Job> = vec![];
182185
let mut unknown_patterns = vec![];
183186
for pattern in patterns {
184-
let matched_jobs = db.find_auto_jobs_by_pattern(pattern);
187+
let matched_jobs = db.find_auto_or_optional_jobs_by_pattern(pattern);
185188
if matched_jobs.is_empty() {
186189
unknown_patterns.push(pattern.clone());
187190
} else {

src/ci/citool/src/jobs/tests.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ auto:
4646
- name: test-msvc-i686-2
4747
os: ubuntu
4848
env: {}
49+
optional:
50+
- name: optional-job-1
51+
os: ubuntu
52+
env: {}
53+
- name: optional-dist-x86_64
54+
os: ubuntu
55+
env: {}
4956
"#,
5057
)
5158
.unwrap();
@@ -57,12 +64,18 @@ auto:
5764
"*i686*",
5865
&["test-i686", "dist-i686", "test-msvc-i686-1", "test-msvc-i686-2"],
5966
);
67+
// Test that optional jobs are found
68+
check_pattern(&db, "optional-*", &["optional-job-1", "optional-dist-x86_64"]);
69+
check_pattern(&db, "*optional*", &["optional-job-1", "optional-dist-x86_64"]);
6070
}
6171

6272
#[track_caller]
6373
fn check_pattern(db: &JobDatabase, pattern: &str, expected: &[&str]) {
64-
let jobs =
65-
db.find_auto_jobs_by_pattern(pattern).into_iter().map(|j| j.name).collect::<Vec<_>>();
74+
let jobs = db
75+
.find_auto_or_optional_jobs_by_pattern(pattern)
76+
.into_iter()
77+
.map(|j| j.name)
78+
.collect::<Vec<_>>();
6679

6780
assert_eq!(jobs, expected);
6881
}
@@ -116,8 +129,13 @@ fn validate_jobs() {
116129
load_job_db(&db_str).expect("Failed to load job database")
117130
};
118131

119-
let all_jobs =
120-
db.pr_jobs.iter().chain(db.try_jobs.iter()).chain(db.auto_jobs.iter()).collect::<Vec<_>>();
132+
let all_jobs = db
133+
.pr_jobs
134+
.iter()
135+
.chain(db.try_jobs.iter())
136+
.chain(db.auto_jobs.iter())
137+
.chain(db.optional_jobs.iter())
138+
.collect::<Vec<_>>();
121139

122140
let errors: Vec<anyhow::Error> =
123141
all_jobs.into_iter().filter_map(|job| validate_codebuild_image(job).err()).collect();

src/ci/citool/tests/test-jobs.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,8 @@ auto:
139139
DIST_REQUIRE_ALL_TOOLS: 1
140140
CODEGEN_BACKENDS: llvm,cranelift
141141
<<: *job-windows
142+
143+
# Jobs that only run when explicitly invoked via `@bors try`.
144+
optional:
145+
- name: test-optional-job
146+
<<: *job-linux-4c

src/ci/github-actions/jobs.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,17 @@ pr:
160160
try:
161161
- <<: *job-dist-x86_64-linux
162162

163+
# Jobs that only run when explicitly invoked in one of the following ways:
164+
# - comment `@bors2 try jobs=<job-name>`
165+
# - `try-job: <job-name>` in the PR description and comment `@bors try` or `@bors2 try`.
166+
optional:
167+
# This job is used just to test optional jobs.
168+
# It will be replaced by tier 2 and tier 3 jobs in the future.
169+
- name: optional-mingw-check-1
170+
env:
171+
IMAGE: mingw-check-1
172+
<<: *job-linux-4c
173+
163174
# Main CI jobs that have to be green to merge a commit into master
164175
# These jobs automatically inherit envs.auto, to avoid repeating
165176
# it in each job definition.

0 commit comments

Comments
 (0)