name: Setup node and pnpm
description: Configure the Node.js and pnpm versions

inputs:
  node-version:
    description: 'The Node.js version to use'
    required: true
    default: 22.6.2
  pnpm-version:
    description: 'The pnpm version to use'
    required: true
    default: 9.7.1

runs:
  using: composite
  steps:
    # https://github.com/actions/virtual-environments/issues/1187
    - name: tune linux network
      shell: bash
      run: sudo ethtool -K eth0 tx off rx off

    - name: Setup Node@${{ inputs.node-version }}
      uses: actions/setup-node@v4
      with:
        node-version: ${{ inputs.node-version }}

    - name: Install pnpm
      uses: pnpm/action-setup@v4
      with:
        version: ${{ inputs.pnpm-version }}
        run_install: false

    - name: Get pnpm store directory
      shell: bash
      run: |
        echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV

    - name: Setup pnpm cache
      uses: actions/cache@v4
      with:
        path: ${{ env.STORE_PATH }}
        key: pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
        restore-keys: |
          pnpm-store-
          pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}

    - shell: bash
      run: pnpm install
