name: Windows x64 CMake/MSVC (Debug)
permissions: read-all

on:
  # This is a required workflow specified in branch enforcement
  # and must run unconditionally to allow merges.
  push:
  pull_request:

jobs:

  win_msvc_dbg_x64_cmake:

    runs-on: windows-2019

    steps:
    - name: Git config
      run: |
        git config --global core.autocrlf false
        git config --global core.eol lf

    - name: Install vcpkg
      shell: cmd
      run: |
        git clone https://github.com/Microsoft/vcpkg.git
        cd vcpkg
        .\bootstrap-vcpkg.bat

    - name: Set up Python 3.x
      uses: actions/setup-python@v2
      with:
        python-version: '3.x'

    - uses: actions/checkout@v2
      with:
        path: test
        fetch-depth: 0

    - name: Generate shared library for main branch (with patch)
      shell: cmd
      run: |
        cd test
        cmake . -Ax64 -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=ON -DCMAKE_TOOLCHAIN_FILE=..\vcpkg\scripts\buildsystems\vcpkg.cmake

    - name: Build shared library for main branch (with patch)
      shell: cmd
      run: |
        cd test
        cmake --build . --config Debug

    - name: Generate D3D12 example app for main branch (with patch)
      shell: cmd
      run: |
        mkdir test_examples
        cd test_examples
        cmake ..\test\examples\D3D12ProjectTemplate -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=..\vcpkg\scripts\buildsystems\vcpkg.cmake

    - name: Build D3D12 example app for main branch (with patch)
      shell: cmd
      run: |
        cd test_examples
        cmake --build . --config Debug

    - name: Generate project for main branch (with patch)
      shell: cmd
      run: |
        cd test
        cmake . -Ax64 -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=OFF -DGPGMM_DISABLE_SIZE_CACHE=ON -DCMAKE_TOOLCHAIN_FILE=..\vcpkg\scripts\buildsystems\vcpkg.cmake

    - name: Build for main branch (with patch)
      shell: cmd
      run: |
        cd test
        cmake --build . --config Debug

    - name: Run gpgmm_end2end_tests (with patch)
      timeout-minutes: 10
      shell: cmd
      run: |
        cd test
        bin\Debug\gpgmm_end2end_tests.exe --gtest_filter=-*NoLeak --check-device-leaks 2>&1

    - name: Run gpgmm_end2end_tests runtime leak checks (with patch)
      timeout-minutes: 10
      shell: cmd
      run: |
        cd test
        bin\Debug\gpgmm_end2end_tests.exe --no-leaks 2>&1

    - name: Run gpgmm_end2end_tests no leak tests (with patch)
      timeout-minutes: 10
      shell: cmd
      run: |
        cd test
        bin\Debug\gpgmm_end2end_tests.exe --gtest_filter=*NoLeak --check-device-leaks 2>&1

    - name: Run gpgmm_unittests (with patch)
      shell: cmd
      run: |
        cd test
        bin\Debug\gpgmm_unittests.exe

    - name: Run gpgmm_capture_replay_tests (with patch)
      shell: cmd
      run: |
        cd test
        bin\Debug\gpgmm_capture_replay_tests.exe --log-level=DEBUG --check-device-leaks 2>&1