name: Prepare
description: Install and build the app
inputs:
  should_skip_build:
    description: 'Should skip the Build step.'
    required: false
    default: 'false'

runs:
  using: 'composite'
  steps:
    - name: Checkout
      uses: actions/checkout@v3

    - uses: hmarr/debug-action@v2

    - name: Install Node.js
      uses: actions/setup-node@v3
      with:
        node-version: 16

    - uses: pnpm/action-setup@v2.0.1
      name: Install pnpm
      id: pnpm-install
      with:
        version: 7
        run_install: false

    - name: Get pnpm store directory
      id: pnpm-cache
      shell: bash
      run: |
        echo "::set-output name=pnpm_cache_dir::$(pnpm store path)"

    - uses: actions/cache@v3
      name: Setup pnpm cache
      with:
        path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
        key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
        restore-keys: |
          ${{ runner.os }}-pnpm-store-

    - name: Install dependencies
      shell: bash
      run: pnpm install

    - name: Build
      if: inputs.should_skip_build != 'true'
      shell: bash
      run: pnpm run -r --workspace-concurrency=1 build
      env:
        NODE_OPTIONS: --max_old_space_size=6144
