name: Contract Tests

on:
  pull_request:
    paths:
      - "src/api/**"
      - ".github/workflows/contract-tests.yml"
  push:
    branches:
      - main
    paths:
      - "src/api/**"
      - ".github/workflows/contract-tests.yml"
  workflow_dispatch:

permissions:
  contents: read

jobs:
  contract-tests:
    name: Run contract tests
    runs-on: ubuntu-latest
    timeout-minutes: 15
    steps:
      - name: Check out repository
        uses: actions/checkout@v6

      - name: Set up Python
        uses: actions/setup-python@v6
        with:
          python-version: "3.11"
          cache: pip
          cache-dependency-path: src/api/requirements.txt

      - name: Install dependencies
        working-directory: src/api
        run: |
          python -m pip install --upgrade pip
          pip install -r requirements.txt

      - name: Run contract tests
        working-directory: src/api
        run: |
          python -m pytest tests/contract -v --tb=short
