# run tests
test:
    uv run pytest tests/ -x

# format and lint
fmt:
    uv run ruff format src/ tests/
    uv run ruff check src/ tests/ --fix

# type check
check:
    uv run ty check

# tag the next alpha, build, publish to pypi (token from .env / ~/.env)
release:
    #!/usr/bin/env bash
    set -euo pipefail
    if [ -f .env ]; then source .env; elif [ -f ~/.env ]; then source ~/.env; fi
    export UV_PUBLISH_TOKEN="${UV_PUBLISH_TOKEN:-${PYPI_API_TOKEN:?no pypi token in .env}}"
    if [ -n "$(git status --porcelain)" ]; then
        echo "working tree is dirty — commit first" >&2
        exit 1
    fi
    last=$(git tag -l 'v*' --sort=-v:refname | head -1)
    if [[ $last =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)a([0-9]+)$ ]]; then
        next="v${BASH_REMATCH[1]}.${BASH_REMATCH[2]}.${BASH_REMATCH[3]}a$((BASH_REMATCH[4] + 1))"
    elif [[ $last =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
        next="v${BASH_REMATCH[1]}.$((BASH_REMATCH[2] + 1)).0a1"
    else
        next="v0.2.0a1"
    fi
    just test
    git tag "$next"
    rm -rf dist && uv build
    uv publish
    echo
    echo "published ${next#v} — try it:  uvx absolutelyright@${next#v}"
