name: Test requirements

on:
  pull_request:
    types:
      - opened
      - synchronize
      - reopened
      - ready_for_review
    paths:
      - requirements/core-requirements.yaml
      - requirements/skinny-requirements.yaml
      - requirements/gateway-requirements.yaml
      - .github/workflows/requirements.yml
  schedule:
    - cron: "0 13 * * *"

permissions:
  contents: read

concurrency:
  group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }}
  cancel-in-progress: true

env:
  MLFLOW_HOME: /home/runner/work/mlflow/mlflow
  MLFLOW_CONDA_HOME: /usr/share/miniconda
  SPARK_LOCAL_IP: localhost
  PYTHON_VERSION: "3.8"

defaults:
  run:
    shell: bash --noprofile --norc -exo pipefail {0}

jobs:
  skinny:
    runs-on: ubuntu-latest
    timeout-minutes: 10
    if: (github.event_name == 'schedule' && github.repository == 'mlflow-automation/mlflow') || (github.event_name == 'pull_request' && github.event.pull_request.draft == false)
    steps:
      - uses: actions/checkout@v3
        with:
          repository: ${{ github.event_name == 'schedule' && 'mlflow/mlflow' || null }}
          submodules: recursive
      - uses: ./.github/actions/setup-python
        with:
          python-version: ${{ env.PYTHON_VERSION }}
      - name: Install dev script dependencies
        run: |
          pip install -r dev/requirements.txt
      - uses: ./.github/actions/update-requirements
        if: github.event_name == 'schedule'
      - name: Install dependencies
        run: |
          source ./dev/install-common-deps.sh --skinny
      - name: Run tests
        run: |
          ./dev/run-python-skinny-tests.sh

  core:
    runs-on: ubuntu-latest
    timeout-minutes: 120
    if: (github.event_name == 'schedule' && github.repository == 'mlflow-automation/mlflow') || (github.event_name == 'pull_request' && github.event.pull_request.draft == false)
    steps:
      - uses: actions/checkout@v3
        with:
          repository: ${{ github.event_name == 'schedule' && 'mlflow/mlflow' || null }}
          submodules: recursive
      - uses: ./.github/actions/free-disk-space
      - uses: ./.github/actions/setup-python
        with:
          python-version: ${{ env.PYTHON_VERSION }}
      - uses: ./.github/actions/setup-pyenv
      - uses: ./.github/actions/setup-java
      - name: Install dev script dependencies
        run: |
          pip install -r dev/requirements.txt
      - uses: ./.github/actions/update-requirements
        if: github.event_name == 'schedule'
      - name: Install dependencies
        run: |
          source ./dev/install-common-deps.sh --ml
          pip install '.[gateway]'
      - name: Run tests
        run: |
          source dev/setup-ssh.sh
          pytest tests --quiet --requires-ssh --ignore-flavors \
            --ignore=tests/examples --ignore=tests/recipes --ignore=tests/evaluate \
            --ignore=tests/deployments