name: CI Build & Test

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

jobs:
  test:
    name: Test on ${{ matrix.os }} (Node ${{ matrix.node-version }})
    runs-on: ${{ matrix.os }}

    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
        node-version: [20.x]

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

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

      - name: Install Dependencies
        run: npm ci

      - name: Type Check & Build
        run: npm run build 2>&1 | tee build.log

      - name: Run Tests
        shell: bash
        run: |
          npx vitest run 2>&1 | tee test.log

      - name: Upload Logs
        if: always()
        uses: actions/upload-artifact@v4
        with:
          name: logs-${{ matrix.os }}
          path: |
            build.log
            test.log