# appveyor file
# http://www.appveyor.com/docs/appveyor-yml

# Set build version format here instead of in the admin panel.
version: 3.0.0.{build}

# http://www.appveyor.com/docs/build-cache#caching-chocolatey-packages
# https://github.com/kvirc/KVIrc/blob/master/.appveyor.yml
cache:
  - C:\ProgramData\chocolatey\bin -> appveyor.yml
  - C:\ProgramData\chocolatey\lib -> appveyor.yml
  - 'C:\Program Files (x86)\NSIS'

## http://www.appveyor.com/docs/installed-software#python
## Python 2.7; 32-bit version
#    - python: C:\Python27;C:\Python27\Scripts
## Python 2.7; 64-bit version
#    - python: C:\Python27-x64;C:\Python27-x64\Scripts
## Python 3.4; 32-bit version
#    - python: C:\Python34;C:\Python34\Scripts
## Python 3.4; 64-bit version
#    - python: C:\Python34-x64;C:\Python34-x64\Scripts

environment:
  matrix:
  - VS_GEN: Visual Studio 12 2013
    CONFIG: Release
    B_NAME: Windows-x86
    DO_REL: true
    PYTHONHOME: C:\Python37
    JAVA_HOME: C:\Program Files (x86)\Java\jdk1.8.0
  - VS_GEN: Visual Studio 12 2013 Win64
    CONFIG: Release
    B_NAME: Windows-x86_64
    DO_REL: true
    PYTHONHOME: C:\Python37-x64
    JAVA_HOME: C:\Program Files\Java\jdk1.8.0
#  - VS_GEN: Visual Studio 14 2015 Win64
#    CONFIG: Release
#    B_NAME: Win64
#  - VS_GEN: MinGW Makefiles
#    CONFIG: None
#    B_NAME: MinGW
#  - VS_GEN: MSYS Makefiles
#    CONFIG: None
#    B_NAME: Msys
#  - VS_GEN: Visual Studio 14 2015 ARM
#    CONFIG: Debug
#    B_NAME: ARM

matrix:
  fast_finish: true

# Operating system (build VM template)
os: Visual Studio 2015
branches:
  except:
  - coverity_scan

#You can disable builds on new tags through UI (General tab of project settings) or in appveyor.yml:
#skip_tags: true

# scripts that are called at very beginning, before repo cloning
init:
  # Print environment info ( set / systeminfo)
  - set PATH=%JAVA_HOME%\bin;%PYTHONHOME%;%PATH%
  - msbuild /version
  - cmake --version
  - python --version
  - java -version
  # https://github.com/chocolatey/chocolatey/issues/431
  - del c:\programdata\chocolatey\bin\cpack.exe

# scripts that run after cloning repository
# https://www.appveyor.com/docs/build-configuration#powershell
install:
  # Fetch submodules
  #- git submodule update --init --recursive
  # PowerShell
  #- ps: (New-Object Net.WebClient).DownloadFile('http://download.microsoft.com/download/f/2/6/f263ac46-1fe9-4ae9-8fd3-21102100ebf5/msxsl.exe', "$env:appveyor_build_folder\msxsl.exe")
  #- msxsl -? --> code return is 1 !!
  # chocolatey:
  - ps: |
      if (Test-Path "C:/ProgramData/chocolatey/bin/swig.exe") {
          echo "using swig from cache"
      } else {
          choco install -y swig > $null
      }
  - swig -version
  # https://chocolatey.org/packages/nsis.install/
  - ps: |
      if (Test-Path "C:/Program Files (x86)/NSIS/makensis.exe") {
          echo "using nsis from cache"
      } else {
          choco install -y nsis.install -pre -version 2.46.0.20150406
      }
  - cmd: SET PATH=%PATH%;C:\Program Files (x86)\NSIS

on_failure:
  - ctest -D ExperimentalSubmit -C %CONFIG% -Q
  # Display error log file if generated
  - dir C:\projects\gdcm\bin
  - dir C:\projects\gdcm\bin\Release
  #- if exist C:\ProgramData\chocolatey\logs\chocolatey.log type C:\ProgramData\chocolatey\logs\chocolatey.log

# scripts to run before build
before_build:
  - cmake -Wno-dev -G"%VS_GEN%" -DCMAKE_BUILD_TYPE=%CONFIG% -DGDCM_BUILD_DOCBOOK_MANPAGES:BOOL=OFF -DGDCM_BUILD_TESTING:BOOL=ON -DGDCM_BUILD_APPLICATIONS:BOOL=ON -DGDCM_BUILD_EXAMPLES:BOOL=ON -DGDCM_BUILD_SHARED_LIBS:BOOL=ON -DBUILDNAME:STRING=%COMPUTERNAME%-%APPVEYOR_REPO_BRANCH%-%B_NAME% -DGDCM_WRAP_CSHARP:BOOL=ON -DGDCM_WRAP_JAVA:BOOL=ON -DGDCM_WRAP_PYTHON:BOOL=ON -DGDCM_USE_PVRG:BOOL=ON -DGDCM_LEGACY_SILENT:BOOL=ON -DCPACK_SYSTEM_NAME:STRING=%B_NAME% .
  - ctest -D ExperimentalStart -C %CONFIG%

# scripts to run after build
after_build:
  # create NSIS installer
  - cpack -G NSIS -C %CONFIG%
  # create NuGet installer
  - cpack -G NuGet -C %CONFIG%
  # create binary zip
  - cpack -G ZIP -C %CONFIG%
  # no need for source release on github

# to run your custom scripts instead of automatic MSBuild
build_script:
  # Do not run Test=Update/Configure, only Start/Build/Test/Submit (TODO: Coverage)
  - ctest -D ExperimentalBuild -j %NUMBER_OF_PROCESSORS% -C %CONFIG% -Q

# scripts to run after tests
after_test:

# to run your custom scripts instead of automatic tests
test_script:
  - ctest -D ExperimentalTest -j %NUMBER_OF_PROCESSORS% -C %CONFIG% -Q || true
  - ctest -D ExperimentalSubmit -C %CONFIG% -Q

#---------------------------------#
#      artifacts configuration    #
#---------------------------------#

artifacts:
  - path: GDCM-*-$(B_NAME).exe
    name: installer
  - path: GDCM-*-$(B_NAME).zip
    name: zip_executable
    type: zip
  - path: GDCM-*-$(B_NAME).nupkg
    name: nuget_package
    type: nugetpackage

#---------------------------------#
#     deployment configuration    #
#---------------------------------#

# scripts to run before deployment
#before_deploy:

# scripts to run after deployment
#after_deploy:

# to run your custom scripts instead of provider deployments
#deploy_script:

# Deploy to GitHub Releases http://www.appveyor.com/docs/deployment/github
# http://www.appveyor.com/docs/branches
# AppVeyor sets APPVEYOR_REPO_TAG environment variable to distinguish regular
# commits from tags - the value is True if tag was pushed; otherwise it's
# False.  When it's True the name of tag is stored in APPVEYOR_REPO_TAG_NAME.
deploy:
  - provider: NuGet
    api_key:
      secure: T6GXp3POj8sDGZWmZ5tkLgdbyLjllar/ZVLNn96SkrI3IDBq+L3GFMH13FEZs0uR
    skip_symbols: true
    artifact: nuget_package
  - provider: GitHub
    auth_token:
      secure: 7HmfZp9O7bVdQo2hRk6FjOUs7jJosftv2rZ6JPBNzjPcAOMXDTvLqv3lvzdAzBfy
    release: $(appveyor_repo_tag_name)
    description: 'Release of GDCM $(appveyor_repo_tag_name)'
    # github automatically does source zip/tarball for us
    artifact: installer,zip_executable
    draft: false
    prerelease: false
    on:
      branch: release               # release from release branch only
      appveyor_repo_tag: true       # deploy on tag push only
      do_rel: true
