Skip to content

Commit dc3c544

Browse files
committed
Move auto jobs to calculate-job-matrix.py
1 parent 6f0ff0b commit dc3c544

File tree

3 files changed

+415
-403
lines changed

3 files changed

+415
-403
lines changed

src/ci/github-actions/calculate-job-matrix.py

+25-4
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,30 @@
2222

2323

2424
def name_jobs(jobs: List[Dict], prefix: str) -> List[Dict]:
25+
"""
26+
Add a `name` attribute to each job, based on its image and the given `prefix`.
27+
"""
2528
for job in jobs:
2629
job["name"] = f"{prefix} - {job['image']}"
2730
return jobs
2831

2932

33+
def add_base_env(jobs: List[Dict], environment: Dict[str, str]) -> List[Dict]:
34+
"""
35+
Prepends `environment` to the `env` attribute of each job.
36+
The `env` of each job has higher precedence than `environment`.
37+
"""
38+
for job in jobs:
39+
env = environment.copy()
40+
env.update(job.get("env", {}))
41+
job["env"] = env
42+
return jobs
43+
44+
3045
class JobType(enum.Enum):
3146
PR = enum.auto()
3247
Try = enum.auto()
48+
Auto = enum.auto()
3349

3450

3551
def find_job_type(github_ctx: Dict[str, Any]) -> Optional[JobType]:
@@ -53,26 +69,31 @@ def find_job_type(github_ctx: Dict[str, Any]) -> Optional[JobType]:
5369
if try_build:
5470
return JobType.Try
5571

72+
if ref == "refs/heads/auto" and repository == "rust-lang-ci/rust":
73+
return JobType.Auto
74+
5675
return None
5776

5877

5978
def calculate_jobs(job_type: JobType, job_data: Dict[str, Any]) -> List[Dict[str, Any]]:
6079
if job_type == JobType.PR:
61-
return name_jobs(job_data["pr"], "PR")
80+
return add_base_env(name_jobs(job_data["pr"], "PR"), job_data["env"]["pr"])
6281
elif job_type == JobType.Try:
63-
return name_jobs(job_data["try"], "try")
82+
return add_base_env(name_jobs(job_data["try"], "try"), job_data["env"]["production"])
83+
elif job_type == JobType.Auto:
84+
return add_base_env(name_jobs(job_data["auto"], "auto"), job_data["env"]["production"])
6485

6586
return []
6687

6788

6889
if __name__ == "__main__":
6990
logging.basicConfig(level=logging.INFO)
7091

71-
github_ctx = json.loads(os.environ["GITHUB_CTX"])
72-
7392
with open(JOBS_YAML_PATH) as f:
7493
data = yaml.safe_load(f)
7594

95+
github_ctx = json.loads(os.environ["GITHUB_CTX"])
96+
7697
job_type = find_job_type(github_ctx)
7798
logging.info(f"Job type: {job_type}")
7899

0 commit comments

Comments
 (0)