Publish line and branch coverage reports in CI (#1564)

* Report line and branch coverage in CI

* docs: explain coverage reports and behavioral tests

* Calculate coverage percentages from counts for older versions
This commit is contained in:
Bas Nijholt 2026-09-06 17:09:35 +02:00 committed by GitHub
commit c19715dadd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 54 additions and 1 deletions

View file

@ -53,6 +53,7 @@ jobs:
core-version: ${{ matrix.core-version }}
- name: Run pytest
id: pytest
timeout-minutes: 60
run: |
export PYTHONPATH=${PYTHONPATH}:${PWD}
@ -64,7 +65,51 @@ jobs:
--timeout=9 \
--durations=10 \
--cov=homeassistant.components.adaptive_lighting \
--cov-branch \
--cov-report=term-missing \
--cov-report=xml \
--cov-report=json \
--cov-report=html \
-o console_output_style=count \
-p no:sugar \
tests/components/adaptive_lighting
- name: Write coverage summary
if: ${{ !cancelled() }}
env:
CORE_VERSION: ${{ matrix.core-version }}
PYTHON_VERSION: ${{ matrix.python-version }}
PYTEST_OUTCOME: ${{ steps.pytest.outcome }}
run: |
{
echo "### Coverage: Home Assistant ${CORE_VERSION}, Python ${PYTHON_VERSION}"
echo
if [[ -f core/coverage.json ]]; then
echo "| Metric | Executed | Total | Coverage |"
echo "| --- | ---: | ---: | ---: |"
jq -r '
def percent(covered; total):
if total == 0 then 100 else (covered / total * 10000 | round) / 100 end;
.totals
| "| Lines | \(.covered_lines) | \(.num_statements) | \(percent(.covered_lines; .num_statements))% |\n"
+ "| Branches | \(.covered_branches) | \(.num_branches) | \(percent(.covered_branches; .num_branches))% |"
' core/coverage.json
else
echo "Coverage JSON was not generated. See the pytest step for details."
fi
} >> "${GITHUB_STEP_SUMMARY}"
if [[ ! -f core/coverage.json && "${PYTEST_OUTCOME}" == "success" ]]; then
exit 1
fi
- name: Upload coverage reports
if: ${{ !cancelled() }}
uses: actions/upload-artifact@v7.0.1
with:
name: coverage-${{ matrix.core-version }}-py${{ matrix.python-version }}
path: |
core/coverage.xml
core/coverage.json
core/htmlcov/
if-no-files-found: warn