name: CI (Windows)

on: [push, pull_request]

env:
  VCPKGRS_DYNAMIC: 1

jobs:
  build_and_test:
    strategy:
      fail-fast: false
      matrix:
        version:
          - stable
          - nightly

    name: ${{ matrix.version }} - x86_64-pc-windows-msvc
    runs-on: windows-latest

    steps:
      - uses: actions/checkout@v4

      - name: Install ${{ matrix.version }}
        uses: actions-rust-lang/setup-rust-toolchain@v1
        with:
          toolchain: ${{ matrix.version }}-x86_64-pc-windows-msvc
      - name: Generate Cargo.lock
        run: cargo generate-lockfile

      - name: Cache vcpkg
        uses: actions/cache@v4
        with:
          path: C:\vcpkg\installed\
          key: x86_64-pc-windows-msvc-openssl

      - name: Cache cargo registry
        uses: actions/cache@v4
        with:
          path: ~/.cargo/registry
          key: ${{ matrix.version }}-x86_64-pc-windows-msvc-cargo-registry-trimmed-${{ hashFiles('**/Cargo.lock') }}

      - name: Cache cargo index
        uses: actions/cache@v4
        with:
          path: ~/.cargo/git
          key: ${{ matrix.version }}-x86_64-pc-windows-msvc-cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}

      - name: Run tests
        uses: actions-rs/cargo@v1
        with:
          command: test
          args: --all --features=ntex/tokio -- --nocapture
