name: Deploy

on:
  push:
    branches:
      - main

jobs:
  typecheck:
    runs-on: ubuntu-latest
    name: typecheck
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: "npm"
      - run: "npm i"
      - run: "npx tsc"

  lexicons:
    runs-on: ubuntu-latest
    name: lexicon
    env:
      LEAFLET_APP_PASSWORD: ${{ secrets.LEAFLET_APP_PASSWORD }}
      VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: "npm"
      - run: "npm i"
      - run: "npm run publish-lexicons"
  deploy-supabase:
    needs: [typecheck]
    runs-on: ubuntu-latest
    name: Deploy Supabase
    env:
      SUPABASE_ACCESS_TOKEN: ${{ secrets.SUPABASE_ACCESS_TOKEN }}
      SUPABASE_DB_PASSWORD: ${{ secrets.SUPABASE_DB_PASSWORD }}
      PRODUCTION_PROJECT_ID: bdefzwcumgzjwllsnaej

    steps:
      - uses: actions/checkout@v3
      - uses: supabase/setup-cli@v1
      - run: supabase link --project-ref $PRODUCTION_PROJECT_ID
      - run: supabase db push
