name: CI

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 package.json
        id: versions
        uses: actions/github-script@v7
        with:
          script: |
            const fs = require('fs');
            const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
            const nodeVersion = packageJson.volta.node;

            core.setOutput('node-version', nodeVersion);
            console.log(`📦 Using Node.js ${nodeVersion} from package.json`);

      - 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 check-all

      - name: Test build
        run: yarn build
