on:
  push:
    branches:
    - master
    - v3.8
  pull_request:
    branches:
    - master
    - v3.8

name: ci

jobs:
    window_build_cpu:
        name: CPU (fftw, OpenBLAS, windows-latest)
        runs-on: windows-latest
        env:
          VCPKG_HASH: f14984af3738e69f197bf0e647a8dca12de92996
          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
