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"
            group: "legacy"
          - torch: ""
            numpy: ""
            group: "latest"
        exclude:
          - python: "3.12"
            pkg:
              group: "legacy"
          - python: "3.13"
            pkg:
              group: "legacy"

        #   - python: "3.9"
        #     torch: "1.13.1"
        #     numpy: "1.21.2"
        #   - python: "3.10"
        #     torch: "1.13.1"
        #     numpy: "1.21.2"
        #   - python: "3.10"
        #     torch: "2.3.1"
        #   - python: "3.11"
        #     torch: "2.3.1"
        #   - python: "3.12"
        #     torch: "2.3.1"
        #   - python: "3.13"
        #     torch: "2.6.0"
    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 pytorch version
        if: ${{ matrix.pkg.torch != '' }}
        run: |
          uv pip install torch==${{ matrix.pkg.torch }}+cpu --extra-index-url https://download.pytorch.org/whl/cpu
      
      - name: Install different numpy version
        if: ${{ matrix.pkg.numpy != '' }}
        run: uv pip install numpy==${{ matrix.pkg.numpy }}
      
      - name: format check
        run: make format-check

      - name: tests
        run: make test

      # - 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
        run: make typing
