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@master

      - name: Install ${{ matrix.version }}
        uses: actions-rs/toolchain@v1
        with:
          toolchain: ${{ matrix.version }}-x86_64-pc-windows-msvc
          profile: minimal
          override: true

      - name: Generate Cargo.lock
        uses: actions-rs/cargo@v1
        with:
          command: generate-lockfile

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

      - name: Cache Dependencies
        uses: Swatinem/rust-cache@v1.0.1

      - name: Install OpenSSL
        run: |
          vcpkg integrate install
          vcpkg install openssl:x64-windows
          Copy-Item C:\vcpkg\installed\x64-windows\bin\libcrypto-1_1-x64.dll C:\vcpkg\installed\x64-windows\bin\libcrypto.dll
          Copy-Item C:\vcpkg\installed\x64-windows\bin\libssl-1_1-x64.dll C:\vcpkg\installed\x64-windows\bin\libssl.dll
          Get-ChildItem C:\vcpkg\installed\x64-windows\bin
          Get-ChildItem C:\vcpkg\installed\x64-windows\lib

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