name: windows

on:
  push:
    branches:
      - main
    paths:
      - interfaces/*/src/**
      - interfaces/*/examples/**
      - interfaces/*/Cargo.toml
      - models/*/src/**
      - models/*/examples/**
      - models/*/Cargo.toml
      - floneum/*/src/**
      - floneum/*/examples/**
      - floneum/*/Cargo.toml
      - fusor-ml/*/src/**
      - fusor-ml/*/tests/**
      - fusor-ml/*/examples/**
      - fusor-ml/*/Cargo.toml
      - src/**
      - .github/**
      - Cargo.toml

  pull_request:
    types: [opened, synchronize, reopened, ready_for_review]
    branches:
      - main
    paths:
      - interfaces/*/src/**
      - interfaces/*/examples/**
      - interfaces/*/Cargo.toml
      - models/*/src/**
      - models/*/examples/**
      - models/*/Cargo.toml
      - floneum/*/src/**
      - floneum/*/examples/**
      - floneum/*/Cargo.toml
      - fusor-ml/*/src/**
      - fusor-ml/*/tests/**
      - fusor-ml/*/examples/**
      - fusor-ml/*/Cargo.toml
      - src/**
      - .github/**
      - Cargo.toml

concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true

jobs:
  test:
    if: github.event.pull_request.draft == false
    runs-on: windows-2022
    name: (${{ matrix.target }}, ${{ matrix.cfg_release_channel }})
    env:
      CFG_RELEASE_CHANNEL: ${{ matrix.cfg_release_channel }}
    strategy:
      matrix:
        target: [x86_64-pc-windows-msvc]
        cfg_release_channel: [stable]

    steps:
      - name: disable git eol translation
        run: git config --global core.autocrlf false

      - name: Install Rustup using win.rustup.rs
        shell: powershell
        run: |
          $ProgressPreference = "SilentlyContinue"
          Invoke-WebRequest https://win.rustup.rs/ -OutFile rustup-init.exe
          .\rustup-init.exe -y --default-host=x86_64-pc-windows-msvc --default-toolchain=none
          del rustup-init.exe
          rustup target add ${{ matrix.target }}

      - name: checkout
        uses: actions/checkout@v6

      - name: Setup WARP
        shell: bash
        run: |
          curl -L --retry 5 https://www.nuget.org/api/v2/package/Microsoft.Direct3D.WARP/1.0.8 -o warp.zip
          7z e warp.zip -owarp build/native/amd64/d3d10warp.dll

      - name: Setup DXC
        shell: bash
        run: |
          curl -L --retry 5 https://github.com/microsoft/DirectXShaderCompiler/releases/download/v1.7.2308/dxc_2023_08_14.zip -o dxc.zip
          7z e dxc.zip -odxc bin/x64/dxcompiler.dll bin/x64/dxil.dll

      - uses: Swatinem/rust-cache@v2

      - name: test
        shell: cmd
        env:
          OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
          ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
          GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
          FUSOR_CONFORMANCE_REQUIRE_GPU: "1"
        run: |
          rustc -Vv
          cargo -V
          set RUST_BACKTRACE=1
          mkdir target\debug\deps 2>nul
          copy warp\d3d10warp.dll target\debug\deps\
          copy dxc\dxcompiler.dll target\debug\deps\
          copy dxc\dxil.dll target\debug\deps\
          cargo test --all --tests --features kalosm/language,kalosm/sound,kalosm/vision,kalosm/remote,kalosm/scrape --exclude kalosm-parse-macro --exclude fusor-core --exclude rbert --exclude rwhisper --exclude kalosm-learning