diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 59bf3cf..f7e8f78 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -281,6 +281,22 @@ jobs: coverage-rate-reduction-failure: false pycobertura-exception-failure: false togglable-report: false + # Test case for report-low-coverage-only: file_full_coverage.py (100%) should be excluded + - path: test-low-coverage-only.xml + threshold: 70 + fail: false + publish: true + diff: false + diff-branch: main + diff-storage: _xml_coverage_reports_low_coverage_only + coverage-summary-title: "Code Coverage Summary (low coverage only)" + exclude-detailed-coverage: false + uncovered-statements-increase-failure: false + new-uncovered-statements-failure: false + coverage-rate-reduction-failure: false + pycobertura-exception-failure: true + togglable-report: false + report-low-coverage-only: true steps: - name: Checkout Code 🛎 uses: actions/checkout@v4 @@ -302,3 +318,4 @@ jobs: coverage-rate-reduction-failure: ${{ matrix.reports.coverage-rate-reduction-failure }} pycobertura-exception-failure: ${{ matrix.reports.pycobertura-exception-failure }} togglable-report: ${{ matrix.reports.togglable-report }} + report-low-coverage-only: ${{ matrix.reports.report-low-coverage-only }} diff --git a/README.md b/README.md index e836632..64b2151 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,15 @@ Inisghts Engineering * `togglable-report`: - _Description_: Make the code coverage report togglable. + _Description_: Wrap the detailed coverage report in a collapsible `
` block in the PR comment, so it is hidden by default and can be expanded on demand. + + _Required_: `false` + + _Default_: `False` + +* `report-low-coverage-only`: + + _Description_: When `true`, the detailed coverage report will only include files where coverage is less than 100%. Files with full coverage are omitted to keep the report focused on files that need attention. The `TOTAL` summary line is always included regardless of this setting. Has no effect when `exclude-detailed-coverage` is `true`. _Required_: `false` diff --git a/action.yml b/action.yml index 3dc465c..240f2b0 100644 --- a/action.yml +++ b/action.yml @@ -81,6 +81,12 @@ inputs: description: Make the code coverage report togglable. required: false default: false + report-low-coverage-only: + description: | + When true, the detailed coverage report will only include files where + coverage is less than 100%. The TOTAL summary line is always included. + required: false + default: false exclude-detailed-coverage: description: | Whether a detailed coverage report should be excluded from the PR comment. @@ -121,6 +127,13 @@ runs: mkdir -p coverage-action cp ${{ inputs.path }} coverage-action/ pycobertura show ${{ inputs.path }} --output .coverage-output + if [[ "${{ inputs.report-low-coverage-only }}" == "true" ]] + then { + # Keep header lines, the TOTAL line, and any file with missed lines (Miss != 0) + awk 'NR<=2 || /^TOTAL / || $3 != 0' .coverage-output > .coverage-output.filtered + mv .coverage-output.filtered .coverage-output + } + fi cat .coverage-output shell: bash diff --git a/fixtures/README.md b/fixtures/README.md index 5c82408..ec07869 100644 --- a/fixtures/README.md +++ b/fixtures/README.md @@ -82,9 +82,15 @@ This directory contains test fixtures for the Code Coverage Report Action. Each #### `test-togglable-report.xml` - **Purpose**: Tests `togglable-report` flag -- **Coverage**: 85% line coverage +- **Coverage**: 85% line coverage (single file: `togglable_test_file.py`) - **Scenario**: Normal coverage report -- **Expected**: Should generate collapsible report format when flag is enabled +- **Expected**: When `togglable-report: true`, the detailed coverage table is wrapped in a collapsible `
` block in the PR comment + +#### `test-low-coverage-only.xml` +- **Purpose**: Tests `report-low-coverage-only` flag +- **Coverage**: 75% overall (3 files: `file_full_coverage.py` at 100%, `file_partial_coverage.py` at 60%, `file_low_coverage.py` at 30%) +- **Scenario**: Mix of fully-covered and partially-covered files +- **Expected**: When `report-low-coverage-only: true`, only `file_partial_coverage.py` and `file_low_coverage.py` appear in the report; `file_full_coverage.py` is omitted; the TOTAL line is always shown ### Comprehensive Testing @@ -111,7 +117,7 @@ The test matrix in `.github/workflows/test.yaml` includes test cases for: 3. **Positive cases**: Scenarios where failure flags should NOT trigger 4. **Combined scenarios**: Multiple flags enabled together 5. **Exception handling**: Both enabled and disabled exception failure modes -6. **Report formatting**: Togglable reports with and without detailed coverage +6. **Report formatting**: Togglable reports (collapsible `
`) with and without detailed coverage 7. **Edge cases**: Comprehensive testing with multiple files and varying coverage ## Usage diff --git a/fixtures/test-low-coverage-only.xml b/fixtures/test-low-coverage-only.xml new file mode 100644 index 0000000..3796a62 --- /dev/null +++ b/fixtures/test-low-coverage-only.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +