name: Checks

on:
  pull_request:
    branches:
      - main
  push:
    branches:
      - main
  
  workflow_dispatch:

jobs:
  lint:
    name: Formatting
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v4
        with: 
          fetch-depth: 0

      - name: Install linters
        run: pip install -r .meta/requirements/requirements-lint.txt

      - name: Run Format Checks
        run: make format-check RUN_GLOBAL=1

  test:
    name: Test
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
        pkg:
          - torch: "1.13.1"
            numpy: "1.24.4"
            pandas: "2.0.3"
            group: "legacy"
          - torch: ""
            numpy: ""
            pandas: ""
            group: "latest"
          - torch: "None"
            numpy: ""
            pandas: ""
            group: "notorch"
        exclude:
          - python: "3.12"
            pkg:
              group: "legacy"
          - python: "3.13"
            pkg:
              group: "legacy"
    steps:
      - name: Checkout code
        uses: actions/checkout@v4
        with: 
          fetch-depth: 1

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


      - name: set up uv
        run: curl -LsSf https://astral.sh/uv/install.sh | sh
  
      - name: check dependencies
        run: make dep-check

      - name: install dependencies and package
        run: make dep

      - name: Install different numpy version
        if: ${{ matrix.pkg.numpy != '' }}
        run: uv pip install numpy==${{ matrix.pkg.numpy }}

      - name: Install different pandas version
        if: ${{ matrix.pkg.pandas != '' }}
        run: uv pip install pandas==${{ matrix.pkg.pandas }}

      - name: Install different pytorch version
        if: ${{ matrix.pkg.torch != '' && matrix.pkg.torch != 'None' }}
        run: |
          uv pip install torch==${{ matrix.pkg.torch }}+cpu --extra-index-url https://download.pytorch.org/whl/cpu

      - name: remove torch if testing torchless
        if: ${{ matrix.pkg.torch == 'None' }}
        run: uv pip uninstall torch

      - name: make info
        run: make info-long UV_NOSYNC=1

      - name: torch dep info
        run: make dep-check-torch UV_NOSYNC=1
        continue-on-error: true
      
      - name: format check
        run: make format-check UV_NOSYNC=1

      - name: tests
        if: ${{ matrix.pkg.torch != 'None' }}
        run: make test UV_NOSYNC=1

      - name: tests without torch
        if: ${{ matrix.pkg.torch == 'None' }}
        run: make test-notorch UV_NOSYNC=1

      # - name: tests in strict mode
      #   # TODO: until zanj ported to 3.8 and 3.9
      #   if: ${{ matrix.python != '3.8' && matrix.python != '3.9' }}
      #   run: make test WARN_STRICT=1 RUN_GLOBAL=1

      - name: check typing
        if: ${{ matrix.python != '3.8' }}
        run: make typing
