Files
ci-workflows/.github/workflows/python-uv-ci.yml
2026-01-04 17:46:06 +01:00

125 lines
3.3 KiB
YAML

name: Python UV Quality
on:
workflow_call:
inputs:
python_version:
type: string
default: "3.13"
uv_version:
type: string
default: "latest"
working_directory:
type: string
default: "."
cache_dependency_path:
type: string
default: "uv.lock"
env:
description: >
Multiline env vars, one per line: KEY=VALUE
required: false
type: string
default: ""
uv_sync_args:
type: string
default: "--frozen --dev"
format_command:
type: string
default: "uv run ruff format --check ."
lint_command:
type: string
default: "uv run ruff check ."
typecheck_command:
type: string
default: "uv run mypy ."
test_command:
type: string
default: "uv run pytest"
secrets:
ssh_private_key:
required: false
ssh_known_hosts:
required: false
jobs:
quality:
runs-on: ubuntu-latest
permissions:
contents: read
defaults:
run:
working-directory: ${{ inputs.working_directory }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Load env vars
if: ${{ inputs.env != '' }}
run: |
while IFS= read -r line; do
[ -z "$line" ] && continue
case "$line" in \#*) continue;; esac
if [[ "$line" != *=* ]]; then
echo "Invalid env line: $line" >&2
exit 1
fi
echo "$line" >> "$GITHUB_ENV"
done <<< "${{ inputs.env }}"
- name: Start ssh-agent
if: ${{ secrets.ssh_private_key != '' }}
uses: webfactory/ssh-agent@v0.9.0
with:
ssh-private-key: ${{ secrets.ssh_private_key }}
- name: Add SSH known hosts
if: ${{ secrets.ssh_known_hosts != '' }}
run: |
mkdir -p ~/.ssh
printf '%s\n' "${{ secrets.ssh_known_hosts }}" >> ~/.ssh/known_hosts
chmod 644 ~/.ssh/known_hosts
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python_version }}
- name: Install uv
env:
UV_VERSION: ${{ inputs.uv_version }}
run: |
python -m pip install --upgrade pip
if [ -z "$UV_VERSION" ] || [ "$UV_VERSION" = "latest" ]; then
python -m pip install uv
else
python -m pip install "uv==$UV_VERSION"
fi
- name: Cache uv downloads
uses: actions/cache@v4
with:
path: ~/.cache/uv
key: uv-${{ runner.os }}-${{ hashFiles(inputs.cache_dependency_path) }}
restore-keys: |
uv-${{ runner.os }}-
- name: Sync dependencies
run: uv sync ${{ inputs.uv_sync_args }}
- name: Run format check
if: ${{ inputs.format_command != '' }}
run: ${{ inputs.format_command }}
- name: Run lint
if: ${{ inputs.lint_command != '' }}
run: ${{ inputs.lint_command }}
- name: Run typecheck
if: ${{ inputs.typecheck_command != '' }}
run: ${{ inputs.typecheck_command }}
- name: Run tests
if: ${{ inputs.test_command != '' }}
run: ${{ inputs.test_command }}