# AppVeyor CI
# https://www.appveyor.com/docs

image:
  - Visual Studio 2019

environment:
  matrix:
    # For Python versions available on AppVeyor, see
    # http://www.appveyor.com/docs/installed-software#python
    - PYTHON: "C:\\Python312-x64"

install:
  - "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%"
  - "python -c \"import sys; print(sys.prefix)\""
  - "python -c \"import sys; print(sys.exec_prefix)\""
  - "python -c \"import sys; print(sys.executable)\""
  - "python -V -V"
  - "python -m pip install -r requirements-pip.txt"
  - "python -m pip install -r requirements-ci.txt"
  - "python -m pip list"
  # Check that pywin32 is properly installed
  - "python -c \"import win32api\""

build: false

test_script:
  # Note that Twisted Trial does not support multiple jobs on Windows
  # The following error is printed: "Customizing childFDs is not supported on Windows."
  - "coverage run --rcfile=common/coveragerc -m twisted.trial --reporter=text --rterrors buildbot.test buildbot_worker.test"
  - ps: |
          echo $ENV:PYTHON
          if ($env:PYTHON -imatch 'C:\\Python27') {
            iex 'pyinstaller pyinstaller/buildbot-worker.spec'
            iex 'appveyor PushArtifact dist\\buildbot-worker.exe'
          }

on_success:
  - "coverage xml --rcfile=common/coveragerc -o coverage.xml -i"
  - ps: |
        (New-Object System.Net.WebClient).DownloadFile("https://uploader.codecov.io/v0.4.1/windows/codecov.exe", (Join-Path $pwd "codecov.exe"))
        .\codecov.exe

on_failure:
  # Store _trial_temp directory as artifact on build failure.
  # See <https://www.appveyor.com/docs/packaging-artifacts#pushing-artifacts-from-scripts>
  - ps: |
          $root = Resolve-Path _trial_temp;
          [IO.Directory]::GetFiles($root.Path, '*.*', 'AllDirectories') | % {
              Push-AppveyorArtifact $_ -FileName $_.Substring($root.Path.Length + 1) -DeploymentName trial-log
            }

# Uncomment this part if you want to interactively debug tests on AppVeyor.
# This will pause build at the end and setup RDP server.
# Connection details will be printed in the build log.
# For detail see: 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'))

deploy:
  release: $(APPVEYOR_REPO_TAG_NAME)
  description: 'windows binary for buildbot-worker'
  provider: GitHub
  auth_token:
    secure: HQNlcAyaY9Jznbl77rfNatZG62Gg+qFY7emzj5n3Wu16fkr8dLlFNTKOJlfXO5uK
  artifact: "buildbot-worker.exe"
  draft: false
  prerelease: false
  on:
    appveyor_repo_tag: true        # deploy on tag push only
    PYTHON: "C:\\Python35"
