name: CI

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

concurrency:
  group: ci-${{ github.ref }}
  cancel-in-progress: true

jobs:
  ci:
    name: Lint → Typecheck → Test → Build
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [22]

    services:
      postgres:
        image: postgis/postgis:16-3.4
        env:
          POSTGRES_DB: goodgo_test
          POSTGRES_USER: goodgo
          POSTGRES_PASSWORD: goodgo_test_secret
        ports:
          - 5432:5432
        options: >-
          --health-cmd "pg_isready -U goodgo -d goodgo_test"
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5
          --health-start-period 30s

    env:
      DATABASE_URL: postgresql://goodgo:goodgo_test_secret@localhost:5432/goodgo_test
      NODE_ENV: test

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Install pnpm
        uses: pnpm/action-setup@v4

      - name: Setup Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node-version }}
          cache: pnpm

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

      - name: Lint
        run: pnpm lint

      - name: Typecheck
        run: pnpm typecheck

      - name: Test
        run: pnpm test

      - name: Build
        run: pnpm build
