name: Prepare
description: Install and build the app
inputs:
  build:
    description: Build the production bundle of the platform
    required: false
    default: true

runs:
  using: 'composite'
  steps:
    - name: Install Node.js
      uses: actions/setup-node@v3
      with:
        node-version: 16

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

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

    - 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.build == 'true'
      shell: bash
      run: pnpm run -r --workspace-concurrency=1 build
      env:
        NODE_OPTIONS: --max_old_space_size=6144
