name: Windows

on:
  push:
  pull_request:
  schedule:
    - cron: "35 7 * * *" # UTC

jobs:
  build:
    runs-on: windows-latest
    strategy:
      matrix:
        config:
          - {
              target: "x86_64-pc-windows-msvc",
              VCPKG_DEFAULT_TRIPLET: "x64-windows-static",
              RUSTFLAGS: "-Ctarget-feature=+crt-static",
            }
          - {
              target: "x86_64-pc-windows-msvc",
              VCPKG_DEFAULT_TRIPLET: "x64-windows-static-md",
            }
          - {
              target: "x86_64-pc-windows-msvc",
              VCPKG_DEFAULT_TRIPLET: "x64-windows",
              VCPKGRS_DYNAMIC: 1,
            }
          - {
              target: "i686-pc-windows-msvc",
              VCPKG_DEFAULT_TRIPLET: "x86-windows-static",
              RUSTFLAGS: "-Ctarget-feature=+crt-static",
            }
          - {
              target: "i686-pc-windows-msvc",
              VCPKG_DEFAULT_TRIPLET: "x86-windows-static-md",
            }
          - {
              target: "i686-pc-windows-msvc",
              VCPKG_DEFAULT_TRIPLET: "x86-windows",
              VCPKGRS_DYNAMIC: 1,
            }
      fail-fast: false
    steps:
      - uses: actions/checkout@v2
      - name: Dump GitHub context
        env:
          GITHUB_CONTEXT: ${{ toJson(github) }}
        run: echo "$Env:GITHUB_CONTEXT"
      - name: Dump job context
        env:
          JOB_CONTEXT: ${{ toJson(job) }}
        run: echo "$JOB_CONTEXT"
      - name: Dump steps context
        env:
          STEPS_CONTEXT: ${{ toJson(steps) }}
        run: echo "$STEPS_CONTEXT"
      - name: Dump runner context
        env:
          RUNNER_CONTEXT: ${{ toJson(runner) }}
        run: echo "$RUNNER_CONTEXT"
      - name: Dump strategy context
        env:
          STRATEGY_CONTEXT: ${{ toJson(strategy) }}
        run: echo "$STRATEGY_CONTEXT"
      - name: Dump matrix context
        env:
          MATRIX_CONTEXT: ${{ toJson(matrix) }}
        run: echo "$MATRIX_CONTEXT"
      - name: Install the target
        run: rustup target add ${{ matrix.config.target }}
      - name: Run build
        run: cargo build --target ${{ matrix.config.target }} --verbose
      - name: Run unit tests
        run: cargo test --target ${{ matrix.config.target }} --verbose
      - name: Install vcpkg
        run: |
          git clone https://github.com/Microsoft/vcpkg.git vcp
          vcp\bootstrap-vcpkg.bat
      - name: Set env
        shell: bash
        run: |
          echo "VCPKG_ROOT=${{ github.workspace }}\vcp" >> $GITHUB_ENV
      - name: Run integration tests
        env:
          RUST_BACKTRACE: 1
          RUST_TEST_THREADS: 1
          VCPKG_DEFAULT_TRIPLET: "${{ matrix.config.VCPKG_DEFAULT_TRIPLET }}"
          RUSTFLAGS: ${{ matrix.config.RUSTFLAGS }}
        shell: bash
        run: |
          set -ex
          rustc --version
          cargo --version
          echo VCPKG_ROOT=${VCPKG_ROOT}
          echo dyn=${{ matrix.config.VCPKGRS_DYNAMIC }}
          if [ '${{ matrix.config.VCPKGRS_DYNAMIC }}' != '' ] ; then export VCPKGRS_DYNAMIC=1 ; fi
          ${VCPKG_ROOT}/vcpkg.exe install curl zeromq openssl
          cargo build --target ${{ matrix.config.target }} --all
          cargo test --target ${{ matrix.config.target }} --all
          cargo run --target ${{ matrix.config.target }} --manifest-path vcpkg_cli/Cargo.toml -- probe curl
          cargo run --target ${{ matrix.config.target }} --manifest-path systest/Cargo.toml
