8
8
and filters them based on the event that happened on CI.
9
9
"""
10
10
import dataclasses
11
- import enum
12
11
import json
13
12
import logging
14
13
import os
14
+ import typing
15
15
from pathlib import Path
16
16
from typing import List , Dict , Any , Optional
17
17
@@ -44,10 +44,22 @@ def add_base_env(jobs: List[Job], environment: Dict[str, str]) -> List[Job]:
44
44
return jobs
45
45
46
46
47
- class WorkflowRunType (enum .Enum ):
48
- PR = enum .auto ()
49
- Try = enum .auto ()
50
- Auto = enum .auto ()
47
+ @dataclasses .dataclass
48
+ class PRRunType :
49
+ pass
50
+
51
+
52
+ @dataclasses .dataclass
53
+ class TryRunType :
54
+ custom_jobs : List [str ]
55
+
56
+
57
+ @dataclasses .dataclass
58
+ class AutoRunType :
59
+ pass
60
+
61
+
62
+ WorkflowRunType = typing .Union [PRRunType , TryRunType , AutoRunType ]
51
63
52
64
53
65
@dataclasses .dataclass
@@ -59,7 +71,7 @@ class GitHubCtx:
59
71
60
72
def find_run_type (ctx : GitHubCtx ) -> Optional [WorkflowRunType ]:
61
73
if ctx .event_name == "pull_request" :
62
- return WorkflowRunType . PR
74
+ return PRRunType ()
63
75
elif ctx .event_name == "push" :
64
76
old_bors_try_build = (
65
77
ctx .ref in ("refs/heads/try" , "refs/heads/try-perf" ) and
@@ -72,20 +84,20 @@ def find_run_type(ctx: GitHubCtx) -> Optional[WorkflowRunType]:
72
84
try_build = old_bors_try_build or new_bors_try_build
73
85
74
86
if try_build :
75
- return WorkflowRunType . Try
87
+ return TryRunType ()
76
88
77
89
if ctx .ref == "refs/heads/auto" and ctx .repository == "rust-lang-ci/rust" :
78
- return WorkflowRunType . Auto
90
+ return AutoRunType ()
79
91
80
92
return None
81
93
82
94
83
95
def calculate_jobs (run_type : WorkflowRunType , job_data : Dict [str , Any ]) -> List [Job ]:
84
- if run_type == WorkflowRunType . PR :
96
+ if isinstance ( run_type , PRRunType ) :
85
97
return add_base_env (name_jobs (job_data ["pr" ], "PR" ), job_data ["envs" ]["pr" ])
86
- elif run_type == WorkflowRunType . Try :
98
+ elif isinstance ( run_type , TryRunType ) :
87
99
return add_base_env (name_jobs (job_data ["try" ], "try" ), job_data ["envs" ]["try" ])
88
- elif run_type == WorkflowRunType . Auto :
100
+ elif isinstance ( run_type , AutoRunType ) :
89
101
return add_base_env (name_jobs (job_data ["auto" ], "auto" ), job_data ["envs" ]["auto" ])
90
102
91
103
return []
@@ -107,11 +119,11 @@ def get_github_ctx() -> GitHubCtx:
107
119
108
120
109
121
def format_run_type (run_type : WorkflowRunType ) -> str :
110
- if run_type == WorkflowRunType . PR :
122
+ if isinstance ( run_type , PRRunType ) :
111
123
return "pr"
112
- elif run_type == WorkflowRunType . Auto :
124
+ elif isinstance ( run_type , AutoRunType ) :
113
125
return "auto"
114
- elif run_type == WorkflowRunType . Try :
126
+ elif isinstance ( run_type , TryRunType ) :
115
127
return "try"
116
128
else :
117
129
raise AssertionError ()
0 commit comments