name: CI

on:
  push:
    branches: [main, master]
  pull_request:
    branches: [main, master]

jobs:
  bot:
    name: Bot (Python)
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: bot
    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-python@v5
        with:
          python-version: "3.11"
          cache: pip
          cache-dependency-path: bot/requirements.txt

      - name: Install dependencies
        run: pip install -r requirements.txt

      - name: Syntax check
        run: python -m compileall -q -x 'leveling_original' .

      - name: Import smoke test
        env:
          TOKEN: test
          OWNER_IDS: "123456789012345678"
          API_ENABLED: "false"
          TUNNEL_ENABLED: "false"
        run: |
          python - <<'PY'
          from core.axiom import Axiom
          from api.server import create_app
          bot = Axiom()
          create_app()
          import cogs
          print("imports ok")
          PY

  dashboard:
    name: Dashboard (Next.js)
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: dashboard
    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-node@v4
        with:
          node-version: "20"
          cache: npm
          cache-dependency-path: dashboard/package-lock.json

      - name: Install dependencies
        run: npm install

      - name: Lint
        run: npm run lint

      - name: Build
        env:
          DASHBOARD_API_URL: http://127.0.0.1:8000/api/v1
          DASHBOARD_API_KEY: ci-test-key
          NEXTAUTH_URL: http://localhost:3000
          NEXTAUTH_SECRET: ci-test-secret-min-32-chars-long!!
          DISCORD_CLIENT_ID: "0"
          DISCORD_CLIENT_SECRET: ci-secret
        run: npm run build
