# This file is part of ssh2-python.
# Copyright (C) 2017-2021 Panos Kittenis and contributors.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation, version 2.1.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
max_jobs: 5
build:
  parallel: true
  verbosity: minimal
skip_branch_with_pr: true
image: Visual Studio 2019
clone_script: echo Skip AppVeyor Clone

environment:
  global:
    PYTHONUNBUFFERED: 1
    SYSTEM_LIBSSH2: 1
    PYPI_USER:
      secure: WKF8ok0UPIgkA+isDUuHww==
    PYPI_PASS:
      secure: uXkrTaPGSNQdXTJIt3aiyyGnH/ZtvWbDVIXdMrsgwROIJ0kprWp5crS6TAqqddyrFxd7Trrfjg/TjM1/Yx9JzfuKTfoJh1zyviWD/j2zibsycmJQy4Q+CrZ6uI3IRQwe/2ILKxGzLGFBWaqt6C8NaQnkKP+h7ptnPeVhy1+kaOaJowwrCKWje1Ag3CJCAJxPjSC8yl1nlM3DA1rAIk2C5SR4eQQLJeEpPSg3nDnxR4o4YjmA7ILD3OuM1Fbh5iue/rUvWzdt6QCxCbE4egtrCQ==
    # Default python version to run single commands with
    PYTHON_DEF: "C:\\Python38-x64"
    PYTHON_VERSION: "3.8"
    # Python versions to build wheels for
    PYTHONVERS: C:\Python38-x64 C:\Python39-x64 C:\Python310-x64 C:\Python311-x64 C:\Python312-x64 C:\Python313-x64
    PYTHON_ARCH: "64"
    MSVC: "Visual Studio 16 2019"

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 it is problematic because it tends to cancel builds pushed
  # directly to master instead of just PR builds (or the converse).
  # 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." }

  # Git checkout
  - git config --global filter.lfs.smudge "git-lfs smudge --skip -- %f"
  - git config --global filter.lfs.process "git-lfs filter-process --skip"
  - git init %APPVEYOR_BUILD_FOLDER%
  - cd %APPVEYOR_BUILD_FOLDER%
  - git remote add origin https://github.com/%APPVEYOR_REPO_NAME%.git
  - git fetch -q origin %APPVEYOR_REPO_COMMIT%
  - git fetch --tags
  - git checkout -qf %APPVEYOR_REPO_COMMIT%

  - set OPENSSL_DIR="C:\OpenSSL-v34-Win64"
  - set VCLIBDIR=%WINDIR%\System32
  - cp %VCLIBDIR%/vcruntime140.dll ssh2/
  - cp %VCLIBDIR%/msvcr120.dll ssh2/
  - cp %OPENSSL_DIR%/bin/*.dll ssh2/
  - ps: ls ssh2/*.dll

  - for %%I in (%PYTHONVERS%) do %%I\python.exe -V
  - for %%I in (%PYTHONVERS%) do %%I\Scripts\pip install -U wheel setuptools twine cython

  # .c files need to be generated on Windows to handle platform
  # specific code.
  # Fix version used by versioneer to current git tag so the generated .c files
  # do not cause a version change.
  - "%PYTHON_DEF%\\python.exe ci/appveyor/fix_version.py ."
  - mv -f .git .git.bak

build_script:
  - dir %OPENSSL_DIR%\lib\VC\x64\MD\
  - for %%I in (%PYTHONVERS%) do cp %OPENSSL_DIR%/lib/VC/x64/MD/libcrypto.lib %%I/libs/libcrypto64MD.lib
  - for %%I in (%PYTHONVERS%) do cp %OPENSSL_DIR%/lib/VC/x64/MD/libssl.lib %%I/libs/libssl64MD.lib
  - ci\\appveyor\\build_zlib.bat
  - for %%I in (%PYTHONVERS%) do cp C:/zlib/lib/zlibstatic.lib %%I/libs/
  - for %%I in (%PYTHONVERS%) do ls %%I/libs/
  - ci\\appveyor\\build_ssh2.bat
  - for %%I in (%PYTHONVERS%) do cp build_dir/src/Release/libssh2.lib %%I/libs/
  - for %%I in (%PYTHONVERS%) do ls %%I/libs/
  - rm -f ssh2/*.c

test_script:
  - ci\\appveyor\\build_package.bat

artifacts:
  - path: "*.whl"

deploy_script:
  # Calling twine requires we set path
  - "SET PATH=%PYTHON_DEF%;%PYTHON_DEF%\\Scripts;%PATH%"
  - python ci/appveyor/pypi_upload.py *.whl
