Error Reporter #1
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: Error Reporter | |
| on: | |
| workflow_run: | |
| workflows: ["Test Suite", "CI/CD Pipeline"] | |
| types: | |
| - completed | |
| permissions: | |
| contents: read | |
| issues: write | |
| pull-requests: write | |
| jobs: | |
| report-errors: | |
| runs-on: ubuntu-latest | |
| if: ${{ github.event.workflow_run.conclusion == 'failure' }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Download artifacts | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const artifacts = await github.rest.actions.listWorkflowRunArtifacts({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| run_id: ${{ github.event.workflow_run.id }} | |
| }); | |
| console.log(`Found ${artifacts.data.artifacts.length} artifacts`); | |
| - name: Parse test results | |
| id: parse-results | |
| run: | | |
| echo "## Test Failure Summary" > error_summary.md | |
| echo "" >> error_summary.md | |
| echo "Workflow: ${{ github.event.workflow_run.name }}" >> error_summary.md | |
| echo "Run ID: ${{ github.event.workflow_run.id }}" >> error_summary.md | |
| echo "Branch: ${{ github.event.workflow_run.head_branch }}" >> error_summary.md | |
| echo "" >> error_summary.md | |
| # Export for use in other steps | |
| echo "summary_file=error_summary.md" >> $GITHUB_OUTPUT | |
| - name: Comment on PR (if applicable) | |
| if: github.event.workflow_run.event == 'pull_request' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| const summary = fs.readFileSync('error_summary.md', 'utf8'); | |
| const issue_number = context.payload.workflow_run.pull_requests[0]?.number; | |
| if (issue_number) { | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: issue_number, | |
| body: summary + '\n\n[View full logs](' + context.payload.workflow_run.html_url + ')' | |
| }); | |
| } | |
| - name: Create issue for persistent failures | |
| if: github.event.workflow_run.head_branch == 'main' || github.event.workflow_run.head_branch == 'master' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| const summary = fs.readFileSync('error_summary.md', 'utf8'); | |
| await github.rest.issues.create({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| title: `Test Failure in ${context.payload.workflow_run.name}`, | |
| body: summary + '\n\n[View full logs](' + context.payload.workflow_run.html_url + ')', | |
| labels: ['test-failure', 'automated'] | |
| }); |