name: Dependencies Check

on:
  schedule:
    - cron: '43 3 * * 6,3'
  workflow_dispatch: {}

env:
  UV_FROZEN: true

permissions:
  contents: read

jobs:
  find_dependency_cases:
    runs-on: ubuntu-latest

    outputs:
      PYTHON_DEPENDENCY_CASES: ${{ steps.list-python-dependencies.outputs.PYTHON_DEPENDENCY_CASES }}

    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
        with:
          persist-credentials: false

      # no release versioning, see https://github.com/samuelcolvin/list-python-dependencies/issues/2
      - uses: samuelcolvin/list-python-dependencies@43f660fbd655f25c3e3ebd3165b09974bbf98e05
        id: list-python-dependencies
        with:
          mode: first-last

  test:
    name: Test py${{ matrix.python-version }} on ${{ matrix.PYTHON_DEPENDENCY_CASE }}

    needs:
      - find_dependency_cases

    strategy:
      fail-fast: true
      matrix:
        python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
        PYTHON_DEPENDENCY_CASE: ${{ fromJSON(needs.find_dependency_cases.outputs.PYTHON_DEPENDENCY_CASES) }}

    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
        with:
          persist-credentials: false

      - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
        with:
          python-version: ${{ matrix.python-version }}

      - run: pip install uv
      - run: uv sync --all-extras

      - run: uv pip install ${MATRIX_PYTHON_DEPENDENCY_CASE}
        env:
          MATRIX_PYTHON_DEPENDENCY_CASE: ${{ matrix.PYTHON_DEPENDENCY_CASE }}

      - run: uv pip freeze

      - run: make test
