7
7
It reads job definitions from `src/ci/github-actions/jobs.yml`
8
8
and filters them based on the event that happened on CI.
9
9
"""
10
+ import dataclasses
10
11
import enum
11
12
import json
12
13
import logging
@@ -46,28 +47,31 @@ class JobType(enum.Enum):
46
47
Auto = enum .auto ()
47
48
48
49
49
- def find_job_type (github_ctx : Dict [str , Any ]) -> Optional [JobType ]:
50
- event_name = github_ctx ["event_name" ]
51
- ref = github_ctx ["ref" ]
52
- repository = github_ctx ["repository" ]
50
+ @dataclasses .dataclass
51
+ class GitHubCtx :
52
+ event_name : str
53
+ ref : str
54
+ repository : str
53
55
54
- if event_name == "pull_request" :
56
+
57
+ def find_job_type (ctx : GitHubCtx ) -> Optional [JobType ]:
58
+ if ctx .event_name == "pull_request" :
55
59
return JobType .PR
56
- elif event_name == "push" :
60
+ elif ctx . event_name == "push" :
57
61
old_bors_try_build = (
58
- ref in ("refs/heads/try" , "refs/heads/try-perf" ) and
59
- repository == "rust-lang-ci/rust"
62
+ ctx . ref in ("refs/heads/try" , "refs/heads/try-perf" ) and
63
+ ctx . repository == "rust-lang-ci/rust"
60
64
)
61
65
new_bors_try_build = (
62
- ref == "refs/heads/automation/bors/try" and
63
- repository == "rust-lang/rust"
66
+ ctx . ref == "refs/heads/automation/bors/try" and
67
+ ctx . repository == "rust-lang/rust"
64
68
)
65
69
try_build = old_bors_try_build or new_bors_try_build
66
70
67
71
if try_build :
68
72
return JobType .Try
69
73
70
- if ref == "refs/heads/auto" and repository == "rust-lang-ci/rust" :
74
+ if ctx . ref == "refs/heads/auto" and ctx . repository == "rust-lang-ci/rust" :
71
75
return JobType .Auto
72
76
73
77
return None
@@ -84,13 +88,21 @@ def calculate_jobs(job_type: JobType, job_data: Dict[str, Any]) -> List[Dict[str
84
88
return []
85
89
86
90
91
+ def get_github_ctx () -> GitHubCtx :
92
+ return GitHubCtx (
93
+ event_name = os .environ ["GITHUB_EVENT_NAME" ],
94
+ ref = os .environ ["GITHUB_REF" ],
95
+ repository = os .environ ["GITHUB_REPOSITORY" ]
96
+ )
97
+
98
+
87
99
if __name__ == "__main__" :
88
100
logging .basicConfig (level = logging .INFO )
89
101
90
102
with open (JOBS_YAML_PATH ) as f :
91
103
data = yaml .safe_load (f )
92
104
93
- github_ctx = json . loads ( os . environ [ "GITHUB_CTX" ] )
105
+ github_ctx = get_github_ctx ( )
94
106
95
107
job_type = find_job_type (github_ctx )
96
108
logging .info (f"Job type: { job_type } " )
0 commit comments