name: Setup macOS dependencies

inputs:
  build-type:
    description: Type for the build
    required: true
    default: Debug

runs:
  using: composite

  steps:
    - name: Install dependencies
      shell: bash
      run: |
        brew update
        brew install ninja extra-cmake-modules temurin@17 mono

    - name: Set JAVA_HOME
      shell: bash
      run: |
        echo "JAVA_HOME=$(/usr/libexec/java_home -v 17)" >> "$GITHUB_ENV"

    - name: Setup vcpkg cache
      if: ${{ inputs.build-type == 'Debug' }}
      shell: bash
      env:
        USERNAME: ${{ github.repository_owner }}
        GITHUB_TOKEN: ${{ github.token }}
        FEED_URL: https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json
      run: |
        mono `vcpkg fetch nuget | tail -n 1` \
          sources add \
          -Source "$FEED_URL" \
          -StorePasswordInClearText \
          -Name GitHubPackages \
          -UserName "$USERNAME" \
          -Password "$GITHUB_TOKEN"
        mono `vcpkg fetch nuget | tail -n 1` \
          setapikey "$GITHUB_TOKEN" \
          -Source "$FEED_URL"
        echo "VCPKG_BINARY_SOURCES=clear;nuget,$FEED_URL,readwrite" >> "$GITHUB_ENV"

    - name: Setup vcpkg environment
      shell: bash
      run: |
        echo "VCPKG_ROOT=$VCPKG_INSTALLATION_ROOT" >> "$GITHUB_ENV"
