|
| 1 | +# Copyright (c) 2022-2025, The Isaac Lab Project Developers (https://github.com/isaac-sim/IsaacLab/blob/main/CONTRIBUTORS.md). |
| 2 | +# All rights reserved. |
| 3 | +# |
| 4 | +# SPDX-License-Identifier: BSD-3-Clause |
| 5 | + |
| 6 | +name: Test Results Reporter |
| 7 | + |
| 8 | +on: |
| 9 | + workflow_run: |
| 10 | + workflows: ["Build and Test"] |
| 11 | + types: [completed] |
| 12 | + |
| 13 | +# This workflow runs with repository permissions |
| 14 | +permissions: |
| 15 | + contents: read |
| 16 | + pull-requests: write |
| 17 | + checks: write |
| 18 | + issues: read |
| 19 | + |
| 20 | +jobs: |
| 21 | + report-test-results: |
| 22 | + runs-on: ubuntu-latest |
| 23 | + if: ${{ github.event.workflow_run.conclusion == 'success' || github.event.workflow_run.conclusion == 'failure' }} |
| 24 | + |
| 25 | + steps: |
| 26 | + - name: Checkout Code |
| 27 | + uses: actions/checkout@v4 |
| 28 | + with: |
| 29 | + fetch-depth: 0 |
| 30 | + |
| 31 | + - name: Extract Workflow Information |
| 32 | + id: workflow-info |
| 33 | + run: | |
| 34 | + if [ "${{ github.event.workflow_run.event }}" == "pull_request" ]; then |
| 35 | + PR_NUMBER=$(echo "${{ github.event.workflow_run.head_branch }}" | grep -oE 'pr-([0-9]+)' | cut -d'-' -f2 || echo "") |
| 36 | + if [ -z "$PR_NUMBER" ]; then |
| 37 | + # Try to get PR number from workflow run data |
| 38 | + PR_NUMBER="${{ github.event.workflow_run.pull_requests[0].number }}" |
| 39 | + fi |
| 40 | + echo "pr-number=$PR_NUMBER" >> $GITHUB_OUTPUT |
| 41 | + echo "is-pr=true" >> $GITHUB_OUTPUT |
| 42 | + echo "Found PR number: $PR_NUMBER" |
| 43 | + else |
| 44 | + echo "is-pr=false" >> $GITHUB_OUTPUT |
| 45 | + echo "Not a PR event: ${{ github.event.workflow_run.event }}" |
| 46 | + fi |
| 47 | +
|
| 48 | + - name: Download Test Artifacts |
| 49 | + uses: actions/download-artifact@v4 |
| 50 | + with: |
| 51 | + name: test-results-pr-${{ steps.workflow-info.outputs.pr-number }} |
| 52 | + path: reports/ |
| 53 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 54 | + run-id: ${{ github.event.workflow_run.id }} |
| 55 | + continue-on-error: true |
| 56 | + if: steps.workflow-info.outputs.is-pr == 'true' |
| 57 | + |
| 58 | + - name: Validate Test Results |
| 59 | + id: validate-results |
| 60 | + run: | |
| 61 | + if [ -f "reports/combined-results.xml" ]; then |
| 62 | + echo "results-exist=true" >> $GITHUB_OUTPUT |
| 63 | + echo "✅ Test results found" |
| 64 | + else |
| 65 | + echo "results-exist=false" >> $GITHUB_OUTPUT |
| 66 | + echo "❌ No test results found" |
| 67 | + fi |
| 68 | +
|
| 69 | + - name: Publish Test Results Report |
| 70 | + if: steps.validate-results.outputs.results-exist == 'true' && steps.workflow-info.outputs.is-pr == 'true' |
| 71 | + uses: dorny/test-reporter@v1 |
| 72 | + with: |
| 73 | + name: IsaacLab Test Results |
| 74 | + path: reports/combined-results.xml |
| 75 | + reporter: java-junit |
| 76 | + fail-on-error: false |
| 77 | + only-summary: false |
| 78 | + max-annotations: '25' |
| 79 | + report-title: "IsaacLab Test Results (PR #${{ steps.workflow-info.outputs.pr-number }})" |
| 80 | + |
| 81 | + - name: Create Test Summary Comment |
| 82 | + if: steps.validate-results.outputs.results-exist == 'true' && steps.workflow-info.outputs.is-pr == 'true' |
| 83 | + uses: EnricoMi/publish-unit-test-result-action@v2 |
| 84 | + with: |
| 85 | + files: "reports/combined-results.xml" |
| 86 | + check_name: "Tests Summary" |
| 87 | + comment_mode: changes |
| 88 | + comment_title: "Test Results Summary (PR #${{ steps.workflow-info.outputs.pr-number }})" |
| 89 | + report_individual_runs: false |
| 90 | + deduplicate_classes_by_file_name: true |
| 91 | + compare_to_earlier_commit: false |
| 92 | + fail_on: errors |
| 93 | + action_fail_on_inconclusive: true |
| 94 | + |
| 95 | + - name: Monitor Failed Workflows |
| 96 | + if: steps.workflow-info.outputs.is-pr == 'false' && github.event.workflow_run.conclusion == 'failure' |
| 97 | + uses: actions/github-script@v7 |
| 98 | + with: |
| 99 | + script: | |
| 100 | + console.log('Non-PR workflow failed:', '${{ github.event.workflow_run.html_url }}'); |
| 101 | + console.log('Branch:', '${{ github.event.workflow_run.head_branch }}'); |
| 102 | + console.log('Event:', '${{ github.event.workflow_run.event }}'); |
| 103 | +
|
| 104 | + // Could add logic here to: |
| 105 | + // - Create issues for failed main/devel builds |
| 106 | + // - Send notifications |
| 107 | + // - Generate reports for scheduled runs |
| 108 | +
|
| 109 | + - name: Handle Missing Test Results |
| 110 | + if: steps.validate-results.outputs.results-exist == 'false' && steps.workflow-info.outputs.is-pr == 'true' |
| 111 | + uses: actions/github-script@v7 |
| 112 | + with: |
| 113 | + script: | |
| 114 | + const prNumber = ${{ steps.workflow-info.outputs.pr-number }}; |
| 115 | + if (!prNumber) { |
| 116 | + console.log('No PR number found, skipping comment'); |
| 117 | + return; |
| 118 | + } |
| 119 | +
|
| 120 | + const { data: comments } = await github.rest.issues.listComments({ |
| 121 | + owner: context.repo.owner, |
| 122 | + repo: context.repo.repo, |
| 123 | + issue_number: prNumber |
| 124 | + }); |
| 125 | +
|
| 126 | + const botComment = comments.find(comment => |
| 127 | + comment.user.type === 'Bot' && |
| 128 | + comment.body.includes('Test Results Summary') |
| 129 | + ); |
| 130 | +
|
| 131 | + if (!botComment) { |
| 132 | + await github.rest.issues.createComment({ |
| 133 | + owner: context.repo.owner, |
| 134 | + repo: context.repo.repo, |
| 135 | + issue_number: prNumber, |
| 136 | + body: `## Test Results Summary (PR #${prNumber}) |
| 137 | +
|
| 138 | + ⚠️ **No test results found** |
| 139 | +
|
| 140 | + The build completed, but no test results were uploaded as artifacts. |
| 141 | +
|
| 142 | + This could be due to: |
| 143 | + - Tests not running in this PR |
| 144 | + - Test results not being generated |
| 145 | + - Artifact upload issues |
| 146 | + - Workflow failure before test completion |
| 147 | +
|
| 148 | + Please check the original workflow run for more details: ${{ github.event.workflow_run.html_url }}` |
| 149 | + }); |
| 150 | + } |
0 commit comments