name: Migrate and deploy

on:
  push:
    branches: [main]
    paths-ignore:
      - "**/*.md"
      - "docs/**"
  workflow_dispatch:

jobs:
  deploy:
    runs-on: ubuntu-latest
    environment: production
    steps:
      - uses: actions/checkout@v4

      - uses: pnpm/action-setup@v4
        with:
          version: 10.10.0

      - uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: pnpm

      - name: Install dependencies
        run: pnpm install --frozen-lockfile

      - name: Run database migrations
        env:
          DATABASE_URL: ${{ secrets.POSTGRES_URL_NON_POOLING }}
        run: pnpm exec drizzle-kit migrate

      - name: Trigger Vercel production deploy
        run: curl -fsSL -X POST "${{ secrets.VERCEL_DEPLOY_HOOK }}"
