@@ -39,6 +39,7 @@ let totalCount = 0
3939let flakeCount = 0
4040
4141async function checkWorkflowRuns ( id , page = 1 ) {
42+ // This only gets the last attempt of every run.
4243 const response = await octokit . rest . actions . listWorkflowRuns ( {
4344 owner : 'DataDog' ,
4445 repo : 'dd-trace-js' ,
@@ -68,17 +69,19 @@ async function checkWorkflowRuns (id, page = 1) {
6869
6970 flakeCount ++
7071
71- promises . push ( checkWorkflowJobs ( run . id ) )
72+ promises . push ( checkWorkflowJobs ( run . id , run . run_attempt - 1 ) )
7273 }
7374
7475 promises . push ( checkWorkflowRuns ( id , page + 1 ) )
7576
7677 return Promise . all ( promises )
7778}
7879
79- async function checkWorkflowJobs ( id , page = 1 ) {
80+ async function checkWorkflowJobs ( id , attempt , page = 1 ) {
81+ if ( attempt < 1 ) return
82+
8083 const response = await octokit . rest . actions . listJobsForWorkflowRunAttempt ( {
81- attempt_number : 1 , // ignore other attempts to keep things simple
84+ attempt_number : attempt ,
8285 owner : 'DataDog' ,
8386 repo : 'dd-trace-js' ,
8487 run_id : id ,
@@ -88,9 +91,6 @@ async function checkWorkflowJobs (id, page = 1) {
8891
8992 const { jobs } = response . data
9093
91- // We've reached the last page and there are no more results.
92- if ( jobs . length === 0 ) return
93-
9494 for ( const job of jobs ) {
9595 if ( job . conclusion !== 'failure' ) continue
9696
@@ -107,7 +107,13 @@ async function checkWorkflowJobs (id, page = 1) {
107107 }
108108 }
109109
110- return checkWorkflowJobs ( id , page + 1 )
110+ // We've reached the last page and there are no more results.
111+ if ( jobs . length < 100 ) {
112+ // Check previous attempt to include successive failures.
113+ return checkWorkflowJobs ( id , attempt - 1 )
114+ }
115+
116+ return checkWorkflowJobs ( id , attempt , page + 1 )
111117}
112118
113119await Promise . all ( workflows . map ( w => checkWorkflowRuns ( w ) ) )
0 commit comments