name: Setup pnpm workspace
description: Restore the pinned pnpm workspace after the caller checks out its ref.

inputs:
  github-packages-token:
    description: GitHub Packages read token for @platform-modules
    required: false
    default: ''

runs:
  using: composite
  steps:
    - name: Route temp files onto the runner work disk
      shell: bash
      run: |
        job_tmp="${RUNNER_TEMP}/job-tmp"
        mkdir -p "$job_tmp"
        echo "TMPDIR=$job_tmp" >> "$GITHUB_ENV"
    - uses: actions/setup-node@v5
      with:
        node-version: 22
        package-manager-cache: false
    - name: Activate pnpm
      id: pnpm-store
      shell: bash
      run: |
        source scripts/setup-pnpm-action.sh
        echo "path=$(pnpm store path)" >> "$GITHUB_OUTPUT"
    - uses: actions/cache@v6
      with:
        path: ${{ steps.pnpm-store.outputs.path }}
        key: ${{ runner.os }}-pnpm-store-${{ hashFiles('pnpm-lock.yaml') }}
    - uses: actions/cache@v6
      with:
        path: ~/.cache/ms-playwright
        key: ${{ runner.os }}-playwright-${{ hashFiles('pnpm-lock.yaml') }}
    - shell: bash
      env:
        GITHUB_PACKAGES_TOKEN: ${{ inputs.github-packages-token }}
      run: |
        source scripts/setup-pnpm-install.sh
