name: CI

on:
  push:
    branches:
      - main
      - develop
  pull_request:
    branches:
      - main
      - develop

jobs:
  test:
    runs-on: ubuntu-latest

    strategy:
      fail-fast: false
      matrix:
        python-version: ["3.10", "3.11", "3.12", "3.13"]

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python-version }}
          cache: 'pip'

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          python -m pip install .[dev]

      - name: Check ONNX Runtime providers
        run: |
          python -c "import onnxruntime as ort; print('Available providers:', ort.get_available_providers())"

      - name: Lint with ruff (if available)
        run: |
          pip install ruff || true
          ruff check . --exit-zero || true
        continue-on-error: true

      - name: Run tests
        run: pytest -v --tb=short

      - name: Test package imports
        run: |
          python -c "from uniface import RetinaFace, ArcFace, Landmark106, AgeGender; print('All imports successful')"

  build:
    runs-on: ubuntu-latest
    needs: test

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: "3.10"
          cache: 'pip'

      - name: Install build tools
        run: |
          python -m pip install --upgrade pip
          python -m pip install build

      - name: Build package
        run: python -m build

      - name: Check package
        run: |
          python -m pip install twine
          twine check dist/*

      - name: Upload build artifacts
        uses: actions/upload-artifact@v4
        with:
          name: dist-python-${{ github.sha }}
          path: dist/
          retention-days: 7

