name: 'Setup and build'
description: 'Setup and build Session Desktop'
inputs:
  cache_suffix:
    description: 'the package we are currently building (used as key for the cached node_modules)'
    required: true

runs:
  using: 'composite'
  steps:
    - name: Install node
      uses: actions/setup-node@v4
      with:
        node-version-file: '.nvmrc'

    - uses: actions/setup-python@v5
      with:
        python-version: '3.11'

    # Not having this will break the windows build because the PATH won't be set by msbuild.
    - name: Add msbuild to PATH
      uses: microsoft/setup-msbuild@v2
      if: runner.os == 'Windows'

    - name: Setup node for windows
      if: runner.os == 'Windows'
      shell: bash
      run: |
        yarn global add node-gyp@latest

    - uses: actions/cache/restore@v4
      id: cache-desktop-modules
      with:
        path: node_modules
        key: ${{ runner.os }}-${{ runner.arch }}-${{ inputs.cache_suffix }}-${{ hashFiles('package.json', 'yarn.lock', 'patches/**') }}

    - name: Install dependencies
      shell: bash
      if: steps.cache-desktop-modules.outputs.cache-hit != 'true'
      run: yarn install --frozen-lockfile --network-timeout 600000

    - uses: actions/cache/save@v4
      id: cache-desktop-modules-save
      if: runner.os != 'Windows'
      with:
        path: node_modules
        key: ${{ runner.os }}-${{ runner.arch }}-${{ inputs.cache_suffix }}-${{ hashFiles('package.json', 'yarn.lock', 'patches/**') }}

    - name: Generate and concat files
      shell: bash
      run: yarn build-everything
