name: Deploy PR preview to Vercel

on:
  pull_request:
    branches:
      - main
      - dev
    types:
      - opened
      - synchronize
      - reopened

jobs:
  deploy:
    name: Deploy preview
    if: ${{ github.repository == 'dot013/.www' }}
    runs-on: ubuntu-latest
    permissions:
      contents: read
      pull-requests: write
      deployments: write
    strategy:
      matrix:
        node-version: [20]
    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Setup pnpm
        uses: pnpm/action-setup@v3
        with:
          version: 8
      - name: Setup Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node-version }}
          cache: 'pnpm'
      - name: Setup Go
        uses: actions/setup-go@v5
        with:
          go-version: '1.22.2'
      - name: Build
        run: |
          pnpm install
          go install github.com/a-h/templ/cmd/templ@latest
          make build/static
      - name: Deploy
        uses: BetaHuhn/deploy-to-vercel-action@v1
        with:
          GITHUB_TOKEN: ${{ SECRETS.GITHUB_TOKEN }}
          VERCEL_TOKEN: ${{ SECRETS.VERCEL_TOKEN }}
          VERCEL_ORG_ID: ${{ SECRETS.VERCEL_ORG_ID }}
          VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
          PRODUCTION: false
