# vim ft=yaml
# CI on Windows via appveyor

environment:
  global:
      # SDK v7.0 MSVC Express 2008's SetEnv.cmd script will fail if the
      # /E:ON and /V:ON options are not enabled in the batch script interpreter
      # See: http://stackoverflow.com/a/13751649/163740
      CMD_IN_ENV: "cmd /E:ON /V:ON /C .\\ci\\windows\\run_with_env.cmd"
      EXTRA_PIP_FLAGS: "--timeout=60"

  matrix:
    - PYTHON: C:\Miniconda36-x64
    - PYTHON: C:\Python35-x64
    - PYTHON: C:\Python36-x64
    - PYTHON: C:\Python36-x64
      OPTIONAL_DEPS: 1

platform:
    - x64

init:
  - systeminfo
  - ps: iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))

# on_finish:
#   - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))

install:
  # If there is a newer build queued for the same PR, cancel this one.
  # The AppVeyor 'rollout builds' option is supposed to serve the same
  # purpose but is problematic because it tends to cancel builds pushed
  # directly to master instead of just PR builds.
  # credits: JuliaLang developers.
  - ps: if ($env:APPVEYOR_PULL_REQUEST_NUMBER -and $env:APPVEYOR_BUILD_NUMBER -ne ((Invoke-RestMethod `
        https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/history?recordsNumber=50).builds | `
        Where-Object pullRequestId -eq $env:APPVEYOR_PULL_REQUEST_NUMBER)[0].buildNumber) { `
        throw "There are newer queued builds for this pull request, failing early." }
  # Install OpenGL
  - "powershell ./ci/windows/install_opengl.ps1"

  # Headless trick. More info: https://help.appveyor.com/discussions/problems/3586-black-screenshots#comment_38618584
  - ps: iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-desktop.ps1'))
  # Setup some environment variable
  - ps: $env:Path = "$env:PYTHON;$env:PYTHON\\Scripts;$env:Path"
  - ps: Write-Output "Env Path = " + $env:Path

  - ps: $env:PYTHON_ARCH = python -c "import struct; print(struct.calcsize('P') * 8)"
  - ps: $env:PYTHON_VERSION = python -c "import platform;print(platform.python_version())"

  # Check that we have the expected version and architecture for Python
  - "python --version"
  - ps: Write-Output "Python version = " + $env:PYTHON_VERSION
  - ps: Write-Output "Python architecture = " + $env:PYTHON_ARCH

  - "%CMD_IN_ENV% powershell ./ci/windows/install.ps1"

build: false # Not a C# project, build stuff at the test step instead.

cache:
  # Avoid re-downloading large packages. More info: https://www.appveyor.com/docs/build-cache/
  - '%LOCALAPPDATA%\pip\Cache -> appveyor.yml'

test_script:
  - ps: ./ci/windows/script.ps1
