on:
  # push:
  #   branches:
  #     - main
  pull_request:
    branches:
      - main

name: PR checks

jobs:
  test:
    name: Build, Test and Cov
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [20.x]
    steps:
      - name: Check out code
        uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node-version }}
          cache: "npm"
      - name: Cache node_modules
        id: cache-node-modules
        uses: actions/cache@v4
        with:
          path: node_modules
          key: ${{ matrix.node-version }}-${{ runner.OS }}-npm-${{ hashFiles('package-lock.json') }}
      - name: Install deps
        if: steps.cache-node-modules.outputs.cache-hit != 'true'
        run: npm ci
      - name: Type checking
        run: npm run test:types
      - name: ESLint
        run: npm run test:lint
      - name: Buildabilty
        run: npm run build
      - name: Unit testing
        run: npm run test:unit:cov
      - name: Unit testing
        run: npm run test:unit:cov
      - uses: codecov/codecov-action@v5
        with:
          fail_ci_if_error: true
          token: ${{ secrets.CODECOV_TOKEN }}
