on:
  push:
    branches:
    - master
  pull_request:
    branches:
    - master

name: ci

jobs:
    window_build_cpu:
        name: CPU (fftw, OpenBLAS, windows-latest)
        runs-on: windows-latest
        env:
          VCPKG_HASH: 9d47b24eacbd1cd94f139457ef6cd35e5d92cc84
          VCPKG_DEFAULT_TRIPLET: x64-windows
        steps:
            - name: Checkout Repository
              uses: actions/checkout@master

            - name: VCPKG Cache
              uses: actions/cache@v3
              id: vcpkg-cache
              with:
                path: ~/vcpkg
                key: vcpkg-deps-${{ env.VCPKG_HASH }}

            - name: Install VCPKG Dependencies
              if: steps.vcpkg-cache.outputs.cache-hit != 'true'
              run: |
                pushd .
                cd ~
                git clone --quiet --recursive https://github.com/microsoft/vcpkg.git
                cd vcpkg
                git checkout $env:VCPKG_HASH
                .\bootstrap-vcpkg.bat
                popd
                mkdir build && cd build && set VCPKG_ROOT=
                cmake .. -G "Visual Studio 17 2022" -A x64 `
                      -DVCPKG_ROOT:PATH=~/vcpkg `
                      -DAF_BUILD_CUDA:BOOL=OFF -DAF_BUILD_OPENCL:BOOL=OFF `
                      -DAF_BUILD_UNIFIED:BOOL=OFF -DAF_BUILD_FORGE:BOOL=ON `
                      -DBUILDNAME:STRING="$buildname" `
                      -DAF_COMPUTE_LIBRARY:STRING="FFTW/LAPACK/BLAS"

            - name: CMake Configure
              run: |
                  $ref = $env:GITHUB_REF | %{ if ($_ -match "refs/pull/[0-9]+/merge") { $_;} }
                  $prnum = $ref | %{$_.Split("/")[2]}
                  $branch = git branch --show-current
                  $buildname = if($prnum -eq $null) { $branch } else { "PR-$prnum" }
                  $dashboard = if($prnum -eq $null) { "Continuous" } else { "Experimental" }
                  $buildname = "$buildname-cpu-openblas"
                  if((Test-Path build) -eq 0) {
                      mkdir build
                  }
                  cd build && set VCPKG_ROOT=
                  cmake .. -G "Visual Studio 17 2022" -A x64 `
                      -DVCPKG_ROOT:PATH=~/vcpkg `
                      -DAF_BUILD_CUDA:BOOL=OFF -DAF_BUILD_OPENCL:BOOL=OFF `
                      -DAF_BUILD_UNIFIED:BOOL=OFF -DAF_BUILD_FORGE:BOOL=ON `
                      -DBUILDNAME:STRING="$buildname" `
                      -DAF_COMPUTE_LIBRARY:STRING="FFTW/LAPACK/BLAS"
                  echo "CTEST_DASHBOARD=${dashboard}" >> $env:GITHUB_ENV

            - name: Build and Test
              run: |
                  cd build
                  $build_path = (pwd).Path
                  $Env:PATH += ";$build_path/vcpkg_installed/x64-windows/bin"
                  ctest -D Experimental --track ${CTEST_DASHBOARD} -T Test -T Submit -C RelWithDebInfo -R cpu -E pinverse -j2
