@@ -7,24 +7,57 @@ import { inspect } from 'util'
77import  core  from  '@actions/core' 
88import  github  from  '@actions/github' 
99
10- export  default  async  function  ( {  octokit,  workflow_id,  run_id,  before } )  { 
10+ export  default  async  function  ( {  octokit,  workflow_id,  run_id,  before,  jobName  } )  { 
1111  // get current run of this workflow 
1212  const  {  data : {  workflow_runs }  }  =  await  octokit . request ( 'GET /repos/{owner}/{repo}/actions/workflows/{workflow_id}/runs' ,  { 
1313    ...github . context . repo , 
1414    workflow_id
1515  } ) 
1616
1717  // find any instances of the same workflow 
18-   const  waiting_for  =  workflow_runs 
18+   const  active_runs  =  workflow_runs 
1919    // limit to currently running ones 
2020    . filter ( run  =>  [ 'in_progress' ,  'queued' ,  'waiting' ,  'pending' ,  'action_required' ,  'requested' ] . includes ( run . status ) ) 
2121    // exclude this one 
2222    . filter ( run  =>  run . id  !==  run_id ) 
2323    // get older runs 
2424    . filter ( run  =>  new  Date ( run . run_started_at )  <  before ) 
2525
26-   core . info ( `found ${ waiting_for . length }   workflow runs` ) 
27-   core . debug ( inspect ( waiting_for . map ( run  =>  ( {  id : run . id ,  name : run . name  } ) ) ) ) 
26+   core . info ( `found ${ active_runs . length }   active workflow runs` ) 
2827
29-   return  waiting_for 
28+   // If no job name specified, return all active runs (existing behavior) 
29+   if  ( ! jobName )  { 
30+     core . debug ( inspect ( active_runs . map ( run  =>  ( {  id : run . id ,  name : run . name  } ) ) ) ) 
31+     return  active_runs 
32+   } 
33+ 
34+   // Job-level filtering: check each active run for the specific job 
35+   const  runs_with_target_job  =  [ ] 
36+   
37+   for  ( const  run  of  active_runs )  { 
38+     try  { 
39+       // Get jobs for this workflow run 
40+       const  {  data : {  jobs }  }  =  await  octokit . request ( 'GET /repos/{owner}/{repo}/actions/runs/{run_id}/jobs' ,  { 
41+         ...github . context . repo , 
42+         run_id : run . id 
43+       } ) 
44+ 
45+       // Check if this run has the target job currently running 
46+       const  target_job  =  jobs . find ( job  =>  
47+         job . name  ===  jobName  &&  
48+         [ 'in_progress' ,  'queued' ,  'waiting' ,  'pending' ,  'action_required' ,  'requested' ] . includes ( job . status ) 
49+       ) 
50+ 
51+       if  ( target_job )  { 
52+         core . info ( `found job "${ jobName }  " (status: ${ target_job . status }  ) in run #${ run . id }  ` ) 
53+         runs_with_target_job . push ( run ) 
54+       } 
55+     }  catch  ( error )  { 
56+       // Log error but continue checking other runs 
57+       core . warning ( `failed to fetch jobs for run #${ run . id }  : ${ error . message }  ` ) 
58+     } 
59+   } 
60+ 
61+   core . debug ( inspect ( runs_with_target_job . map ( run  =>  ( {  id : run . id ,  name : run . name  } ) ) ) ) 
62+   return  runs_with_target_job 
3063} 
0 commit comments