name: CI

on:
  push:
    branches: [main]
    paths-ignore:
      - 'timegpt-docs/**'
  pull_request:
    branches: [main]
    paths-ignore:
      - 'timegpt-docs/**'

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

env:
  NIXTLA_API_KEY: ${{ secrets.NIXTLA_DEV_API_KEY }}
  NIXTLA_BASE_URL: ${{ secrets.NIXTLA_DEV_BASE_URL }}
  NIXTLA_API_KEY_CUSTOM: ${{ secrets.NIXTLA_API_KEY_CUSTOM }}
  NIXTLA_BASE_URL_CUSTOM: ${{ secrets.NIXTLA_BASE_URL_CUSTOM }}
  API_KEY_FRED: ${{ secrets.API_KEY_FRED }}

jobs:
  check-import:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
    steps:
      - name: Clone repo
        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

      - name: Set up python
        uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # 5.4.0
        with:
          python-version: ${{ matrix.python-version }}

      - name: Install nixtla
        run: pip install uv && uv pip install --system .

      - name: Check import
        run: python -c "from nixtla import NixtlaClient"

  run-notebooks-test:
    runs-on: nixtla-linux-large-public
    timeout-minutes: 60
    strategy:
      fail-fast: false
      matrix:
        python-version: ["3.11"]
    steps:
      - name: Clone repo
        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

      - name: Set up python
        uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # 5.4.0
        with:
          python-version: ${{ matrix.python-version }}

      - name: Install pip requirements
        run: pip install uv && uv pip install --system ".[dev,distributed]"

      - name: Run nbconvert
        run: |
          find nbs/docs/ -name "*.ipynb" -print0 | while IFS= read -r -d '' nb; do
            if [[ "$(basename "$nb")" == "19_computing_at_scale_ray_distributed.ipynb" ]]; then
              echo "Skipping $nb..."
              continue
            fi
            echo "Running $nb..."
            jupyter nbconvert --to notebook --execute --inplace "$nb"
          done
