name: Node.js CI

on:
  push:
  pull_request:
    branches: [master, release]

jobs:
  test:
    runs-on: ubuntu-latest
    name: test

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

    steps:
      - name: Checkout code repository
        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 }}
      # Install pnpm depends on package.json packageManager field
      - uses: pnpm/action-setup@v2
        name: Install pnpm
        id: pnpm-install
        with:
          run_install: false
      - name: Get pnpm store directory
        shell: bash
        run: |
          echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
      - uses: actions/cache@v3
        name: Setup pnpm cache
        with:
          path: ${{ env.STORE_PATH }}
          key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
          restore-keys: |
            ${{ runner.os }}-pnpm-store-
      - name: Install
        run: |
          pnpm install --frozen-lockfile=false
      # - name: Build
      #   run: |
      #     pnpm build
      - name: Test
        run: |
          pnpm test
