# AppVeyor build configuration
#
# doc: http://www.appveyor.com/docs/build-configuration
# Qt-versions: https://www.appveyor.com/docs/windows-images-software/#qt
# validator: https://ci.appveyor.com/tools/validate-yaml

skip_tags: true

branches:
  only:
    - release

environment:
  global:
    qtdir57: C:\Qt\5.7\mingw53_32
    qtdirlatest: C:\Qt\latest\mingw73_32
    CCACHE_DIR: "%APPVEYOR_BUILD_FOLDER%\\.ccache"

  matrix:
    # latest Qt 32 bit
    #    - QTDIR: C:\Qt\5.13\mingw73_32
    #      TOOLCHAIN_VERSION: 730_32
    #      gpp: win32-g++
    # latest Qt 64 bit (broken)
    #    - QTDIR: C:\Qt\latest\mingw73_64
    #      TOOLCHAIN_VERSION: 730_64
    #      gpp: g++
    # Qt 5.7 (for Windows XP)
    - QTDIR: C:\Qt\5.7\mingw53_32
      TOOLCHAIN_VERSION: 530_32
      gpp: win32-g++

#matrix:
#  allow_failures:
#    - QTDIR: C:\Qt\latest\mingw73_64
#      TOOLCHAIN_VERSION: 730_64
#      gpp: g++

cache:
  - .ccache

install:
  # Qt-versions: https://www.appveyor.com/docs/build-environment/#qt
  #  - set QTDIR=C:\Qt\5.7\mingw53_32
  #  - set QTDIR=C:\Qt\5.10.1\mingw53_32
  - set PATH=%PATH%;%QTDIR%\bin;C:\Qt\Tools\QtCreator\bin;C:\Qt\Tools\mingw%TOOLCHAIN_VERSION%\bin
  - echo PATH=%PATH%
  - set RELEASE_PATH=appveyor\release
  - set TEST_PATH=appveyor\test
  # enable this to use RDP connection, see https://www.appveyor.com/docs/how-to/rdp-to-build-worker/
#  - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/release/scripts/enable-rdp.ps1'))

#  - C:\msys64\usr\bin\pacman --verbose --noconfirm --sync ccache
#  - ccache.exe -V
#  - dir %CCACHE_DIR%

before_build:
  # getting submodules
  - git submodule update --init
  #
  # do tests
  #
  - cd tests
  # we need to modify that to make it running on AppVeyor
  #- sed -i "s/CONFIG += c++11/QMAKE_CXXFLAGS += -std=gnu++0x\nQMAKE_CXX=ccache %gpp%/g" QOwnNotesTests.pro
  - sed -i "s/CONFIG += c++11/QMAKE_CXXFLAGS += -std=gnu++0x/g" QOwnNotesTests.pro
  - 'echo #define RELEASE "AppVeyor" > release.h'
  - qmake QOwnNotesTests.pro DEFINES+=INTEGRATION_TESTS CONFIG+=ccache
  - mingw32-make
  # creating the test path
  - md ..\%TEST_PATH%
  # copy the binary to our release path
  - copy ..\bin\tests\tests.exe ..\%TEST_PATH%
  # copy OpenSSL DLLs to the release path
  - copy ..\appveyor\OpenSSL\libcrypto-1_1.dll ..\%TEST_PATH%
  - copy ..\appveyor\OpenSSL\libssl-1_1.dll ..\%TEST_PATH%
  - cd ..\%TEST_PATH%
  # fetching dependencies of QT app
  # http://doc.qt.io/qt-5/windows-deployment.html
  - windeployqt tests.exe
  # this dll was missed by windeployqt
  - copy ..\libwinpthread-1.dll . /y
  # this dll didn't work when released by windeployqt
  # important: this dll needs to be updated when a new version of Qt is used!
  # search for it in the mingw* folder of your local installation of Qt
  - copy "..\libstdc++-6.dll" . /y
  - tests.exe -txt
  - cd ..\..

build_script:
  # enable this to take a look if there are new qt versions
  - dir C:\Qt
  - dir C:\Qt\latest
  - dir %QTDIR%\bin
  - dir C:\Qt\Tools\mingw%TOOLCHAIN_VERSION%\bin
  - dir C:\MinGW\bin
  - cd src
  # we need to modify that to make it running on AppVeyor
  #- sed -i "s/CONFIG += c++11/QMAKE_CXXFLAGS += -std=gnu++0x\nQMAKE_CXX=ccache %gpp%/g" QOwnNotes.pro
  - sed -i "s/CONFIG += c++11/QMAKE_CXXFLAGS += -std=gnu++0x/g" QOwnNotes.pro
  - 'echo #define RELEASE "AppVeyor" > release.h'
  # setting the build number in the header file
  - "echo #define BUILD %APPVEYOR_BUILD_NUMBER% > build_number.h"
  #  - qmake QOwnNotes.pro -r -spec win32-g++
  #  - qmake QOwnNotes.pro -r -spec %gpp% CONFIG+=ccache QMAKE_CXX="ccache $$QMAKE_CXX"
  - qmake QOwnNotes.pro -r -spec %gpp% CONFIG+=ccache
  #  - qmake QOwnNotes.pro -r -spec win32-g++ "CONFIG+=debug"
  - lrelease QOwnNotes.pro
  - mingw32-make
  # creating the release path
  - md ..\%RELEASE_PATH%
  # copy the binary to our release path
  - copy release\QOwnNotes.exe ..\%RELEASE_PATH%
  # copy OpenSSL DLLs to the release path
  - copy ..\appveyor\OpenSSL\libcrypto-1_1.dll ..\%RELEASE_PATH%
  - copy ..\appveyor\OpenSSL\libssl-1_1.dll ..\%RELEASE_PATH%
  # copy unzip application for updater
  - copy ..\appveyor\unzip.exe ..\%RELEASE_PATH%
  # copy updater script
  - copy ..\appveyor\update.bat ..\%RELEASE_PATH%
  # copy portable mode launcher to the release path
  - copy ..\appveyor\QOwnNotesPortable.bat ..\%RELEASE_PATH%
  # copy translation files
  - copy languages\*.qm ..\%RELEASE_PATH%
  - cd ..\%RELEASE_PATH%
  # fetching dependencies of QT app
  # http://doc.qt.io/qt-5/windows-deployment.html
  - windeployqt --release QOwnNotes.exe
  # this dll was missed by windeployqt
  - copy ..\libwinpthread-1.dll . /y
  # this dll didn't work when released by windeployqt
  # important: this dll needs to be updated when a new version of Qt is used!
  # search for it in the mingw* folder of your local installation of Qt
  - copy "..\libstdc++-6.dll" . /y
  # for some reason AppVeyor or windeployqt uses a copy of the German
  # translation file as English one, which screws up the English user interface
  - del "translations\qt_en.qm"

artifacts:
  # pushing entire folder as a zip archive
  - path: appveyor\release
    name: QOwnNotes

#deploy:
#  # Deploy to GitHub Releases
#  - provider: GitHub
#    artifact: QOwnNotes
#    draft: false
#    prerelease: false
#    auth_token:
#      secure: spcyN/Dz3B2GXBPii8IywDLq6vfxC1SrN+xR2wMerFM7g2nTy0Lrh5agQONFoInR#
#    on:
#      branch: release
#      QTDIR: C:\Qt\5.13\mingw73_32

notifications:
  # Gitter webhook
  - provider: Webhook
    url: https://webhooks.gitter.im/e/b6ef22402eb4af50f73a
    on_build_success: true
    on_build_failure: true
    on_build_status_changed: false
