Improve debug logging #86
This file contains 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: Tests | |
on: | |
push: | |
paths: | |
- '**/*.py' | |
pull_request: | |
paths: | |
- '**/*.py' | |
workflow_dispatch: | |
jobs: | |
tests: | |
name: Run Tests | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python 3.12 | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.12' | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements.test.txt | |
pip install pytest pytest-cov | |
- name: Run tests with coverage | |
run: | | |
python -m pytest --cov --cov-report json | |
- name: Fail if coverage under 95% | |
run: | | |
# Load coverage percentage from coverage.json | |
coverage_percent=$(python -c 'import json; print(json.load(open("coverage.json"))["totals"]["percent_covered"])') | |
echo "Coverage percentage: ${coverage_percent}%" | |
# Check if coverage is below the threshold | |
if (( $(echo "${coverage_percent} < 95" | bc -l) )); then | |
echo "Test coverage under 95%, was ${coverage_percent}%" | |
exit 1 | |
else | |
echo "Coverage meets the threshold." | |
fi | |
- name: Upload .coverage for main branch | |
if: github.ref == 'refs/heads/main' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: coverage-data | |
path: .coverage | |
update-coverage-badge: | |
name: Update Coverage Badge | |
runs-on: ubuntu-latest | |
needs: tests | |
if: github.ref == 'refs/heads/main' | |
outputs: | |
badge-success: ${{ steps.badge-output.outputs.success }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Download .coverage | |
uses: actions/download-artifact@v4 | |
with: | |
name: coverage-data | |
- name: Set up Python 3.12 | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.12' | |
- name: Install setuptools and coverage-badge | |
run: | | |
pip install setuptools coverage-badge | |
- name: Generate coverage badge | |
id: badge-output | |
continue-on-error: true | |
run: | | |
mkdir -p badges | |
if coverage-badge -o badges/coverage.svg; then | |
echo "success=true" >> $GITHUB_OUTPUT | |
else | |
echo "success=false" >> $GITHUB_OUTPUT | |
echo "::warning::Failed to generate coverage badge." | |
fi | |
- name: Upload coverage badge for gh-pages | |
if: steps.badge-output.outputs.success == 'true' | |
uses: actions/upload-artifact@v4 | |
with: | |
name: coverage-badge | |
path: badges/coverage.svg | |
commit-coverage-badge: | |
name: Commit Coverage Badge | |
runs-on: ubuntu-latest | |
needs: update-coverage-badge | |
if: github.ref == 'refs/heads/main' && needs.update-coverage-badge.outputs.badge-success == 'true' | |
permissions: | |
contents: write | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
ref: gh-pages | |
- name: Download coverage badge | |
uses: actions/download-artifact@v4 | |
with: | |
name: coverage-badge | |
path: badges | |
- name: Deploy Badge to gh-pages | |
uses: stefanzweifel/git-auto-commit-action@v5 | |
with: | |
commit_message: "Update coverage badge [skip ci]" | |
branch: gh-pages | |
file_pattern: badges/coverage.svg |