name: Windows

on:
   push:
      branches: [ RC_1_2 RC_2_0 master ]
   pull_request:

defaults:
   run:
      shell: cmd

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

jobs:

   tests:
      name: Test
      runs-on: windows-latest
      continue-on-error: true

      strategy:
         matrix:
           include:
             - config: address-model=32 crypto=built-in
             - config: address-model=64
             - config: release

      steps:
      - name: checkout
        uses: actions/checkout@v2
        with:
           submodules: true

      - name: install openssl (64 bit)
        uses: nick-invision/retry@v2
        with:
          timeout_minutes: 30
          retry_wait_seconds: 4
          max_attempts: 3
          command: choco install openssl --limitoutput --no-progress

      - name: install boost
        run: |
          git clone --depth=1 --recurse-submodules -j10 --branch=boost-1.78.0 https://github.com/boostorg/boost.git
          cd boost
          bootstrap.bat

      - name: boost headers
        run: |
          cd boost
          .\b2 headers

      - name: tests (deterministic)
        run: |
          set BOOST_ROOT=%CD%\boost
          set PATH=%BOOST_ROOT%;%PATH%
          set PYTHON_INTERPRETER=python
          cd test
          b2 -l400 warnings=all warnings-as-errors=on ${{ matrix.config }} deterministic-tests


      - name: tests (flaky)
        run: |
          set BOOST_ROOT=%CD%\boost
          set PATH=%BOOST_ROOT%;%PATH%
          set PYTHON_INTERPRETER=python
          cd test
          set c=3
          :retry
          if %c%==0 exit /B 1
          set /a c = %c% -1
          b2 -l400 warnings=all warnings-as-errors=on ${{ matrix.config }}
          if %errorlevel%==0 exit /B 0
          if %c% gtr 0 goto retry
          exit /B 1

   simulations:
      name: Simulations
      runs-on: windows-2019

      steps:
      - name: checkout
        uses: actions/checkout@v2.3.3
        with:
           submodules: true

      - name: install boost
        run: |
          git clone --depth=1 --recurse-submodules -j10 --branch=boost-1.78.0 https://github.com/boostorg/boost.git
          cd boost
          bootstrap.bat

      - name: boost headers
        run: |
          cd boost
          .\b2 headers

      - shell: pwsh
        run: |
          echo "BOOST_ROOT=$(pwd)/boost" >> $env:GITHUB_ENV
          echo "$(pwd)/boost" >> $env:GITHUB_PATH

  # debug iterators are turned off here because msvc has issues with noexcept
  # specifiers when debug iterators are enabled. Specifically, constructors that
  # allocate memory are still marked as noexcept. That results in program
  # termination
  # the IOCP backend in asio appears to have an issue where it hangs under
  # certain unexpected terminations (through exceptions)
      - name: build sims
        run: |
          echo %BOOST_ROOT%
          echo %PATH%
          cd simulation
          b2 --hash release address-model=64 link=static debug-iterators=off invariant-checks=on define=BOOST_ASIO_DISABLE_IOCP asserts=on testing.execute=off

      - name: run sims
        uses: nick-fields/retry@v2
        with:
          max_attempts: 3
          timeout_minutes: 120
          command: |
            cd simulation
            b2 --hash -l700 release address-model=64 link=static debug-iterators=off invariant-checks=on define=BOOST_ASIO_DISABLE_IOCP asserts=on

   build:
      name: Build
      runs-on: windows-2019
      continue-on-error: true

      strategy:
         matrix:
           include:
             - config: asio-debugging=on picker-debugging=on windows-version=vista
             - config: windows-api=store windows-version=win10
             - config: deprecated-functions=off

      steps:
      - name: checkout
        uses: actions/checkout@v2.3.3
        with:
           submodules: true

      - name: install boost
        run: |
          git clone --depth=1 --recurse-submodules -j10 --branch=boost-1.78.0 https://github.com/boostorg/boost.git
          cd boost
          bootstrap.bat

      - name: install openssl (64 bit)
        uses: nick-invision/retry@v2
        with:
          timeout_minutes: 30
          retry_wait_seconds: 4
          max_attempts: 3
          command: choco install openssl --limitoutput --no-progress

      - name: boost headers
        run: |
          cd boost
          .\b2 headers

      - name: build library
        run: |
          set BOOST_ROOT=%CD%\boost
          set PATH=%BOOST_ROOT%;%PATH%
          b2 ${{ matrix.config }} cxxstd=14 address-model=64 warnings=all warnings-as-errors=on

      - name: build examples
        if: ${{ ! contains(matrix.config, 'windows-api=store') }}
        run: |
          set BOOST_ROOT=%CD%\boost
          set PATH=%BOOST_ROOT%;%PATH%
          cd examples
          b2 ${{ matrix.config }} address-model=64 warnings=all warnings-as-errors=on

      - name: build tools
        if: ${{ ! contains(matrix.config, 'windows-api=store') }}
        run: |
          set BOOST_ROOT=%CD%\boost
          set PATH=%BOOST_ROOT%;%PATH%
          cd tools
          b2 ${{ matrix.config }} address-model=64 warnings=all warnings-as-errors=on

