Skip to content

Fix warnings

Fix warnings #105

Workflow file for this run

name: Tests
on:
push:
paths:
- '**/*.py'
pull_request:
paths:
- '**/*.py'
workflow_dispatch:
jobs:
tests:
name: Run Tests
runs-on: ubuntu-latest
outputs:
badge-success: ${{ steps.generate_badge.outputs.success }}
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 setuptools coverage-badge
- 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: Generate coverage badge
id: generate_badge
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.generate_badge.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: tests
if: github.ref == 'refs/heads/main' && needs.tests.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