Skip to content

aggressive caching in workflows #112

aggressive caching in workflows

aggressive caching in workflows #112

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: Cache apt packages
uses: actions/cache@v4
with:
path: /var/cache/apt/archives
key: ${{ runner.os }}-apt-${{ hashFiles('.github/workflows/ci.yml') }}
restore-keys: |
${{ runner.os }}-apt-
- 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"
enable-cache: true
- name: Install just
uses: extractions/setup-just@v3
- name: Cache uv dependencies
uses: actions/cache@v4
with:
path: |
~/.cache/uv
.venv
key: ${{ runner.os }}-uv-${{ matrix.python-version }}-${{ hashFiles('pyproject.toml', 'uv.lock') }}
restore-keys: |
${{ runner.os }}-uv-${{ matrix.python-version }}-
${{ runner.os }}-uv-
- 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: Cache apt packages
uses: actions/cache@v4
with:
path: /var/cache/apt/archives
key: ${{ runner.os }}-apt-${{ hashFiles('.github/workflows/ci.yml') }}
restore-keys: |
${{ runner.os }}-apt-
- 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"
enable-cache: true
- name: Install just
uses: extractions/setup-just@v3
- name: Cache uv dependencies
uses: actions/cache@v4
with:
path: |
~/.cache/uv
.venv
key: ${{ runner.os }}-uv-3.11-${{ hashFiles('pyproject.toml', 'uv.lock') }}
restore-keys: |
${{ runner.os }}-uv-3.11-
${{ runner.os }}-uv-
- name: Install dependencies
run: uv sync
- name: Build documentation
run: |
just docs
# Ensure badge files are in the site directory
mkdir -p ./site/img
cp docs/img/badge_*.svg ./site/img/ 2>/dev/null || true
ls -la ./site/img/
- 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: Cache apt packages
uses: actions/cache@v4
with:
path: /var/cache/apt/archives
key: ${{ runner.os }}-apt-${{ hashFiles('.github/workflows/ci.yml') }}
restore-keys: |
${{ runner.os }}-apt-
- 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"
enable-cache: true
- name: Install just
uses: extractions/setup-just@v3
- name: Cache uv dependencies
uses: actions/cache@v4
with:
path: |
~/.cache/uv
.venv
key: ${{ runner.os }}-uv-3.11-${{ hashFiles('pyproject.toml', 'uv.lock') }}
restore-keys: |
${{ runner.os }}-uv-3.11-
${{ runner.os }}-uv-
- 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)"
- name: Commit coverage files
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add -f coverage.xml coverage_report.txt || true
git diff --staged --quiet || git commit -m "Update coverage reports" || true
git push || true