# Appveyor, continuous integration for Windows
# https://ci.appveyor.com/project/nedbat/coveragepy

version: '{branch}-{build}'

shallow_clone: true

cache:
  - '%LOCALAPPDATA%\pip\Cache'

environment:

  CMD_IN_ENV: "cmd /E:ON /V:ON /C .\\ci\\run_with_env.cmd"

  PYTEST_ADDOPTS: "-n auto"

  # Note: There is logic to install Python version $PYTHON_VERSION if the
  # $PYTHON directory doesn't exist.  $PYTHON_VERSION is visible in the job
  # descriptions, but can be wrong in the minor version, since we use the
  # version pre-installed on AppVeyor.
  #
  matrix:
    - JOB: "2.7 64-bit"
      TOXENV: "py27"
      PYTHON: "C:\\Python27-x64"
      PYTHON_VERSION: "2.7.17"
      PYTHON_ARCH: "64"

    - JOB: "3.5 64-bit"
      TOXENV: "py35"
      PYTHON: "C:\\Python35-x64"
      PYTHON_VERSION: "3.5.9"
      PYTHON_ARCH: "64"

    - JOB: "3.6 64-bit"
      TOXENV: "py36"
      PYTHON: "C:\\Python36-x64"
      PYTHON_VERSION: "3.6.9"
      PYTHON_ARCH: "64"

    - JOB: "3.7 64-bit"
      TOXENV: "py37"
      PYTHON: "C:\\Python37-x64"
      PYTHON_VERSION: "3.7.5"
      PYTHON_ARCH: "64"

    - JOB: "3.8 64-bit"
      TOXENV: "py38"
      PYTHON: "C:\\Python38-x64"
      PYTHON_VERSION: "3.8.0"
      PYTHON_ARCH: "64"

    - JOB: "3.9 64-bit"
      TOXENV: "py39"
      PYTHON: "C:\\Python39-x64"
      PYTHON_VERSION: "3.9.0a3"
      PYTHON_ARCH: "64"

    # 32-bit jobs don't run the tests under the Python tracer, since that should
    # be exactly the same as 64-bit.
    - JOB: "2.7 32-bit"
      TOXENV: "py27"
      PYTHON: "C:\\Python27"
      PYTHON_VERSION: "2.7.17"
      PYTHON_ARCH: "32"
      COVERAGE_NO_PYTRACER: "1"

    - JOB: "3.5 32-bit"
      TOXENV: "py35"
      PYTHON: "C:\\Python35"
      PYTHON_VERSION: "3.5.9"
      PYTHON_ARCH: "32"
      COVERAGE_NO_PYTRACER: "1"

    - JOB: "3.6 32-bit"
      TOXENV: "py36"
      PYTHON: "C:\\Python36"
      PYTHON_VERSION: "3.6.9"
      PYTHON_ARCH: "32"
      COVERAGE_NO_PYTRACER: "1"

    - JOB: "3.7 32-bit"
      TOXENV: "py37"
      PYTHON: "C:\\Python37"
      PYTHON_VERSION: "3.7.5"
      PYTHON_ARCH: "32"
      COVERAGE_NO_PYTRACER: "1"

    - JOB: "3.8 32-bit"
      TOXENV: "py38"
      PYTHON: "C:\\Python38"
      PYTHON_VERSION: "3.8.0"
      PYTHON_ARCH: "32"
      COVERAGE_NO_PYTRACER: "1"

    - JOB: "3.9 32-bit"
      TOXENV: "py39"
      PYTHON: "C:\\Python39"
      PYTHON_VERSION: "3.9.0a3"
      PYTHON_ARCH: "32"
      COVERAGE_NO_PYTRACER: "1"

    # Meta coverage
    - JOB: "Meta 2.7"
      TOXENV: "py27"
      PYTHON: "C:\\Python27"
      PYTHON_VERSION: "2.7.17"
      PYTHON_ARCH: "32"
      COVERAGE_COVERAGE: "yes"

    - JOB: "Meta 3.6"
      TOXENV: "py36"
      PYTHON: "C:\\Python36"
      PYTHON_VERSION: "3.6.9"
      PYTHON_ARCH: "32"
      COVERAGE_COVERAGE: "yes"

init:
  - "ECHO %TOXENV%"

install:
  # Install Python (from the official .msi of http://python.org) and pip when
  # not already installed.
  - ps: if (-not(Test-Path($env:PYTHON))) { & ci\install.ps1 }

  # Prepend newly installed Python to the PATH of this build (this cannot be
  # done from inside the powershell script as it would require to restart
  # the parent CMD process).
  - "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%"

  # Check that we have the expected version and architecture for Python
  - "python -c \"import struct, sys; print('{}\\n{}-bit'.format(sys.version, struct.calcsize('P') * 8))\""

  # Upgrade to the latest version of pip to avoid it displaying warnings
  # about it being out of date.
  - "python -m pip install --disable-pip-version-check --upgrade pip"
  # And upgrade virtualenv to get the latest pip inside .tox virtualenvs.
  - "python -m pip install --disable-pip-version-check --upgrade virtualenv"

  # Install requirements.
  - "%CMD_IN_ENV% pip install -r requirements/ci.pip"

  # Make a pythonX.Y.bat file in the current directory so that tox will find it
  # and pythonX.Y will mean what we want it to.
  - "python -c \"import os; open('python{}.{}.bat'.format(*os.environ['TOXENV'][2:]), 'w').write('@{}\\\\python \\x25*\\n'.format(os.environ['PYTHON']))\""

build_script:
  # If not a metacov job, then build wheel installers.
  - if NOT "%COVERAGE_COVERAGE%" == "yes" %CMD_IN_ENV% %PYTHON%\python setup.py bdist_wheel

  # Push everything in dist\ as an artifact.
  - ps: if ( Test-Path 'dist' -PathType Container ) { Get-ChildItem dist\*.* | % { Push-AppveyorArtifact $_.FullName -FileName ('dist\' + $_.Name) } }

test_script:
  - "%CMD_IN_ENV% %PYTHON%\\Scripts\\tox"

after_test:
  - if "%COVERAGE_COVERAGE%" == "yes" 7z a metacov-win-%TOXENV%.zip %APPVEYOR_BUILD_FOLDER%\.metacov*
  - if "%COVERAGE_COVERAGE%" == "yes" %CMD_IN_ENV% %PYTHON%\python igor.py combine_html
  - if "%COVERAGE_COVERAGE%" == "yes" %CMD_IN_ENV% pip install codecov
  - if "%COVERAGE_COVERAGE%" == "yes" %CMD_IN_ENV% codecov -X gcov --file coverage.xml

# Uncomment this to enable RDP access to the build when done.
# https://www.appveyor.com/docs/how-to/rdp-to-build-worker/
# on_finish:
#   - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))

artifacts:
  - path: "metacov-*.zip"
