# Copyright © SixtyFPS GmbH <info@slint.dev>
# SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0

name: Python Test (Reusable)

on:
    workflow_call:
      inputs:
        name:
            description: 'Name of the job'
            required: true
            type: string
        os:
            description: 'Operating system to run on'
            required: true
            type: string

env:
    DYLD_FRAMEWORK_PATH: /Users/runner/work/slint/Qt/5.15.2/clang_64/lib
    QT_QPA_PLATFORM: offscreen
    RUSTFLAGS: -D warnings
    CARGO_PROFILE_DEV_DEBUG: 0
    CARGO_INCREMENTAL: false
    RUST_BACKTRACE: full
    SLINT_BACKEND: testing
    MATURIN_PEP517_ARGS: --features backend-testing

jobs:
    python_test:
        name: ${{ inputs.name }}
        runs-on: ${{ inputs.os }}
        steps:
            - uses: actions/checkout@v6
            - uses: ./.github/actions/install-linux-dependencies
            - uses: ./.github/actions/setup-rust
              with:
                  key: x-python-v0-${{ steps.node-install.outputs.node-version }} # the cache key consists of a manually bumpable version and the node version, as the cached rustc artifacts contain linking information where to find node.lib, which is in a versioned directory.
            - uses: actions/setup-python@v6
              with:
                  python-version: "3.12"
            - name: Install uv
              uses: astral-sh/setup-uv@v7
            - name: Build and sync environment
              working-directory: api/python/slint
              run: uv sync
            - name: Run ty
              working-directory: api/python/slint
              run: uvx ty check
            - name: Run ruff linter
              working-directory: api/python/slint
              run: uv tool run ruff check
            - name: Run ruff linter
              working-directory: api/python/briefcase
              run: uv tool run ruff check
            - name: Run python tests
              working-directory: api/python/slint
              run: uv run pytest -s -v
            - name: Run python test driver
              run: cargo test -p test-driver-python
