branches:
  only:
    - /.*/

image:
  - Visual Studio 2017

platform:
  - x64
  - x86

configuration:
  - Release

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

install:
  # Capture environment:
  - cmd: set RIVET_HOME=%cd%
  - cmd: set /p RIVET_VERSION=<VERSION
  - cmd: echo %RIVET_VERSION%
  # Install Tcl/Tk
  - cmd: if %platform%==x86 set DOWNLOAD_PLATFORM=win32
  - cmd: if %platform%==x64 set DOWNLOAD_PLATFORM=amd64
  - cmd: if %platform%==x86 set APACHE_DOWNLOAD_PLATFORM=win32
  - cmd: if %platform%==x64 set APACHE_DOWNLOAD_PLATFORM=win64
  - cmd: if %platform%==x86 set CMAKE_GENERATOR="Visual Studio 15"
  - cmd: if %platform%==x64 set CMAKE_GENERATOR="Visual Studio 15 Win64"
  - cmd: set IRONTCL_VERSION="8.6.7"
  - 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=%TCL_ROOT%\bin;%PATH%
  - cmd: set TCL_TCLSH=%cd%\IronTcl\bin\tclsh86t.exe
  - cmd: set TK_WISH=%cd%\IronTcl\bin\wish86t.exe
  # Install Apache
  - cmd: set APACHE_VERSION="2.4.58"
  - cmd: set APACHE_COMPILER="VS17"
  - cmd: appveyor DownloadFile https://www.apachelounge.com/download/%APACHE_COMPILER%/binaries/httpd-%APACHE_VERSION%-%APACHE_DOWNLOAD_PLATFORM%-%APACHE_COMPILER%.zip
  - cmd: cmake -E tar xf httpd-%APACHE_VERSION%-%APACHE_DOWNLOAD_PLATFORM%-%APACHE_COMPILER%.zip
  - cmd: set APACHE_ROOT=%cd%\Apache24
  # Generate solution...
  - cmd: cd cmake
  - cmd: cmake -E make_directory "build"
  - cmd: cmake -E chdir build cmake -DAPACHE_ROOT=%APACHE_ROOT% -DTCL_ROOT=%TCL_ROOT% -DTCL_TCLSH=%TCL_TCLSH% -DTK_WISH=%TK_WISH% -G %CMAKE_GENERATOR% ..

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

before_build:
  - cmd: if %platform%==x86 set RIVET_PLATFORM=Win32
  - cmd: if %platform%==x64 set RIVET_PLATFORM=x64

build_script:
  - cmd: echo %cd%
  - cmd: cd build
  - cmd: msbuild Rivet.sln /p:Platform=%RIVET_PLATFORM% /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
  - cmd: msbuild INSTALL.vcxproj /p:Platform=%RIVET_PLATFORM% /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"

after_build:
  - cmd: set ARTIFACT_DIR=%RIVET_HOME%\artifacts\rivet-%RIVET_VERSION%-windows-%platform%
  - cmd: echo %cd%
  - cmd: mkdir %ARTIFACT_DIR%\modules
  # Copy the installed files into a new directory, so we can zip it...
  - cmd: copy /y /b %APACHE_ROOT%\modules\mod_rivet.so %ARTIFACT_DIR%\modules
  - cmd: xcopy %APACHE_ROOT%\bin\rivet%RIVET_VERSION% %ARTIFACT_DIR%\rivet%RIVET_VERSION% /s /e /y /i
  - cmd: cd %RIVET_HOME%\artifacts && dir
  - cmd: cd %ARTIFACT_DIR% && dir
  - cmd: cd %RIVET_HOME%\artifacts && 7z a -tzip rivet-%RIVET_VERSION%-windows-%platform%.zip *

artifacts:
  - path: '\artifacts\*.zip'
    type: zip
    name: rivet-%RIVET_VERSION%-windows-%platform%.zip

deploy:
  provider: GitHub
  # The following token belongs to the user "petasis":
  auth_token:
    secure: "u2sUa4ovDQsL08AQjtmcIIVmHw6pFqIsT8JSBkMA2Ciebku0slhbTCGDZ19sp0Xt"
  tag: $(APPVEYOR_REPO_TAG_NAME)
  release: $(APPVEYOR_REPO_TAG_NAME)
  description: 'Apache Rivet binaries'
  artifact: rivet-%RIVET_VERSION%-windows-%platform%.zip
  draft: true
  prerelease: true
  on:
    branch: master                 # release from master branch only
    appveyor_repo_tag: true        # deploy on tag push only

## How to trigger a release:
#  Add a new tag:
#    git tag rivet-release-test-v3.2.0-1
#    git push origin --tags
#
#  If you want to remove the tag:
#    git push --delete origin tagName ;# tagName: rivet-release-test-v3.2.0-1
#    git tag -d tagName
