# Deploys to the Dokploy instance on mercury (mercury.kennethreitz.org)
# by hitting the application's deploy webhook after tests pass.

name: Deploy
on:
  push:
    branches: [main]

jobs:
  test:
    name: Run Tests
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: astral-sh/setup-uv@v5
        with:
          version: "latest"
      - run: uv python install 3.13
      - run: uv sync --extra dev
      - run: uv run pytest tests/ -n auto --tb=short

  deploy:
    name: Deploy app
    runs-on: ubuntu-latest
    needs: test
    environment: prod
    concurrency: deploy-group
    steps:
      - name: Trigger Dokploy deploy
        # Dokploy's deploy endpoint expects a GitHub-style push event;
        # a bare POST returns 200 but deploys nothing.
        run: |
          curl -fsS -X POST "$DOKPLOY_DEPLOY_URL" \
            -H 'Content-Type: application/json' \
            -H 'x-github-event: push' \
            -d "{\"ref\":\"refs/heads/${GITHUB_REF_NAME}\"}"
        env:
          DOKPLOY_DEPLOY_URL: ${{ secrets.DOKPLOY_DEPLOY_URL }}
