Skip to content

Commit cae80b0

Browse files
authored
ci: also auto retry for main (#18231)
1 parent f5ba785 commit cae80b0

File tree

3 files changed

+87
-70
lines changed

3 files changed

+87
-70
lines changed

.github/scripts/retry_failed_jobs.js

Lines changed: 85 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -324,53 +324,65 @@ async function addCommentToPR(github, context, core, runID, runURL, failedJobs,
324324
// Build title with retry count
325325
const titleSuffix = newRetryCount > 0 ? ` (Retry #${newRetryCount})` : '';
326326

327-
let comment = `## 🤖 Smart Auto-retry Analysis${titleSuffix}
327+
// Calculate code issues count (exclude priority cancelled)
328+
const codeIssuesCount = priorityCancelled ? 0 : (failedJobs.length - retryableJobsCount);
329+
330+
let comment;
331+
332+
if (priorityCancelled) {
333+
// Simplified comment for priority cancelled workflow
334+
comment = `## 🤖 Smart Auto-retry Analysis${titleSuffix}
335+
336+
> **Workflow:** [\`${runID}\`](${runURL})
337+
338+
### ⛔️ **CANCELLED**
339+
Higher priority request detected - retry cancelled to avoid conflicts.
340+
341+
[View Workflow](${runURL})`;
342+
} else {
343+
// Full comment for normal analysis
344+
comment = `## 🤖 Smart Auto-retry Analysis${titleSuffix}
328345
329346
> **Workflow:** [\`${runID}\`](${runURL})
330347
331348
### 📊 Summary
332349
- **Failed Jobs:** ${failedJobs.length}
333350
- **Retryable:** ${retryableJobsCount}
334-
- **Code Issues:** ${failedJobs.length - retryableJobsCount}`;
351+
- **Code Issues:** ${codeIssuesCount}`;
335352

336-
if (priorityCancelled) {
337-
comment += `
338-
339-
### ⛔️ **CANCELLED**
340-
Higher priority request detected - retry cancelled to avoid conflicts.`;
341-
} else if (retryableJobsCount > 0) {
342-
comment += `
353+
if (retryableJobsCount > 0) {
354+
comment += `
343355
344356
### ✅ **AUTO-RETRY INITIATED**
345357
**${retryableJobsCount} job(s)** retried due to infrastructure issues (runner failures, timeouts, etc.)
346358
347359
[View Progress](${runURL})`;
348-
} else {
349-
comment += `
360+
} else {
361+
comment += `
350362
351363
### ❌ **NO RETRY NEEDED**
352364
All failures appear to be code/test issues requiring manual fixes.`;
353-
}
365+
}
354366

355-
comment += `
367+
comment += `
356368
357369
### 🔍 Job Details
358370
${analyzedJobs.map(job => {
359-
if (job.reason.includes('Analysis failed')) {
360-
return `- ❓ **${job.name}**: Analysis failed`;
361-
}
362-
if (job.reason.includes('Cancelled by higher priority')) {
363-
return `- ⛔️ **${job.name}**: Cancelled by higher priority`;
364-
}
365-
if (job.reason.includes('No annotations found')) {
366-
return `- ❓ **${job.name}**: No annotations available`;
367-
}
368-
if (job.retryable) {
369-
return `- 🔄 **${job.name}**: ✅ Retryable (Infrastructure)`;
370-
} else {
371-
return `- ❌ **${job.name}**: Not retryable (Code/Test)`;
372-
}
373-
}).join('\n')}
371+
if (job.reason.includes('Analysis failed')) {
372+
return `- ❓ **${job.name}**: Analysis failed`;
373+
}
374+
if (job.reason.includes('Cancelled by higher priority')) {
375+
return `- ⛔️ **${job.name}**: Cancelled by higher priority`;
376+
}
377+
if (job.reason.includes('No annotations found')) {
378+
return `- ❓ **${job.name}**: No annotations available`;
379+
}
380+
if (job.retryable) {
381+
return `- 🔄 **${job.name}**: ✅ Retryable (Infrastructure)`;
382+
} else {
383+
return `- ❌ **${job.name}**: Not retryable (Code/Test)`;
384+
}
385+
}).join('\n')}
374386
375387
---
376388
@@ -379,6 +391,7 @@ ${analyzedJobs.map(job => {
379391
380392
Automated analysis using job annotations to distinguish infrastructure issues (auto-retried) from code/test issues (manual fixes needed).
381393
</details>`;
394+
}
382395

383396
if (existingComment) {
384397
// Update existing comment
@@ -404,9 +417,53 @@ Automated analysis using job annotations to distinguish infrastructure issues (a
404417
}
405418
}
406419

420+
async function deleteRetryComment(github, context, core, runID) {
421+
try {
422+
// Get workflow run to find the branch
423+
const { data: workflowRun } = await github.rest.actions.getWorkflowRun({
424+
owner: context.repo.owner,
425+
repo: context.repo.repo,
426+
run_id: runID
427+
});
428+
429+
// Find related PR
430+
const pr = await findRelatedPR(github, context, core, workflowRun);
431+
432+
if (!pr) {
433+
core.info('No related PR found, skipping comment deletion');
434+
return;
435+
}
436+
437+
// Try to find existing retry comment
438+
const existingComment = await findExistingRetryComment(github, context, core, pr);
439+
440+
if (existingComment) {
441+
// Delete existing comment
442+
await github.rest.issues.deleteComment({
443+
owner: context.repo.owner,
444+
repo: context.repo.repo,
445+
comment_id: existingComment.id
446+
});
447+
core.info(`Deleted smart retry analysis comment from PR #${pr.number}`);
448+
} else {
449+
core.info('No existing retry analysis comment found to delete');
450+
}
451+
} catch (error) {
452+
core.error(`Failed to delete comment from PR:`, error.message);
453+
}
454+
}
455+
407456
module.exports = async ({ github, context, core }) => {
408457
const runID = process.env.WORKFLOW_RUN_ID;
409458
const runURL = process.env.WORKFLOW_RUN_URL;
459+
const conclusion = process.env.CONCLUSION;
460+
461+
// Check if workflow succeeded - if so, delete any existing retry comments and exit
462+
if (conclusion === 'success') {
463+
core.info('Workflow succeeded - deleting any existing retry analysis comments');
464+
await deleteRetryComment(github, context, core, runID);
465+
return;
466+
}
410467

411468
// Get workflow information and failed jobs
412469
const { failedJobs, workflowRun } = await getWorkflowInfo(github, context, core, runID);

.github/workflows/cancel.yml

Lines changed: 0 additions & 41 deletions
This file was deleted.

.github/workflows/retry.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
workflow_run:
55
workflows:
66
- Dev
7+
- Main
78
types:
89
- completed
910

@@ -16,7 +17,6 @@ permissions:
1617
jobs:
1718
retry:
1819
runs-on: ubuntu-latest
19-
if: ${{ github.event.workflow_run.conclusion == 'failure' || github.event.workflow_run.conclusion == 'cancelled' }}
2020
steps:
2121
- name: Checkout code
2222
uses: actions/checkout@v4
@@ -26,6 +26,7 @@ jobs:
2626
env:
2727
WORKFLOW_RUN_ID: ${{ github.event.workflow_run.id }}
2828
WORKFLOW_RUN_URL: ${{ github.event.workflow_run.html_url }}
29+
CONCLUSION: ${{ github.event.workflow_run.conclusion }}
2930
with:
3031
github-token: ${{ github.token }}
3132
script: |

0 commit comments

Comments
 (0)