Skip to content

Code Coverage

Code Coverage #138

Workflow file for this run

name: Code Coverage
on:
push:
branches: [main]
paths:
- 'cli/**'
- 'tests/**'
- 'pytest.ini'
- 'setup.cfg'
pull_request:
branches: [main]
paths:
- 'cli/**'
- 'tests/**'
- 'pytest.ini'
- 'setup.cfg'
schedule:
# Run daily at 2 AM UTC
- cron: '0 2 * * *'
jobs:
coverage:
name: Test Coverage Report
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.13'
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
pip install -e .
pip install pytest pytest-cov coverage
- name: Run tests with coverage
run: |
pytest tests/ \
--cov=cli \
--cov-report=term-missing \
--cov-report=html:htmlcov \
--cov-report=xml \
--cov-report=json \
--cov-branch \
-v
- name: Check coverage threshold
run: |
coverage report --fail-under=75
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
with:
files: ./coverage.xml
flags: unittests
name: codecov-umbrella
fail_ci_if_error: false
- name: Generate coverage badge
run: |
pip install coverage-badge
coverage-badge -o coverage.svg -f
- name: Upload coverage artifacts
uses: actions/upload-artifact@v4
if: always()
with:
name: coverage-reports
path: |
htmlcov/
coverage.xml
coverage.json
coverage.svg
- name: Comment PR with coverage
if: github.event_name == 'pull_request'
uses: py-cov-action/python-coverage-comment-action@v3
with:
GITHUB_TOKEN: ${{ github.token }}
- name: Archive coverage results
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage-archive-${{ github.run_number }}
path: htmlcov/
coverage-check:
name: Coverage Threshold Check
runs-on: ubuntu-latest
needs: coverage
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download coverage reports
uses: actions/download-artifact@v4
with:
name: coverage-reports
- name: Display coverage summary
run: |
echo "## Coverage Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "![Coverage Badge](./coverage.svg)" >> $GITHUB_STEP_SUMMARY
- name: Fail if coverage too low
run: |
if grep -q "statements=" coverage.json; then
python -c "
import json
with open('coverage.json') as f:
data = json.load(f)
total_coverage = data['totals']['percent_covered']
if total_coverage < 75:
print(f'Coverage {total_coverage}% is below 75% threshold')
exit(1)
else:
print(f'✓ Coverage {total_coverage}% meets threshold')
"
fi