name: CI
permissions:
  contents: read

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

jobs:
  test:
    runs-on: ubuntu-latest

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

      - name: Get Node.js version from .nvmrc
        id: versions
        shell: bash
        run: |
          NODE_VERSION=$(cat .nvmrc)
          echo "node-version=$NODE_VERSION" >> $GITHUB_OUTPUT
          echo "📦 Using Node.js $NODE_VERSION from .nvmrc"

      - name: Enable Corepack
        run: corepack enable

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: ${{ steps.versions.outputs.node-version }}
          cache: 'yarn'

      - name: Install dependencies
        run: yarn

      - name: Run checks (lint, type check, spell check)
        run: yarn test

      - name: Test build
        run: yarn build
