version: 1.0.{build}

# msvc arch decode is host_target

environment:
  matrix:
  - arch: x86_amd64
    qt: 5.12\msvc2017_64
    flow: nmake
    APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
  - arch: x86_amd64
    qt: 5.12\msvc2017_64
    flow: msbuild
    APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
  - arch: x86
    qt: 5.12\msvc2017
    flow: nmake
    APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
  #- arch: x86
  #  qt: 5.9\msvc2015
  #  flow: nmake
  #  APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
  #- arch: amd64
  #  qt: 5.9\msvc2015_64
  #  flow: nmake
  #  APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015

init:
  - set PATH=C:\Qt\%qt%\bin;%PATH%
  - if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2015" call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" %arch%
  - if "%APPVEYOR_BUILD_WORKER_IMAGE%"=="Visual Studio 2017" call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" %arch%

build_script:
  - ps: |
      # be aware that vcvarsall will reset platform amd64 to X64!
      echo "arch: $env:arch"
      echo "qt: $env:qt"
      qmake -query
      Get-Location
      if (($env:flow -eq "nmake") -and ($env:arch -eq "x86_amd64") -and ($env:qt -eq "5.12\msvc2017_64"))
      {
        # full build and deploy of our release configuration
        & ".\tools\make_windows_release.ps1" -flow $env:flow -buildinstaller "true" -arch $env:arch
        $verid=(Get-Date -UFormat "%Y%m%dT%H%MZ" -Date (Get-Date -Date (git show -s --format="%aI" HEAD)).toUniversalTime()) `
               + '-' + (git rev-parse --short=7 HEAD)
        Get-ChildItem .\gui\release\GPSBabel-*-Setup.exe | % { Push-AppveyorArtifact $_.FullName -FileName "GPSBabel-$($verid)-Setup.exe" }
        Get-ChildItem .\gui\release\GPSBabel-*-Manifest.txt | % { Push-AppveyorArtifact $_.FullName -FileName "GPSBabel-$($verid)-Manifest.txt" }
      }
      else
      {
        & ".\tools\make_windows_release.ps1" -flow $env:flow -arch $env:arch
      }
      # work around issue with standard error output causing a build failure by making sure last command succeeds.
      # see https://help.appveyor.com/discussions/problems/10014-false-build-fail-status
      Write-Host "Finished build_script"

test_script:
  - ps: |
      $env:projdir=(C:\msys64\usr\bin\bash.exe -c "pwd")
      C:\msys64\usr\bin\bash.exe -lc "echo $env:projdir"
      # work around issue with standard error output from xmllint causing a build failure by redirecting stderr.
      # in this case making sure the last command succeeds is not sufficient.
      # see https://help.appveyor.com/discussions/problems/10014-false-build-fail-status
      C:\msys64\usr\bin\bash.exe -lc "cd $env:projdir; PNAME=./release/GPSBabel.exe GBTEMP=./gbtemp ./testo 2>&1"
      if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode)  }
      C:\msys64\usr\bin\bash.exe -lc "cd $env:projdir; PNAME=./release/GPSBabel.exe GBTEMP=./gbtemp ./test_encoding_utf8 2>&1"
      Write-Host "Finished test_script with exit status $LastExitCode"
      if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode)  }

deploy_script:
  - ps: |
      $env:projdir=(C:\msys64\usr\bin\bash.exe -c "pwd")
      C:\msys64\usr\bin\bash.exe -lc "cd $env:projdir; ./tools/ci_tokens"
      if (($env:flow -eq "nmake") -and ($env:arch -eq "x86_amd64") -and ($env:qt -eq "5.12\msvc2017_64") -and ($env:APPVEYOR_REPO_BRANCH -eq "master"))
      {
        $verid=(Get-Date -UFormat "%Y%m%dT%H%MZ" -Date (Get-Date -Date (git show -s --format="%aI" HEAD)).toUniversalTime()) `
               + '-' + (git rev-parse --short=7 HEAD)
        C:\msys64\usr\bin\bash.exe -lc "cd $env:projdir; ls ./gui/release/*.exe"
        C:\msys64\usr\bin\bash.exe -lc "cd $env:projdir; cp -p ./gui/release/GPSBabel-*-Setup.exe GPSBabel-$($verid)-Setup.exe"
        C:\msys64\usr\bin\bash.exe -lc "cd $env:projdir; ./tools/uploadtool/upload_appveyor.sh GPSBabel-$($verid)-Setup.exe"
        Write-Host "Finished deploy_script"
      }

#deploy:
#  tag: 'continuous windows'
#  release: 'Continuous windows build'
#  description: 'Continuous build'
#  provider: GitHub
#  auth_token:
#    secure: gOkGevzhckv5gwFMhnyRk9JZqn6eaZ4vdVFkRdjL6p6NNZu7mwf8aTfMhWSnhaS2 # your encrypted token from GitHub
#  artifact: /GPSBabel.*Setup.exe/      # upload installer to release assets
#  draft: false
#  prerelease: true
#  on:
#    branch: master                 # release from master branch only
#    appveyor_repo_tag: false       # deploy on tag push only
#    platform: x86
#    qt: 5.9\msvc2015

skip_tags: true
