name: CI

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

jobs:
  test:
    name: Test, Lint & Typecheck
    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [18, 20, 22]

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

      - name: Setup 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: Configure git for tests
        run: |
          git config --global init.defaultBranch main
          git config --global user.name "GitHub Actions"
          git config --global user.email "actions@github.com"

      - name: Run linter
        run: pnpm run lint

      - name: Run type check
        run: pnpm run typecheck

      - name: Build
        run: pnpm run build

      - name: Run tests
        run: pnpm test
