version: 1.4.{build}
image: Visual Studio 2019
configuration: Release
environment:
  global:
    TWINE_USERNAME: jdavid
    TWINE_PASSWORD:
      secure: m6oBGys2nmQTRn7vDv8/FA==
  matrix:
  - GENERATOR: 'Visual Studio 14'
    PYTHON: 'C:\Python36\python.exe'
  - GENERATOR: 'Visual Studio 14 Win64'
    PYTHON: 'C:\Python36-x64\python.exe'
  - GENERATOR: 'Visual Studio 14'
    PYTHON: 'C:\Python37\python.exe'
  - GENERATOR: 'Visual Studio 14 Win64'
    PYTHON: 'C:\Python37-x64\python.exe'
  - GENERATOR: 'Visual Studio 14'
    PYTHON: 'C:\Python38\python.exe'
  - GENERATOR: 'Visual Studio 14 Win64'
    PYTHON: 'C:\Python38-x64\python.exe'
  - GENERATOR: 'Visual Studio 14'
    PYTHON: 'C:\Python39\python.exe'
  - GENERATOR: 'Visual Studio 14 Win64'
    PYTHON: 'C:\Python39-x64\python.exe'

matrix:
  fast_finish: true

init:
- cmd: |
    "%PYTHON%" -m pip install -U pip
    "%PYTHON%" -m pip install -U wheel pytest

build_script:
# Clone, build and install libgit2
- cmd: |
    set LIBGIT2=%APPVEYOR_BUILD_FOLDER%\venv
    git clone --depth=1 -b ethomson/v1.1 https://github.com/libgit2/libgit2.git libgit2
    cd libgit2
    cmake . -DBUILD_CLAR=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="%LIBGIT2%" -G "%GENERATOR%"
    cmake --build . --target install
    cd ..

# Build and install pygit2
# Rename pygit2 folder, so when testing it picks the installed one
- cmd: |
    "%PYTHON%" setup.py bdist_wheel
    cd dist
    "%PYTHON%" -m pip install --find-links=. pygit2
    cd ..
    mv pygit2 pygit2.bak

test_script:
- ps: |
    &$env:PYTHON -m pytest test --junitxml=testresults.xml

    if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) }

    # upload results to AppVeyor
    $wc = New-Object 'System.Net.WebClient'
    $wc.UploadFile("https://ci.appveyor.com/api/testresults/junit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path ".\testresults.xml"))

artifacts:
- path: dist\*.whl

deploy_script:
- ps: if ($env:APPVEYOR_REPO_TAG -eq $TRUE) { pip install twine; twine upload dist/* }

deploy: on
