name: Setup and Install
description: Sets up Node.js and installs dependencies

runs:
  using: "composite"
  steps:
    - uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4.2.0
      with:
        node-version: 22<% if (packageManager !== 'yarn') { %>
        cache: <%= packageManager %><% } %>
    - name: Enable Corepack
      shell: bash
      run: corepack enable<% if (packageManager === 'yarn') { %>
    - name: Get yarn cache directory path
      shell: bash
      id: yarn-cache-dir-path
      run: echo "dir=$(<% if (yarn2) { %>yarn config get cacheFolder<% } else { %>yarn cache dir<% } %>)" >> $GITHUB_OUTPUT
    - name: Cache dependencies
      uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf # v4.2.2
      with:
        path: |
          ${{ steps.yarn-cache-dir-path.outputs.dir }}
          <% if (yarn2) { %>.yarn/unplugged
          .pnp.cjs
          .pnp.loader.mjs<% } %>
        key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
        restore-keys: |
          ${{ runner.os }}-yarn
          ${{ runner.os }}<% } %>
    - name: Install<% if (npmRegistry) { %>
      env:
        COREPACK_NPM_REGISTRY: <%= npmRegistry %>
        COREPACK_INTEGRITY_KEYS: ""<% } %>
      shell: bash
      run: <%= setupCommand %>
