# appveyor.yml     AppVeyor CI configuration file for MindForger
#
# Copyright (C) 2016-2020
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

version: 1.52.{build}

skip_commits:
  files:
    - '**/*.md'

environment:
   APPVEYOR_SAVE_CACHE_ON_ERROR: true

image: Visual Studio 2017

#---------------------------------#
#       build configuration       #
#---------------------------------#

# build platform, i.e. x86, x64, Any CPU. This setting is optional.
platform: x64

# build Configuration, i.e. Debug, Release, etc.
configuration: Release

cache: 
 - c:\cache
 - C:\Program Files\googletest-distribution 

# check https://www.appveyor.com/docs/windows-images-software for updates
install:
 - set QT_DIR=C:\Qt\5.9.9\msvc2017_64
# - set QT_DIR=C:\Qt\5.9.7\msvc2017_64
 - set PATH=%PATH%;%QT_DIR%\bin
 - set M8R_HOME=%APPVEYOR_BUILD_FOLDER%
 - if not exist c:\cache mkdir c:\cache
# on the image vcredist is in C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Redist\MSVC\14.16.27012 
 - if not exist c:\cache\vcredist_x64.exe  curl -LfSs -o c:\cache\vcredist_x64.exe https://aka.ms/vs/15/release/vc_redist.x64.exe
 - if not exist "C:\Program Files\googletest-distribution" pushd %TEMP% && curl -LfSs -o gtest.zip https://github.com/google/googletest/archive/release-1.8.1.zip && 7z x gtest.zip && cd googletest-release-1.8.1 && mkdir build && cd build && cmake -G "Visual Studio 15 2017 Win64" -DCMAKE_CONFIGURATION_TYPES=Debug;Release -Dgtest_build_samples=OFF -Dgtest_build_tests=OFF -Dgmock_build_tests=OFF -Dgtest_force_shared_crt=ON .. && cmake --build . --config Debug -- /m &&  cmake -DBUILD_TYPE=Debug -P cmake_install.cmake && popd 

before_build:
 - cd "%M8R_HOME%"
 - git submodule init
 - git submodule update

build_script:
 - pushd "%M8R_HOME%\deps\cmark-gfm" && mkdir build && cd build && cmake -G "Visual Studio 15 2017 Win64" -DCMAKE_CONFIGURATION_TYPES=Debug;Release -DCMARK_TESTS=OFF -DCMARK_SHARED=OFF .. && cmake --build . --config Release -- /m && cmake --build . --config Debug -- /m && popd
 - call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"
 - cd "%M8R_HOME%" && qmake -r mindforger.pro && nmake
 - windeployqt app\release\mindforger.exe  --dir app\release\bin --no-compiler-runtime && "C:\Program Files (x86)\Inno Setup 5\iscc.exe" /Q /DVcRedistPath=c:\cache\vcredist_x64.exe build\windows\installer\mindforger-setup.iss
# - if "%APPVEYOR_REPO_BRANCH%" equ "master" appveyor PushArtifact app\release\installer\mindforger-setup.exe
 - appveyor PushArtifact app\release\installer\mindforger-setup.exe

before_test:
 - pushd "%M8R_HOME%\lib\test" && qmake -r mindforger-lib-unit-tests.pro "CONFIG+=debug" "CONFIG+=mfdebug" "CONFIG+=mfunit" && nmake && popd
 - if not exist c:\tmp mkdir c:\tmp

test_script:
 - ps: |
     $env:M8R_GIT_PATH=$env:M8R_HOME
     $env:PATH+=";$env:M8R_HOME\deps\zlib-win\lib"
     cd $env:M8R_HOME
     & lib\test\src\debug\mindforger-lib-unit-tests.exe --gtest_output=xml:tests.xml >mindforger-unit-tests.log 2>&1
     $TestExitCode=$LastExitCode
     Get-Content mindforger-unit-tests.log -Tail 20
     (new-object net.webclient).UploadFile("https://ci.appveyor.com/api/testresults/junit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path .\tests.xml))
     Write-Output "Test exit code: $TestExitCode"
     if ($TestExitCode -ne 0) {
       Push-AppveyorArtifact mindforger-unit-tests.log -Type zip
       throw "Exec: tests failed" 
     }

on_finish:
# also set APPVEYOR_RDP_PASSWORD environment variable for password before uncommenting
# - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
