name: 'Setup plugin build dependencies'
description: 'Builds the plugin build dependencies'
inputs:
  target:
    description: 'Build target for dependencies'
    required: true
  config:
    description: 'Build configuration'
    required: false
    default: 'Release'
  visualStudio:
    description: 'Visual Studio version (Windows only)'
    required: false
    default: 'Visual Studio 16 2019'
  workingDirectory:
    description: 'Working directory for packaging'
    required: false
    default: ${{ github.workspace }}
runs:
  using: 'composite'
  steps:
    - name: Restore cached dependencies
      id: restore-cache
      uses: actions/cache@v5
      with:
        path: ${{ env.DEP_DIR }}
        key: ${{ env.DEP_DIR }}-${{ runner.os }}-${{ inputs.target }}

    - name: Run macOS Build
      if: ${{ runner.os == 'macOS' && steps.restore-cache.outputs.cache-hit != 'true' }}
      shell: zsh {0}
      run: |
        build_args=(
          -c ${{ inputs.config }}
          -t ${{ inputs.target }}
          -o ${{ env.DEP_DIR }}
        )

        if (( ${+CI} && ${+RUNNER_DEBUG} )) build_args+=(--debug)

        .github/scripts/build-deps-macos.zsh -o ${{ env.DEP_DIR }} ${build_args}

    - name: Run Linux Build
      if: ${{ runner.os == 'Linux' && steps.restore-cache.outputs.cache-hit != 'true' }}
      shell: bash
      run: |
        build_args=(
          -c ${{ inputs.config }}
          -t linux-${{ inputs.target }}
        )

        if [[ -n "${CI}" && -n "${RUNNER_DEBUG}" ]]; then
          build_args+=(--debug)
        fi

        .github/scripts/build-deps-linux.sh -o ${{ env.DEP_DIR }} "${build_args[@]}"

    - name: Run Windows Build
      if: ${{ runner.os == 'Windows' && steps.restore-cache.outputs.cache-hit != 'true' }}
      shell: pwsh
      run: |
        $BuildArgs = @{
          Target = '${{ inputs.target }}'
          Configuration = '${{ inputs.config }}'
          OutDirName  = '${{ env.DEP_DIR }}'
        }

        if ( ( Test-Path env:CI ) -and ( Test-Path env:RUNNER_DEBUG ) ) {
          $BuildArgs += @{
            Debug = $true
          }
        }

        .github/scripts/Build-Deps-Windows.ps1 -OutDirName ${{ env.DEP_DIR }} @BuildArgs

