Add comprehensive testing summary documentation #3
Workflow file for this run
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: C++ Unit Tests with Coverage | |
| on: | |
| push: | |
| branches: [ main, develop, copilot/** ] | |
| pull_request: | |
| branches: [ main, develop ] | |
| workflow_dispatch: | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Install dependencies | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y \ | |
| cmake \ | |
| g++ \ | |
| libopenmpi-dev \ | |
| openmpi-bin \ | |
| petsc-dev \ | |
| lcov | |
| - name: Configure CMake | |
| working-directory: ${{github.workspace}}/code/cpp | |
| run: | | |
| mkdir -p build | |
| cd build | |
| cmake -DENABLE_COVERAGE=ON .. | |
| - name: Build tests | |
| working-directory: ${{github.workspace}}/code/cpp/build | |
| run: make -j$(nproc) unit_tests | |
| - name: Run tests | |
| working-directory: ${{github.workspace}}/code/cpp/build | |
| run: ./tests/unit_tests | |
| - name: Generate coverage report | |
| working-directory: ${{github.workspace}}/code/cpp/build | |
| run: | | |
| # Capture coverage data | |
| lcov --capture --directory . --output-file coverage.info --ignore-errors mismatch | |
| # Filter out system files and test files | |
| lcov --remove coverage.info '/usr/*' '*/build/_deps/*' '*/tests/*' \ | |
| --output-file coverage_filtered.info --ignore-errors unused | |
| # Generate HTML report | |
| genhtml coverage_filtered.info --output-directory coverage_report | |
| # Print summary | |
| echo "## Code Coverage Summary" >> $GITHUB_STEP_SUMMARY | |
| lcov --summary coverage_filtered.info 2>&1 | tee -a $GITHUB_STEP_SUMMARY | |
| - name: Upload coverage report | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: coverage-report | |
| path: ${{github.workspace}}/code/cpp/build/coverage_report/ | |
| retention-days: 30 | |
| - name: Comment coverage on PR | |
| if: github.event_name == 'pull_request' | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| const coverage = fs.readFileSync('${{github.workspace}}/code/cpp/build/coverage_filtered.info', 'utf8'); | |
| // Parse coverage data | |
| const lines = coverage.match(/LF:(\d+)/g); | |
| const linesHit = coverage.match(/LH:(\d+)/g); | |
| if (lines && linesHit) { | |
| const totalLines = lines.reduce((sum, l) => sum + parseInt(l.split(':')[1]), 0); | |
| const hitLines = linesHit.reduce((sum, l) => sum + parseInt(l.split(':')[1]), 0); | |
| const percentage = totalLines > 0 ? ((hitLines / totalLines) * 100).toFixed(2) : 0; | |
| const comment = `## Test Results ✅\n\n` + | |
| `All tests passed! 🎉\n\n` + | |
| `**Coverage:** ${percentage}% (${hitLines}/${totalLines} lines)\n\n` + | |
| `[View detailed coverage report](https://github.com/${{github.repository}}/actions/runs/${{github.run_id}})`; | |
| github.rest.issues.createComment({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: comment | |
| }); | |
| } |