Skip to content

simpler cov

simpler cov #110

Workflow file for this run

name: CI
on:
push:
branches:
- main
- master
pull_request:
branches:
- main
- master
env:
LANG: "en_US.utf-8"
LC_ALL: "en_US.utf-8"
PYTHONIOENCODING: "UTF-8"
jobs:
test:
name: Tests (Python ${{ matrix.python-version }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y graphviz imagemagick tmux fd-find ripgrep
# Create symlinks for fd (Ubuntu packages it as fd-find)
sudo ln -sf /usr/bin/fdfind /usr/local/bin/fd
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
version: "latest"
- name: Install just
uses: extractions/setup-just@v3
- name: Install dependencies
run: uv sync
- name: Run tests with coverage
run: |
uv run coverage run --rcfile=config/coverage.pytest.ini -m pytest tests -c config/pytest.ini
uv run coverage combine
uv run coverage report --precision=2
uv run coverage xml
docs:
name: Build and Deploy Documentation
runs-on: ubuntu-latest
needs: test
# Only run on main/master branch pushes
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for git-changelog
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y graphviz imagemagick tmux fd-find ripgrep
# Create symlinks for fd (Ubuntu packages it as fd-find)
sudo ln -sf /usr/bin/fdfind /usr/local/bin/fd
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
version: "latest"
- name: Install just
uses: extractions/setup-just@v3
- name: Install dependencies
run: uv sync
- name: Build documentation
run: just docs
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./site
cname: ${{ vars.DOCS_CNAME }} # Optional: set this in repository variables if you have a custom domain
coverage-badge:
name: Update Coverage Badge
runs-on: ubuntu-latest
needs: test
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y graphviz imagemagick tmux fd-find ripgrep
# Create symlinks for fd (Ubuntu packages it as fd-find)
sudo ln -sf /usr/bin/fdfind /usr/local/bin/fd
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
version: "latest"
- name: Install just
uses: extractions/setup-just@v3
- name: Install dependencies
run: uv sync
- name: Generate coverage report
run: |
uv run coverage run --rcfile=config/coverage.pytest.ini -m pytest tests -c config/pytest.ini
uv run coverage combine
uv run coverage report --precision=2 > coverage_report.txt
- name: Extract coverage percentage
id: coverage
run: |
COVERAGE=$(grep "TOTAL" coverage_report.txt | awk '{print $4}' | sed 's/%//' | head -1)
echo "Coverage: $COVERAGE%"
echo "percentage=$COVERAGE" >> $GITHUB_OUTPUT
- name: Create coverage badge
run: |
COVERAGE=$(grep "TOTAL" coverage_report.txt | awk '{print $4}' | sed 's/%//' | head -1)
echo "Coverage: $COVERAGE%"
COLOR="red"
if (( $(echo "$COVERAGE > 80" | bc -l) )); then COLOR="brightgreen"; fi
if (( $(echo "$COVERAGE > 60 && $COVERAGE <= 80" | bc -l) )); then COLOR="yellow"; fi
# Create a simple coverage badge URL for README
echo "Add this to your README:"
echo "[![Coverage](https://img.shields.io/badge/coverage-${COVERAGE}%25-${COLOR})](https://github.com/axiros/docutools/actions/workflows/ci.yml)"