name: Windows

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

permissions:
  contents: read

jobs:
  # CMake release build with shared library (msbuild)
  release-cmake-msvc-msbuild:
    env:
      BUILD_TYPE: Release
    runs-on: windows-latest

    steps:
    - name: Setup NASM
      uses: ilammy/setup-nasm@13cbeb366c45c4379d3478cdcbadd8295feb5028 # v1.5.1

    - name: Checkout repo
      uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
      with:
        repository: 'intel/intel-ipsec-mb'

    - name: Add MSBuild to PATH
      uses: microsoft/setup-msbuild@c26a08ba26249b81327e26f6ef381897b6a8754d # v1.0.2

    - name: Setup environment
      run: |
        New-Item -ItemType Directory -Path "$pwd\build"
        New-Item -ItemType Directory -Path "$pwd\build\bin"
        "BUILD_DIR=$pwd\build" >> $env:GITHUB_ENV
        "BINARY_DIR=$pwd\build\bin" >> $env:GITHUB_ENV
        $env:PATH += "$pwd\build\bin;"

    - name: Configure CMake
      run: cmake -A x64 -DIMB_BIN_DIR=${{env.BINARY_DIR}} -B ${{env.BUILD_DIR}}

    - name: Build
      run: cmake --build ${{env.BUILD_DIR}} --config ${{env.BUILD_TYPE}}

    - name: Test
      run: ctest -j 5 -C ${{env.BUILD_TYPE}} --test-dir ${{env.BUILD_DIR}}

  # CMake debug build with shared library (msbuild)
  debug-cmake-msvc-msbuild:
    env:
      BUILD_TYPE: Debug
    runs-on: windows-latest

    steps:
    - name: Setup NASM
      uses: ilammy/setup-nasm@13cbeb366c45c4379d3478cdcbadd8295feb5028 # v1.5.1

    - name: Checkout repo
      uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
      with:
        repository: 'intel/intel-ipsec-mb'

    - name: Add MSBuild to PATH
      uses: microsoft/setup-msbuild@c26a08ba26249b81327e26f6ef381897b6a8754d # v1.0.2

    - name: Setup environment
      run: |
        New-Item -ItemType Directory -Path "$pwd\build"
        New-Item -ItemType Directory -Path "$pwd\build\bin"
        "BUILD_DIR=$pwd\build" >> $env:GITHUB_ENV
        "BINARY_DIR=$pwd\build\bin" >> $env:GITHUB_ENV
        $env:PATH += "$pwd\build\bin;"

    - name: Configure CMake
      run: cmake -A x64 -DIMB_BIN_DIR=${{env.BINARY_DIR}} -B ${{env.BUILD_DIR}}

    - name: Build
      run: cmake --build ${{env.BUILD_DIR}} --config ${{env.BUILD_TYPE}}

    - name: Test
      run: ctest -j 5 -C ${{env.BUILD_TYPE}} --test-dir ${{env.BUILD_DIR}}
