name: Windows CI

on:
  pull_request_review:
    types: [submitted, edited]
  workflow_dispatch:

jobs:
  gcc-build:
    name: GCC build
    # For jobs triggered by pull_request_review, build task should run only if is in `approved` state.
    if: ${{ github.event_name == 'workflow_dispatch' || github.event.review.state == 'approved' }}
    strategy:
      matrix:
        python-version: ["3.10"]
    runs-on: "windows-2022"
    env:
      CXX_COMPILER: "g++-8"
      C_COMPILER: "gcc-8"
      PYTHON: ${{ matrix.python-version }}
      COVERAGE: "ON"
    steps:
      - uses: actions/checkout@v4

      - name: Setup cmake
        uses: lukka/get-cmake@latest

      # TODO: In Windows, ccache is not used because its behavior is not stable.
      # mozilla/sccache is one candidate for this situation.

      - name: Setup Python
        uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python-version }}

      - name: Install boost
        uses: MarkusJx/install-boost@v2.4.3
        id: install-boost
        with:
          boost_version: 1.77.0

      - name: Install qulacs for Windows
        run: |
          $env:USE_TEST = "Yes"
          ./script/build_msvc_2022.bat
        env:
          BOOST_ROOT: ${{ steps.install-boost.outputs.BOOST_ROOT }}

      - name: Install qulacs Python module
        env:
          BOOST_ROOT: ${{ steps.install-boost.outputs.BOOST_ROOT }}
        run: pip install .[ci]

      - name: Test in Windows
        env:
          BOOST_ROOT: ${{ steps.install-boost.outputs.BOOST_ROOT }}
        run: |
          cmake --build ./visualstudio --target test --config Release
          cmake --build ./visualstudio --target pythontest --config Release
