Auto-Create Issue on Failure #7
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: Auto-Create Issue on Failure | |
| on: | |
| workflow_run: | |
| workflows: ["CI Pipeline"] | |
| types: [completed] | |
| permissions: | |
| issues: write | |
| actions: read | |
| contents: read | |
| jobs: | |
| create-issue-on-failure: | |
| name: Create Issue for Failed Workflow | |
| runs-on: ubuntu-latest | |
| if: ${{ github.event.workflow_run.conclusion == 'failure' }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Extract failure information | |
| id: failure_info | |
| run: | | |
| # Get workflow details | |
| WORKFLOW_NAME="${{ github.event.workflow_run.name }}" | |
| RUN_NUMBER="${{ github.event.workflow_run.run_number }}" | |
| RUN_ID="${{ github.event.workflow_run.id }}" | |
| BRANCH="${{ github.event.workflow_run.head_branch }}" | |
| COMMIT_SHA="${{ github.event.workflow_run.head_sha }}" | |
| ACTOR="${{ github.event.workflow_run.actor.login }}" | |
| # Create short SHA | |
| SHORT_SHA="${COMMIT_SHA:0:7}" | |
| # Generate issue title | |
| ISSUE_TITLE="🔴 CI Failure: ${WORKFLOW_NAME} #${RUN_NUMBER} on ${BRANCH}" | |
| # Create issue body | |
| cat << EOF > issue_body.md | |
| ## 🚨 Workflow Failure Detected | |
| The **${WORKFLOW_NAME}** workflow has failed. | |
| ### Details | |
| | Field | Value | | |
| |-------|-------| | |
| | **Workflow** | ${WORKFLOW_NAME} | | |
| | **Run Number** | #${RUN_NUMBER} | | |
| | **Branch** | \`${BRANCH}\` | | |
| | **Commit** | \`${SHORT_SHA}\` | | |
| | **Triggered by** | @${ACTOR} | | |
| | **Run URL** | [View Failed Run](https://github.com/${{ github.repository }}/actions/runs/${RUN_ID}) | | |
| ### 🔍 Investigation Steps | |
| 1. **Review the logs**: Click on the run URL above to see detailed error messages | |
| 2. **Check recent changes**: Review the commit that triggered this failure | |
| 3. **Reproduce locally**: | |
| \`\`\`bash | |
| git checkout ${SHORT_SHA} | |
| cd rust_blender_anim | |
| ./health_check.sh | |
| \`\`\` | |
| 4. **Common failure points**: | |
| - ❌ Health checks failed | |
| - ❌ Compilation errors | |
| - ❌ Clippy warnings | |
| - ❌ Blender installation/rendering issues | |
| ### 📋 Next Steps | |
| - [ ] Identify the root cause | |
| - [ ] Fix the issue | |
| - [ ] Run health checks locally | |
| - [ ] Push fix and verify CI passes | |
| - [ ] Close this issue | |
| --- | |
| **Auto-generated by workflow failure detection** | |
| *This issue was automatically created when the CI pipeline failed.* | |
| EOF | |
| # Export for next step | |
| echo "title=${ISSUE_TITLE}" >> $GITHUB_OUTPUT | |
| # Store body in environment file | |
| echo "ISSUE_BODY<<EOF" >> $GITHUB_ENV | |
| cat issue_body.md >> $GITHUB_ENV | |
| echo "EOF" >> $GITHUB_ENV | |
| - name: Check for existing open issue | |
| id: check_existing | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const workflowName = '${{ github.event.workflow_run.name }}'; | |
| const branch = '${{ github.event.workflow_run.head_branch }}'; | |
| // Search for open issues with similar title | |
| const issues = await github.rest.issues.listForRepo({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| state: 'open', | |
| labels: 'ci-failure', | |
| per_page: 100 | |
| }); | |
| // Check if there's already an open issue for this workflow and branch | |
| const existingIssue = issues.data.find(issue => | |
| issue.title.includes(workflowName) && | |
| issue.title.includes(branch) | |
| ); | |
| if (existingIssue) { | |
| console.log('Found existing issue:', existingIssue.number); | |
| return existingIssue.number; | |
| } | |
| return null; | |
| - name: Create or update issue | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const existingIssueNumber = ${{ steps.check_existing.outputs.result }}; | |
| const title = '${{ steps.failure_info.outputs.title }}'; | |
| const body = process.env.ISSUE_BODY; | |
| const runUrl = 'https://github.com/${{ github.repository }}/actions/runs/${{ github.event.workflow_run.id }}'; | |
| if (existingIssueNumber) { | |
| // Add comment to existing issue | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: existingIssueNumber, | |
| body: `## 🔄 Another Failure Detected\n\nThe workflow failed again in run [#${{ github.event.workflow_run.run_number }}](${runUrl})\n\n**Commit**: \`${{ github.event.workflow_run.head_sha }}\`.substring(0, 7)\`\n**Branch**: \`${{ github.event.workflow_run.head_branch }}\`` | |
| }); | |
| console.log('Added comment to existing issue #' + existingIssueNumber); | |
| } else { | |
| // Create new issue | |
| const issue = await github.rest.issues.create({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| title: title, | |
| body: body, | |
| labels: ['ci-failure', 'bug', 'automated'] | |
| }); | |
| console.log('Created new issue #' + issue.data.number); | |
| } | |
| - name: Notify in workflow summary | |
| run: | | |
| echo "## 🚨 CI Failure Detected" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "An issue has been created to track this failure." >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "**Workflow**: ${{ github.event.workflow_run.name }}" >> $GITHUB_STEP_SUMMARY | |
| echo "**Run**: #${{ github.event.workflow_run.run_number }}" >> $GITHUB_STEP_SUMMARY | |
| echo "**Branch**: ${{ github.event.workflow_run.head_branch }}" >> $GITHUB_STEP_SUMMARY |