name: CI / Publish web

on:
  workflow_dispatch:

env:
  NODE_VERSION: 22.x

jobs:
  tests:
    name: 🧪 Tests
    secrets: inherit
    uses: ./.github/workflows/tests.yml

  publish:
    name: 🚀 Publish web
    runs-on: ubuntu-latest
    environment: Production
    needs: [tests]
    env:
      VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
      VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}

    steps:
      - name: ✅ Checkout code
        uses: actions/checkout@v5

      - name: 🔨 Setup
        uses: ./tooling/github/setup
        with:
          node-version: ${{ env.NODE_VERSION }}

      - name: 🔼 Install Vercel CLI
        run: pnpm install --global vercel@latest

      - name: 💪 Pull environment information
        run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}

      - name: 📦 Build
        run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }}

      - name: 💨 Publish!
        run: vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }}
