name: Markdown tests

env:
  # enable colored output
  # https://github.com/pytest-dev/pytest/issues/7443
  PY_COLORS: 1
  UV_SYSTEM_PYTHON: 1

on:
  workflow_dispatch:

  pull_request:
    paths:
      - .github/workflows/markdown-tests.yaml
      - "docs/**"
      - pyproject.toml
      - Dockerfile

  push:
    branches:
      - main
    paths:
      - .github/workflows/markdown-tests.yaml
      - "src/prefect/**/*.py"
      - "tests/**/*.py"
      - pyproject.toml
      - Dockerfile

permissions:
  contents: read

# Limit concurrency by workflow/branch combination.
#
# For pull request builds, pushing additional changes to the
# branch will cancel prior in-progress and pending builds.
#
# For builds triggered on a branch push, additional changes
# will wait for prior builds to complete before starting.
#
# https://docs.github.com/en/actions/using-jobs/using-concurrency
concurrency:
  group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
  cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
  run-markdown-tests:
    runs-on: ubuntu-latest
    name: markdown:${{ matrix.python-version }}, ${{ matrix.database }}
    strategy:
      matrix:
        database:
          - "sqlite"
        python-version:
          - "3.10"

      fail-fast: true

    timeout-minutes: 10

    steps:
      - name: Display current test matrix
        run: echo '${{ toJSON(matrix) }}'

      - uses: actions/checkout@v6
        with:
          persist-credentials: false
          fetch-depth: 0

      - name: Set up uv
        uses: astral-sh/setup-uv@v7
        with:
          enable-cache: true
          python-version: ${{ matrix.python-version }}
          cache-dependency-glob: "pyproject.toml"

      - name: Install packages
        run: uv sync --group markdown-docs --locked

      - name: Start server
        run: |
          PREFECT_HOME=$(pwd) uv run prefect server start&
          PREFECT_API_URL="http://127.0.0.1:4200/api" uv run ./scripts/wait-for-server.py

      - name: Run tests
        run: >
          PREFECT_API_URL="http://127.0.0.1:4200/api" uv run pytest docs/ --markdown-docs -m markdown-docs
          --numprocesses auto
          --maxprocesses 6
