platform: x64

image: Visual Studio 2017

branches:
  only:
    - master
    - 2.2

environment:
  my_secret:
    secure: ngfIQmr9kcRyopeRyHZG8g==
  MINGW_DIR: mingw64
  MINGW_URL: https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/8.1.0/threads-win32/seh/x86_64-8.1.0-release-win32-seh-rt_v6-rev0.7z
  MINGW_ARCHIVE: x86_64-8.1.0-release-win32-seh-rt_v6-rev0.7z
  TCLKIT_URL: http://kitcreator.rkeene.org/kits/43b2a6f8b159514a79e4330cb4d2dbb3a47f7acc/tclkit.exe
  TCLKIT: tclkit.exe
  matrix:
  - TCLTAG: core-8-6-branch
    TOOLCHAIN: autoconf-tea
  - TCLTAG: core-8-6-branch
    TOOLCHAIN: nmake-tea
  - TCLTAG: core-8-6-9
    TOOLCHAIN: autoconf-tea
  - TCLTAG: core-8-6-9
    TOOLCHAIN: nmake-tea
  - TCLTAG: core-8-5-branch
    TOOLCHAIN: autoconf-tea
  - TCLTAG: core-8-5-19
    TOOLCHAIN: autoconf-tea	
  - TCLTAG: core-8-7-a1
    TOOLCHAIN: autoconf-tea
  - TCLTAG: core-8-branch
    TOOLCHAIN: autoconf-tea

matrix:
  allow_failures:
  - TCLTAG: core-8-6-branch
  - TCLTAG: core-8-5-branch
  - TCLTAG: core-8-branch
  fast_finish: true

install:
  - ps: iex ((New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/appveyor/secure-file/master/install.ps1'))
  - appveyor-tools\secure-file -decrypt deploy_key.appveyor.enc -out deploy_key -secret %my_secret%
  - appveyor-retry choco install openssh -confirm
  # - if not exist "%MINGW_ARCHIVE%" appveyor DownloadFile "%MINGW_URL%" -FileName "%MINGW_ARCHIVE%"
  # - 7z x -y "%MINGW_ARCHIVE%" > nul
  - if not exist "%TCLKIT%" appveyor DownloadFile "%TCLKIT_URL%" -FileName "%TCLKIT%"

build_script:
  - if "%TOOLCHAIN%" == "autoconf-tea" set CHERE_INVOKING=1
  - if "%TOOLCHAIN%" == "autoconf-tea" set PATH=C:\msys64\mingw64\bin;C:\msys64\usr\bin;%PATH%
  # Needed to align MSYS and Windows HOME dirs
  - if "%TOOLCHAIN%" == "autoconf-tea" set HOME=C:\Users\appveyor
  - if "%TOOLCHAIN%" == "autoconf-tea" bash -lc "cd && echo \"export PATH=/c/msys64/mingw64/bin:/c/msys64/usr/bin:\$PATH; export MSYSTEM=MINGW64; export MINGW_PREFIX=/c/msys64/mingw64; \" >> .profile"
  - if "%TOOLCHAIN%" == "nmake-tea" call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"
  - tclkit.exe apps/build.tcl %CD% %APPVEYOR_BUILD_FOLDER% %TCLTAG% %TOOLCHAIN%

on_failure:
  - if "%TOOLCHAIN%" == "autoconf-tea" cat tcl\win\config.log

after_build:
- ps: $env:DATESTRING=(get-date -UFormat "%Y%m%d").ToString()
- set TARBALL="nsf_%APPVEYOR_REPO_BRANCH%_%TCLTAG%_win_%TOOLCHAIN%_%DATESTRING%_%APPVEYOR_BUILD_NUMBER%.zip"
- if exist "%CD%\install" 7z a %TARBALL% %CD%\install\* 
- if exist "%TARBALL%" scp -v -oStrictHostKeyChecking=no -i deploy_key %TARBALL% "sobernig@alice.wu.ac.at:/home/sobernig/builds"

cache:
  - tclkit.exe -> appveyor.yml