---
name: Cloud API Compatibility
on:
  pull_request:
    paths:
      - .github/workflows/api-compatibility-tests.yaml
      - "**/*.py"
      - pyproject.toml
      - compat-tests
  push:
    branches:
      - main

# 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.ref }}
  cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
  compatibility-tests:

    if: false # temporarily pausing compat tests on OSS

    timeout-minutes: 10

    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v6
        with:
          # Versioningit only generates correct versions with a full fetch
          fetch-depth: 0
          persist-credentials: false
          submodules: true

      - name: Set up Python 3.12
        uses: actions/setup-python@v6
        id: setup_python
        with:
          python-version: "3.12"

      - name: UV Cache
        # Manually cache the uv cache directory
        # until setup-python supports it:
        # https://github.com/actions/setup-python/issues/822
        uses: actions/cache@v5
        id: cache-uv
        with:
          path: ~/.cache/uv
          key: uvcache-${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ hashFiles('requirements-client.txt', 'requirements.txt', 'requirements-dev.txt') }}

      - name: Install packages
        run: |
          python -m pip install -U uv
          uv pip install --upgrade --system -e .[dev] 'pydantic>=2.4,<3'

      - name: Create Cloud OpenAPI JSON
        working-directory: compat-tests
        run: curl https://api.prefect.cloud/api/openapi.json > cloud_schema.json

      - name: Create OSS OpenAPI JSON
        working-directory: compat-tests
        run: python ../scripts/generate_oss_openapi_schema.py

      - name: Run API compatibility tests
        working-directory: compat-tests
        run: pytest -vv
