Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions .github/workflows/python-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Python CI contract: runs `bash scripts/check.sh <target>` of the caller repository, so lint and test commands
# live in the repository (one contract, same command locally and in CI). Tool versions come from the caller's uv.lock.
# Concurrency is owned by the calling workflow, as for the other reusable workflows of this repository.
name: Python check

on:
workflow_call:
inputs:
target:
description: check.sh target, lint or test; any other value fails before the job starts work
required: true
type: string
python-version:
description: Python version installed by setup-uv
default: '3.12'
type: string
runs-on:
description: Runner label
default: ubuntu-latest
type: string
pre-install-command:
description: Shell command run before uv sync (system packages, for example)
default: ''
type: string
env:
description: Lines KEY=VALUE written to GITHUB_ENV before the check
default: ''
type: string
uv-sync-args:
description: Extra arguments passed to uv sync (extras, groups), split on whitespace; no quoting or globbing
default: ''
type: string
coverage-artifact:
description: Artifact name uploading coverage.xml (target test only); use the coverage-* form read by coverage.yml
default: ''
type: string
timeout-minutes:
description: Job timeout in minutes
default: 15
type: number

permissions:
contents: read

jobs:
check:
runs-on: ${{ inputs.runs-on }}
timeout-minutes: ${{ inputs.timeout-minutes }}
steps:
- name: Validate inputs
env:
TARGET: ${{ inputs.target }}
COVERAGE_ARTIFACT: ${{ inputs.coverage-artifact }}
run: |
case "$TARGET" in
lint|test) ;;
*) echo "::error::target must be lint or test, got '$TARGET'"; exit 1 ;;
esac
if [[ -n "$COVERAGE_ARTIFACT" && "$TARGET" != test ]]; then
echo "::error::coverage-artifact applies to target test only"; exit 1
fi
if [[ -n "$COVERAGE_ARTIFACT" && "$COVERAGE_ARTIFACT" != coverage-* ]]; then
echo "::error::coverage-artifact must match coverage-* to be read by coverage.yml"; exit 1
fi
- uses: actions/checkout@v5
with:
persist-credentials: false
- name: Write environment
if: ${{ inputs.env != '' }}
env:
ENV_LINES: ${{ inputs.env }}
run: |
while IFS= read -r line; do
line=${line%$'\r'}
[[ -z "$line" ]] && continue
if [[ ! "$line" =~ ^[A-Za-z_][A-Za-z0-9_]*= ]]; then
echo "::error::env lines must be KEY=VALUE"; exit 1
fi
printf '%s\n' "$line" >> "$GITHUB_ENV"
done <<< "$ENV_LINES"
- name: Pre-install command
if: ${{ inputs.pre-install-command != '' }}
env:
PRE_INSTALL: ${{ inputs.pre-install-command }}
run: bash -euo pipefail -c "$PRE_INSTALL"
- uses: astral-sh/setup-uv@2a39bcff78b189a5800d31cfcf0205c7a3e8381e # v10.4.1
with:
python-version: ${{ inputs.python-version }}
enable-cache: true
- name: Check
env:
TARGET: ${{ inputs.target }}
UV_SYNC_ARGS: ${{ inputs.uv-sync-args }}
run: |
read -r -a sync_args <<< "$UV_SYNC_ARGS"
uv sync --locked "${sync_args[@]}"
bash scripts/check.sh "$TARGET"
- name: Upload coverage
if: ${{ inputs.coverage-artifact != '' && inputs.target == 'test' }}
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.coverage-artifact }}
path: coverage.xml
if-no-files-found: error
Loading