#version: '3.0.1.{build}'
#
# When planning updates here, check availability at:
# https://www.appveyor.com/docs/windows-images-software/
# This is slow, try to keep the number of builds as low as makes sense.

image:
  # linux builds done in Travis CI for now
  - Visual Studio 2017
  - Visual Studio 2019
  - Visual Studio 2022

cache:
  - downloads -> appveyor.yml
  - '%LOCALAPPDATA%\pip\Cache'
  - C:\ProgramData\chocolatey\bin -> appveyor.yml
  - C:\ProgramData\chocolatey\lib -> appveyor.yml

install:
  # direct choco install supposed to work, but not? still doing in install.bat
  #- cinst: dmd ldc swig vswhere ixsltproc winflexbison3
  - cmd: .\.appveyor\install.bat
  - cmd: if %COVERAGE% equ 1 .\.appveyor\install-cov.bat

# Build matrix will be number of images multiplied by #entries in matrix:,
# less any excludes.
#
# "Build" is kind of a misnomer - we are actually running the test suite,
# and this is slow on Windows, so keep the matrix as small as possible.
# Leaving the Coverage build on VS2017 for build-time reasons (1hr time limit).
# maybe move coverage to github in future to restore some flexibility?
environment:
  # set COVERAGE to 1 for any builder that should run it
  COVERAGE: 0
  SCONS_CACHE_MSVC_CONFIG: "true"
  matrix:
    # Test oldest and newest supported Pythons, and a subset in between.
    # Skipping 3.8, 3.10, 3.12 at this time
    - WINPYTHON: "Python313"
    - WINPYTHON: "Python311"
    - WINPYTHON: "Python39"
    - WINPYTHON: "Python37"

# remove sets of build jobs based on criteria below
# to fine tune the number and platforms tested
matrix:
  exclude:
    # test python 3.7 on Visual Studio 2017 image
    - image: Visual Studio 2017
      WINPYTHON: "Python313"
    - image: Visual Studio 2017
      WINPYTHON: "Python311"
    - image: Visual Studio 2017
      WINPYTHON: "Python39"

    # test python 3.9 on Visual Studio 2019 image
    - image: Visual Studio 2019
      WINPYTHON: "Python313"
    - image: Visual Studio 2019
      WINPYTHON: "Python311"
    - image: Visual Studio 2019
      WINPYTHON: "Python37"

    # test python 3.11, 3.13 on Visual Studio 2022 image
    - image: Visual Studio 2022
      WINPYTHON: "Python39"
    - image: Visual Studio 2022
      WINPYTHON: "Python37"

# Remove some binaries we don't want to be found
# Note this is no longer needed, git-windows bin/ is quite minimal now.
before_build:
    - ps: .\.appveyor\ignore_git_bins.ps1

build: off

build_script:
  # Image version-based excludes:
  # No excludes at the moment, but the exclude script generates the
  # (possibly empty) exclude_list.txt which is used in the following step,
  # so leave the scheme in place in case we need to put back excludes later.
  - ps: .\.appveyor\exclude_tests.ps1

  # setup coverage by creating the coverage config file, and adding coverage
  # to the sitecustomize so that all python processes start with coverage
  - ps: if ($env:COVERAGE -eq 1) { .\.appveyor\coverage_setup.ps1 }

  # NOTE: running powershell from cmd is intended because
  # it formats the output correctly
  - cmd: powershell -Command "& { if($env:COVERAGE -eq 1) { coverage run -p --rcfile=$($env:COVERAGE_PROCESS_START) runtest.py -j 2 -t --exclude-list exclude_list.txt -a } else { C:\\%WINPYTHON%\\python.exe runtest.py -j 2 -t --exclude-list exclude_list.txt -a }; if($LastExitCode -eq 2 -Or $LastExitCode -eq 0) { $host.SetShouldExit(0 )} else {$host.SetShouldExit(1)}}"

# run coverage even if there was a test failure
on_finish:
  - ps: if ($env:COVERAGE -eq 1) { .\.appveyor\coverage_report.ps1 }
  # running codecov in powershell causes an error so running in cmd
  - cmd: if %COVERAGE% equ 1 codecov -X gcov --file coverage_xml.xml

