# version format
version: 2.9.{build}

branches:
  only:
    - master

image:
  - Visual Studio 2017

platform:
  - x86
  - x64

configuration:
  - Release

matrix:
  fast_finish: true
  allow_failures:
    - platform: x86
      configuration: Release

install:
  - cmd: set TKDND_HOME=%cd%
  - cmd: set /p TKDND_VERSION=<VERSION
  - cmd: echo %TKDND_VERSION%
  # Install Tcl/Tk
  - cmd: set IRONTCL_VERSION="8.6.7"
  - cmd: if %platform%==x86 set DOWNLOAD_PLATFORM=win32
  - cmd: if %platform%==x64 set DOWNLOAD_PLATFORM=amd64
  - cmd: if %platform%==x86 set CMAKE_GENERATOR="Visual Studio 15"
  - cmd: if %platform%==x64 set CMAKE_GENERATOR="Visual Studio 15 Win64"
  - cmd: appveyor DownloadFile https://www.irontcl.com/downloads/irontcl-%DOWNLOAD_PLATFORM%-%IRONTCL_VERSION%.zip
  - cmd: cmake -E tar xf irontcl-%DOWNLOAD_PLATFORM%-%IRONTCL_VERSION%.zip
  - cmd: set TCL_ROOT=%cd%\IronTcl
  - cmd: set PATH=%cd%\IronTcl\bin;%PATH%
  - cmd: set TCL_TCLSH=%cd%\IronTcl\bin\tclsh86t.exe
  - cmd: set TK_WISH=%cd%\IronTcl\bin\wish86t.exe
  # Generate solution...
  - cmd: cmake -E make_directory "build"
  - cmd: cd build && cmake -G %CMAKE_GENERATOR% -DTCL_TCLSH=%TCL_TCLSH% -DTK_WISH=%TK_WISH% -DCMAKE_INSTALL_PREFIX=runtime ..

build:
  project: build\tkdnd.sln      # path to Visual Studio solution or project

before_build:
  - cmd: if %platform%==x86 set TKDND_PLATFORM=Win32
  - cmd: if %platform%==x86 set MSYS2_ARCH=i686
  - cmd: if %platform%==x86 set MSYSTEM=MINGW32
  - cmd: if %platform%==x64 set TKDND_PLATFORM=x64
  - cmd: if %platform%==x64 set MSYS2_ARCH=x86_64
  - cmd: if %platform%==x64 set MSYSTEM=MINGW64

build_script:
  - cmd: msbuild tkdnd.sln /p:Platform=%TKDND_PLATFORM% /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
  - cmd: msbuild INSTALL.vcxproj /p:Platform=%TKDND_PLATFORM% /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
  ## MSYS2
  - PATH C:\msys64\%MSYSTEM%\bin;C:\msys64\usr\bin;C:\msys64\bin;%PATH%
  - cd %TKDND_HOME%
  - bash '%APPVEYOR_BUILD_FOLDER%\appveyor_build_msys2.sh'
  - cd %TKDND_HOME%\build

after_build:
  - cmd: echo %cd%
  - cmd: cd runtime && 7z a -tzip tkdnd-%TKDND_VERSION%-windows-%platform%.zip *

artifacts:
  - path: '\build\runtime\*.zip'
    type: zip
    name: tkdnd-%TKDND_VERSION%-windows-%platform%.zip

# https://github.com/forexample/github-binary-release
# git tag tkdnd-release-test-v2.9.2
# git push --tags
#
# Delete tag:
# git push --delete origin tkdnd-release-test-v2.9.1
# git tag -d tkdnd-release-test-v2.9.1
deploy:
  provider: GitHub
  auth_token:
    secure: "u2sUa4ovDQsL08AQjtmcIIVmHw6pFqIsT8JSBkMA2Ciebku0slhbTCGDZ19sp0Xt"
  tag: $(APPVEYOR_REPO_TAG_NAME)
  # release: $(APPVEYOR_REPO_TAG_NAME)-%platform%-v$(appveyor_build_version)
  # release: $(APPVEYOR_REPO_TAG_NAME)-windows-v$(appveyor_build_version)
  release: $(APPVEYOR_REPO_TAG_NAME)
  description: 'TkDND binaries'
  artifact: tkdnd-%TKDND_VERSION%-windows-%platform%.zip
  draft: false
  prerelease: false
  on:
    branch: master                 # release from master branch only
    appveyor_repo_tag: true        # deploy on tag push only
