name: CI

on:
  push:
    branches: [main]
    paths:
      - 'katashiro/**'
  pull_request:
    branches: [main]
    paths:
      - 'katashiro/**'

jobs:
  build:
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: katashiro

    strategy:
      matrix:
        node-version: [20.x, 22.x]

    steps:
      - uses: actions/checkout@v4

      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node-version }}
          cache: 'npm'
          cache-dependency-path: katashiro/package-lock.json

      - name: Install dependencies
        run: npm ci

      - name: Lint
        run: npm run lint

      - name: Type check
        run: npm run typecheck

      - name: Build
        run: npm run build

      - name: Test
        run: npm run test

  coverage:
    runs-on: ubuntu-latest
    defaults:
      run:
        working-directory: katashiro
    needs: build

    steps:
      - uses: actions/checkout@v4

      - name: Use Node.js 20.x
        uses: actions/setup-node@v4
        with:
          node-version: 20.x
          cache: 'npm'
          cache-dependency-path: katashiro/package-lock.json

      - name: Install dependencies
        run: npm ci

      - name: Build
        run: npm run build

      - name: Test with coverage
        run: npm run test:coverage

      - name: Upload coverage reports
        uses: codecov/codecov-action@v4
        with:
          directory: katashiro/coverage
          flags: katashiro
          fail_ci_if_error: false
