1111import  json 
1212import  logging 
1313import  os 
14+ import  re 
1415import  typing 
1516from  pathlib  import  Path 
1617from  typing  import  List , Dict , Any , Optional 
@@ -67,6 +68,23 @@ class GitHubCtx:
6768    event_name : str 
6869    ref : str 
6970    repository : str 
71+     commit_message : Optional [str ]
72+ 
73+ 
74+ def  get_job_from_commit (ctx : GitHubCtx ) ->  Optional [str ]:
75+     """ 
76+     Tries to parse a name of a CI job that should be executed in the form of 
77+     ci-job: <job-name> 
78+     from the commit message of the passed GitHub context. 
79+     """ 
80+     if  ctx .commit_message  is  None :
81+         return  None 
82+ 
83+     regex  =  re .compile (r"ci-job: (.*)" )
84+     match  =  regex .search (ctx .commit_message )
85+     if  match  is  None :
86+         return  None 
87+     return  match .group (1 )
7088
7189
7290def  find_run_type (ctx : GitHubCtx ) ->  Optional [WorkflowRunType ]:
@@ -84,7 +102,8 @@ def find_run_type(ctx: GitHubCtx) -> Optional[WorkflowRunType]:
84102        try_build  =  old_bors_try_build  or  new_bors_try_build 
85103
86104        if  try_build :
87-             return  TryRunType ()
105+             job_name  =  get_job_from_commit (ctx )
106+             return  TryRunType (job = job_name )
88107
89108        if  ctx .ref  ==  "refs/heads/auto"  and  ctx .repository  ==  "rust-lang-ci/rust" :
90109            return  AutoRunType ()
@@ -96,8 +115,16 @@ def calculate_jobs(run_type: WorkflowRunType, job_data: Dict[str, Any]) -> List[
96115    if  isinstance (run_type , PRRunType ):
97116        return  add_base_env (name_jobs (job_data ["pr" ], "PR" ), job_data ["envs" ]["pr" ])
98117    elif  isinstance (run_type , TryRunType ):
99-         return  add_base_env (name_jobs (job_data ["try" ], "try" ), job_data ["envs" ]["try" ])
100-     elif  isinstance (run_type , AutoRunType ):
118+         jobs  =  job_data ["try" ]
119+         if  run_type .job  is  not   None :
120+             jobs  =  [job  for  job  in  job_data ["auto" ] if  job ["image" ] ==  run_type .job ]
121+             if  not  jobs :
122+                 raise  Exception (
123+                     f"CI job `{ run_type .job }  ` asked for in the try build does not exist" 
124+                 )
125+ 
126+         return  add_base_env (name_jobs (jobs , "try" ), job_data ["envs" ]["try" ])
127+     elif  run_type  is  AutoRunType :
101128        return  add_base_env (name_jobs (job_data ["auto" ], "auto" ), job_data ["envs" ]["auto" ])
102129
103130    return  []
@@ -111,10 +138,16 @@ def skip_jobs(jobs: List[Dict[str, Any]], channel: str) -> List[Job]:
111138
112139
113140def  get_github_ctx () ->  GitHubCtx :
141+     event_name  =  os .environ ["GITHUB_EVENT_NAME" ]
142+ 
143+     commit_message  =  None 
144+     if  event_name  ==  "push" :
145+         commit_message  =  os .environ ["COMMIT_MESSAGE" ]
114146    return  GitHubCtx (
115-         event_name = os . environ [ "GITHUB_EVENT_NAME" ] ,
147+         event_name = event_name ,
116148        ref = os .environ ["GITHUB_REF" ],
117-         repository = os .environ ["GITHUB_REPOSITORY" ]
149+         repository = os .environ ["GITHUB_REPOSITORY" ],
150+         commit_message = commit_message 
118151    )
119152
120153
0 commit comments