name: windows-x64-Release

on: [push, pull_request, workflow_dispatch]

concurrency:
  group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
  cancel-in-progress: true

permissions:
  packages: write

env:
  FEED_URL: https://nuget.pkg.github.com/gwaldron/index.json
  VCPKG_BINARY_SOURCES: "clear;nuget,https://nuget.pkg.github.com/gwaldron/index.json,readwrite"
  # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
  BUILD_TYPE: Release
  VCPKG_VERSION: '2026.01.16'

jobs:

  build:
    runs-on: ${{ matrix.os }}

    strategy:
      matrix:
        os: ['windows-latest']
        include:
          - os: 'windows-latest'
            triplet: 'x64-windows-release'
            mono: ''
            VCPKG_WORKSPACE: 'c:/vcpkg_own'

    steps:
    - uses: actions/checkout@v4
      with:
        submodules: recursive

    - name: Installing vcpkg (windows)
      shell: 'bash'
      run: |
        cmake -E make_directory ${{ matrix.VCPKG_WORKSPACE }}
        cd ${{ matrix.VCPKG_WORKSPACE }}
        # git clone --depth 1 --branch ${{env.VCPKG_VERSION}} https://github.com/microsoft/vcpkg
        git clone https://github.com/microsoft/vcpkg
        cd vcpkg
        git checkout ${{env.VCPKG_VERSION}}
        cd ..
        ./vcpkg/bootstrap-vcpkg.bat -disableMetrics
        ${{ matrix.VCPKG_WORKSPACE }}/vcpkg/vcpkg version

    - name: Add NuGet sources
      shell: pwsh
      run: |
        .$(${{ matrix.VCPKG_WORKSPACE }}/vcpkg/vcpkg fetch nuget) `
          sources add `
          -Source "${{ env.FEED_URL }}" `
          -StorePasswordInClearText `
          -Name GitHubPackages `
          -UserName "gwaldron" `
          -Password "${{ secrets.NUGET_CACHE_TOKEN }}"
        .$(${{ matrix.VCPKG_WORKSPACE }}/vcpkg/vcpkg fetch nuget) `
          setapikey "${{ secrets.NUGET_CACHE_TOKEN }}" `
          -Source "${{ env.FEED_URL }}"

    - name: Create Build Environment
      run: |
        cmake -E make_directory ${{runner.workspace}}/build

    - name: Download cesium-native
      shell: powershell
      run: |
        Invoke-WebRequest -Uri "https://pelican-public.s3.us-east-1.amazonaws.com/cesium-native-v0.37.0-vs2019.zip" -OutFile "C:\cesium-native.zip"
        Expand-Archive -Path "C:\cesium-native.zip" -DestinationPath "C:\cesium-native"

    - name: Configure CMake
      shell: bash
      working-directory: ${{ runner.workspace }}/build
      # Add the following for vcpkg install debugging: -DVCPKG_INSTALL_OPTIONS=--debug  
      run: |
        cmake $GITHUB_WORKSPACE -DOSGEARTH_BUILD_LEGACY_SPLAT_NODEKIT=OFF -DOSGEARTH_BUILD_PROCEDURAL_NODEKIT=ON -DOSGEARTH_BUILD_CESIUM_NODEKIT=ON -DOSGEARTH_ENABLE_S3=ON -DCESIUM_NATIVE_DIR=C:/cesium-native -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_TOOLCHAIN_FILE=${{ matrix.VCPKG_WORKSPACE }}/vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_MANIFEST_DIR=$GITHUB_WORKSPACE -DVCPKG_TARGET_TRIPLET=${{ matrix.triplet }}

    - name: 'Upload cmake configure log artifact'
      uses: actions/upload-artifact@v4
      if: ${{ failure() }}
      with:
        name: cmake-log
        path: |
          ${{ runner.workspace }}/build/CMakeCache.txt
        retention-days: 1

    - name: Build
      working-directory: ${{ runner.workspace }}/build
      shell: bash
      run: cmake --build . --config $BUILD_TYPE --parallel
