@@ -317,44 +317,19 @@ async function findExistingRetryComment(github, context, core, pr) {
317317 }
318318}
319319
320- async function getRetryCountFromAPI ( github , context , core , workflowRun ) {
321- try {
322- // Get workflow runs for the same branch/commit
323- const { data : workflowRuns } = await github . rest . actions . listWorkflowRuns ( {
324- owner : context . repo . owner ,
325- repo : context . repo . repo ,
326- workflow_id : workflowRun . workflow_id ,
327- branch : workflowRun . head_branch ,
328- per_page : 100
329- } ) ;
330-
331- // Count runs that were retries (have the same head_sha)
332- let retryCount = 0 ;
333- const currentSha = workflowRun . head_sha ;
334-
335- for ( const run of workflowRuns . workflow_runs ) {
336- if ( run . head_sha === currentSha && run . id !== workflowRun . id ) {
337- // This is a previous run with the same commit SHA
338- retryCount ++ ;
339- }
340- }
341-
342- core . info ( `Found ${ retryCount } previous workflow runs for the same commit` ) ;
343- return retryCount ;
344- } catch ( error ) {
345- core . warning ( `Failed to get retry count from API: ${ error . message } ` ) ;
320+ function getCurrentRetryCount ( workflowRun ) {
321+ if ( ! workflowRun || typeof workflowRun . run_attempt !== 'number' ) {
346322 return 0 ;
347323 }
324+ return Math . max ( 0 , workflowRun . run_attempt - 1 ) ;
348325}
349326
350- async function addCommentToPR ( github , context , core , runID , runURL , jobData , priorityCancelled , maxRetriesReached = false ) {
327+ async function addCommentToPR ( github , context , core , workflowRun , runURL , jobData , priorityCancelled , maxRetriesReached = false ) {
351328 try {
352- // Get workflow run to find the branch
353- const { data : workflowRun } = await github . rest . actions . getWorkflowRun ( {
354- owner : context . repo . owner ,
355- repo : context . repo . repo ,
356- run_id : runID
357- } ) ;
329+ const runID = workflowRun . id ;
330+ const currentRetryCount = getCurrentRetryCount ( workflowRun ) ;
331+ const newRetryCount = jobData . retryableJobsCount > 0 ? currentRetryCount + 1 : currentRetryCount ;
332+ const displayRunURL = runURL || workflowRun . html_url ;
358333
359334 // Find related PR
360335 const pr = await findRelatedPR ( github , context , core , workflowRun ) ;
@@ -367,10 +342,6 @@ async function addCommentToPR(github, context, core, runID, runURL, jobData, pri
367342 // Try to find existing retry comment
368343 const existingComment = await findExistingRetryComment ( github , context , core , pr ) ;
369344
370- // Get current retry count from API
371- const currentRetryCount = await getRetryCountFromAPI ( github , context , core , workflowRun ) ;
372- const newRetryCount = jobData . retryableJobsCount > 0 ? currentRetryCount + 1 : currentRetryCount ;
373-
374345 // Build title with retry count
375346 const titleSuffix = newRetryCount > 0 ? ` (Retry ${ newRetryCount } )` : '' ;
376347
@@ -383,17 +354,17 @@ async function addCommentToPR(github, context, core, runID, runURL, jobData, pri
383354 // Simplified comment for priority cancelled workflow
384355 comment = `${ TITLE } ${ titleSuffix }
385356
386- > **Workflow:** [\`${ runID } \`](${ runURL } )
357+ > **Workflow:** [\`${ runID } \`](${ displayRunURL } )
387358
388359### ⛔️ **CANCELLED**
389360Higher priority request detected - retry cancelled to avoid conflicts.
390361
391- [View Workflow](${ runURL } )` ;
362+ [View Workflow](${ displayRunURL } )` ;
392363 } else if ( maxRetriesReached ) {
393364 // Comment for when max retries reached
394365 comment = `${ TITLE } ${ titleSuffix }
395366
396- > **Workflow:** [\`${ runID } \`](${ runURL } )
367+ > **Workflow:** [\`${ runID } \`](${ displayRunURL } )
397368
398369### 📊 Summary
399370- **Total Jobs:** ${ jobData . totalJobs }
@@ -404,7 +375,7 @@ Higher priority request detected - retry cancelled to avoid conflicts.
404375### 🚫 **MAX RETRIES REACHED**
405376Maximum retry count (3) has been reached. Manual intervention required.
406377
407- [View Workflow](${ runURL } )` ;
378+ [View Workflow](${ displayRunURL } )` ;
408379
409380 comment += `
410381
@@ -440,7 +411,7 @@ Automated analysis using job annotations to distinguish infrastructure issues (a
440411 // Full comment for normal analysis
441412 comment = `${ TITLE } ${ titleSuffix }
442413
443- > **Workflow:** [\`${ runID } \`](${ runURL } )
414+ > **Workflow:** [\`${ runID } \`](${ displayRunURL } )
444415
445416### 📊 Summary
446417- **Total Jobs:** ${ jobData . totalJobs }
@@ -454,7 +425,7 @@ Automated analysis using job annotations to distinguish infrastructure issues (a
454425### ✅ **AUTO-RETRY INITIATED**
455426**${ jobData . retryableJobsCount } job(s)** retried due to infrastructure issues (runner failures, timeouts, etc.)
456427
457- [View Progress](${ runURL } )` ;
428+ [View Progress](${ displayRunURL } )` ;
458429 } else {
459430 comment += `
460431
@@ -579,32 +550,33 @@ module.exports = async ({ github, context, core }) => {
579550 // Handle priority cancellation
580551 if ( priorityCancelled ) {
581552 core . info ( 'Cancelling retry since a higher priority request was made' ) ;
582- await addCommentToPR ( github , context , core , runID , runURL , { failedJobs, analyzedJobs, totalJobs, retryableJobsCount : 0 } , true ) ;
553+ await addCommentToPR ( github , context , core , workflowRun , runURL , { failedJobs, analyzedJobs, totalJobs, retryableJobsCount : 0 } , true ) ;
583554 return ;
584555 }
585556
586557 // Check retry count limit (max 3 retries)
587- const currentRetryCount = await getRetryCountFromAPI ( github , context , core , workflowRun ) ;
558+ const currentRetryCount = getCurrentRetryCount ( workflowRun ) ;
559+ core . info ( `Current retry attempt: ${ workflowRun . run_attempt || 1 } (previous retries: ${ currentRetryCount } )` ) ;
588560 const maxRetries = 3 ;
589561
590562 if ( currentRetryCount >= maxRetries ) {
591563 core . info ( `Maximum retry count (${ maxRetries } ) reached. Skipping retry.` ) ;
592- await addCommentToPR ( github , context , core , runID , runURL , { failedJobs, analyzedJobs, totalJobs, retryableJobsCount : 0 } , false , true ) ;
564+ await addCommentToPR ( github , context , core , workflowRun , runURL , { failedJobs, analyzedJobs, totalJobs, retryableJobsCount : 0 } , false , true ) ;
593565 return ;
594566 }
595567
596568 // Handle no retryable jobs
597569 if ( jobsToRetry . length === 0 ) {
598570 core . info ( 'No jobs found with retryable errors. Skipping retry.' ) ;
599- await addCommentToPR ( github , context , core , runID , runURL , { failedJobs, analyzedJobs, totalJobs, retryableJobsCount : 0 } , false ) ;
571+ await addCommentToPR ( github , context , core , workflowRun , runURL , { failedJobs, analyzedJobs, totalJobs, retryableJobsCount : 0 } , false ) ;
600572 return ;
601573 }
602574
603575 // Retry failed jobs
604576 await retryFailedJobs ( github , context , core , runID , jobsToRetry ) ;
605577
606578 // Add comment to PR
607- await addCommentToPR ( github , context , core , runID , runURL , { failedJobs, analyzedJobs, totalJobs, retryableJobsCount : jobsToRetry . length } , false ) ;
579+ await addCommentToPR ( github , context , core , workflowRun , runURL , { failedJobs, analyzedJobs, totalJobs, retryableJobsCount : jobsToRetry . length } , false ) ;
608580
609581 core . info ( 'Retry process completed' ) ;
610582} ;
0 commit comments