From 154851b9f11c426e81cdc93a760e64febd9c493f Mon Sep 17 00:00:00 2001 From: mignot Date: Wed, 2 Dec 2026 19:19:38 +0100 Subject: [PATCH 1/2] feat(python-check): add reusable python-check workflow Runs bash scripts/check.sh of the caller with uv, optional coverage.xml upload for coverage.yml. Co-Authored-By: Claude Sonnet 5.5 --- .github/workflows/python-check.yml | 103 +++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 .github/workflows/python-check.yml diff --git a/.github/workflows/python-check.yml b/.github/workflows/python-check.yml new file mode 100644 index 0000000..8bd41d1 --- /dev/null +++ b/.github/workflows/python-check.yml @@ -0,0 +1,103 @@ +# Python CI contract: runs `bash scripts/check.sh ` 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) + 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 + [[ -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: | + # shellcheck disable=SC2086 + uv sync --locked $UV_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 From ac8fe5b5da6919e8d7ea4ba78e9161abe50b3f8e Mon Sep 17 00:00:00 2001 From: mignot Date: Wed, 2 Dec 2026 19:20:39 +0100 Subject: [PATCH 2/2] fix(python-check): strip CR from env lines and split uv-sync-args without globbing Co-Authored-By: Claude Sonnet 5.5 --- .github/workflows/python-check.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/python-check.yml b/.github/workflows/python-check.yml index 8bd41d1..54afd07 100644 --- a/.github/workflows/python-check.yml +++ b/.github/workflows/python-check.yml @@ -27,7 +27,7 @@ on: default: '' type: string uv-sync-args: - description: Extra arguments passed to uv sync (extras, groups) + description: Extra arguments passed to uv sync (extras, groups), split on whitespace; no quoting or globbing default: '' type: string coverage-artifact: @@ -71,6 +71,7 @@ jobs: 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 @@ -91,8 +92,8 @@ jobs: TARGET: ${{ inputs.target }} UV_SYNC_ARGS: ${{ inputs.uv-sync-args }} run: | - # shellcheck disable=SC2086 - uv sync --locked $UV_SYNC_ARGS + 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' }}