Close Failure Issues on Success #441
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Close Failure Issues on Success | |
| on: | |
| workflow_run: | |
| workflows: | |
| - "AI Assistant CI/CD Pipeline" | |
| - "MCP Server CI/CD" | |
| - "Airflow DAG CI/CD" | |
| - "Deploy Documentation to GitHub Pages" | |
| types: | |
| - completed | |
| permissions: | |
| issues: write | |
| actions: read | |
| jobs: | |
| close-resolved-issues: | |
| runs-on: ubuntu-latest | |
| if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
| steps: | |
| - name: Get workflow run details | |
| id: workflow | |
| run: | | |
| echo "workflow_name=${{ github.event.workflow_run.name }}" >> $GITHUB_OUTPUT | |
| echo "workflow_url=${{ github.event.workflow_run.html_url }}" >> $GITHUB_OUTPUT | |
| echo "commit_sha=${{ github.event.workflow_run.head_sha }}" >> $GITHUB_OUTPUT | |
| echo "branch=${{ github.event.workflow_run.head_branch }}" >> $GITHUB_OUTPUT | |
| - name: Find and close related failure issues | |
| uses: actions/github-script@v8 | |
| with: | |
| script: | | |
| const workflowName = '${{ steps.workflow.outputs.workflow_name }}'; | |
| const workflowUrl = '${{ steps.workflow.outputs.workflow_url }}'; | |
| const commitSha = '${{ steps.workflow.outputs.commit_sha }}'; | |
| const branch = '${{ steps.workflow.outputs.branch }}'; | |
| // Search for open issues with ci-failure label and matching workflow name | |
| const issues = await github.rest.issues.listForRepo({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| state: 'open', | |
| labels: 'ci-failure', | |
| per_page: 100 | |
| }); | |
| const matchingIssues = issues.data.filter(issue => | |
| issue.title.includes(workflowName) | |
| ); | |
| if (matchingIssues.length === 0) { | |
| console.log(`No open failure issues found for workflow: ${workflowName}`); | |
| return; | |
| } | |
| // Close matching issues with a success comment | |
| for (const issue of matchingIssues) { | |
| const comment = `### ✅ Workflow Recovered | |
| The **${workflowName}** workflow is now passing! | |
| **Success run:** [View Logs](${workflowUrl}) | |
| **Branch:** \`${branch}\` | |
| **Commit:** \`${commitSha.substring(0, 7)}\` | |
| **Recovered at:** ${new Date().toISOString()} | |
| Automatically closing this issue as the CI pipeline has recovered.`; | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: issue.number, | |
| body: comment | |
| }); | |
| await github.rest.issues.update({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: issue.number, | |
| state: 'closed', | |
| state_reason: 'completed' | |
| }); | |
| console.log(`✅ Closed issue #${issue.number}: ${issue.title}`); | |
| } | |
| console.log(`Closed ${matchingIssues.length} issue(s) for recovered workflow: ${workflowName}`); |