# Notes:
#   - Minimal appveyor.yml file is an empty file. All sections are optional.
#   - Indent each level of configuration with 2 spaces. Do not use tabs!
#   - All section names are case-sensitive.
#   - Section names should be unique on each level.
# from example:
# https://github.com/Phonations/Joker/blob/master/appveyor.yml
# https://github.com/unicorn-engine/autobuild/blob/master/.appveyor.yml
      
#---------------------------------#
#      general configuration      #
#---------------------------------#

# version format
version: RetroShare-git-{branch}-{build}

# you can use {branch} name in version format too
# version: 1.0.{build}-{branch}

# branches to build
branches:
  # whitelist
  #only:
  #  - master

  # blacklist
  except:
    - /^skipthisbranch$/

# Do not build on tags (GitHub only)
skip_tags: true

# Skipping commits with particular message or from user
skip_commits:
  message: /Created.*\.(png|jpg|jpeg|bmp|gif)/       # Regex for matching commit message
  #author: Anonymous        # Commit author's username, name, email or regexp maching one of these.

#---------------------------------#
#    environment configuration    #
#---------------------------------#

# Operating system (build VM template)
#os: Windows Server 2012

# scripts that are called at very beginning, before repo cloning
init:
  - git config --global core.autocrlf input
  #To get RDP while compiling
  - ps: iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
on_finish:
  #To get RDP running after compiling
  #- ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))

# clone directory
clone_folder: C:\projects\RetroShare

# fetch repository as zip archive
#shallow_clone: true                 # default is "false"

# set clone depth
clone_depth: 2000                    # clone entire repository history if not defined

environment:
  global:
## Qt: https://www.appveyor.com/docs/installed-software#qt
#    QTDIR: C:\Qt\5.10.1\mingw53_32
    MSYS2_ARCH: i686
    TARGET: i686_32-pc-msys
    MINGW_PREFIX: C:\msys64\mingw32
    RS_DEPLOY: RetroShare_deploy


# build cache to preserve files/folders between builds
#cache:
# Disabled because it's bigger then supported by appveyor free plan
#  - C:\msys64\var\cache\pacman\pkg

# scripts that run after cloning repository
#install:
#  # by default, all script lines are interpreted as batch
#  - echo This is batch
#  # to run script as a PowerShell command prepend it with ps:
#  - ps: Write-Host 'This is PowerShell'
#  # batch commands start from cmd:
#  - cmd: echo This is batch again
#  - cmd: set MY_VAR=12345
install:
  - git submodule update --init
  # Configuring MSys2
  - set PATH=C:\msys64\usr\bin;%PATH%
  - set PATH=C:\msys64\mingw32\bin;%PATH%
  - pacman --noconfirm -S mingw-w64-i686-qt5 mingw-w64-i686-miniupnpc mingw-w64-i686-sqlcipher mingw-w64-i686-libmicrohttpd mingw-w64-i686-xapian-core
  #- pacman --noconfirm -S mingw-w64-i686-qt5-static mingw-w64-i686-miniupnpc mingw-w64-i686-sqlcipher mingw-w64-i686-libmicrohttpd
  #- set PATH=C:\msys64\mingw32\qt5-static\bin\;%PATH%

  # Configuring Qt
#  - set PATH=%QTDIR%\bin;C:\Qt\Tools\mingw491_32\bin;%PATH%

  # Hack for new MSys2
  - copy C:\msys64\mingw32\i686-w64-mingw32\bin\ar.exe C:\msys64\mingw32\bin\i686-w64-mingw32-ar.exe
  - copy C:\msys64\mingw32\i686-w64-mingw32\bin\ranlib.exe C:\msys64\mingw32\bin\i686-w64-mingw32-ranlib.exe
  - copy C:\msys64\mingw32\bin\windres.exe C:\msys64\mingw32\bin\i686-w64-mingw32-windres.exe
  - copy C:\msys64\mingw64\x86_64-w64-mingw32\bin\ar.exe C:\msys64\mingw64\bin\x86_64-w64-mingw32-ar.exe
  - copy C:\msys64\mingw64\x86_64-w64-mingw32\bin\ranlib.exe C:\msys64\mingw64\bin\x86_64-w64-mingw32-ranlib.exe
  - copy C:\msys64\mingw64\bin\windres.exe C:\msys64\mingw64\bin\x86_64-w64-mingw32-windres.exe


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

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

# to add several platforms to build matrix:
#platform:
#  - x86
#  - Any CPU

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

# to add several configurations to build matrix:
#configuration:
#  - Debug
#  - Release

# scripts to run before build
before_build:
  - cd C:\projects\RetroShare
#  - find C:\ > filelist.txt

# scripts to run *after* solution is built and *before* automatic packaging occurs (web apps, NuGet packages, Azure Cloud Services)
before_package:

# to run your custom scripts instead of automatic MSBuild
build_script:
  - qmake -Wall -spec win32-g++ "CONFIG=debug"
  - mingw32-make -j3

# scripts to run after build
after_build:
  - mkdir %RS_DEPLOY%
  - copy retroshare-nogui\src\retroshare-nogui.exe %RS_DEPLOY%\
  - copy retroshare-gui\src\retroshare.exe %RS_DEPLOY%\

## In Debug build winedeplyqt forget the non debug Qt libs
  - copy C:\msys64\mingw32\bin\Qt5Svg.dll %RS_DEPLOY%\
  - copy C:\msys64\mingw32\bin\Qt5Core.dll %RS_DEPLOY%\
  - copy C:\msys64\mingw32\bin\Qt5Multimedia.dll %RS_DEPLOY%\
  - copy C:\msys64\mingw32\bin\Qt5Widgets.dll %RS_DEPLOY%\
  - copy C:\msys64\mingw32\bin\Qt5Xml.dll %RS_DEPLOY%\
  - copy C:\msys64\mingw32\bin\Qt5PrintSupport.dll %RS_DEPLOY%\
  - copy C:\msys64\mingw32\bin\Qt5Gui.dll %RS_DEPLOY%\
  - copy C:\msys64\mingw32\bin\Qt5Network.dll %RS_DEPLOY%\

  - mkdir %RS_DEPLOY%\playlistformats\
  - copy C:\msys64\mingw32\share\qt5\plugins\playlistformats\qtmultimedia_m3u.dll %RS_DEPLOY%\playlistformats

  - mkdir %RS_DEPLOY%\printsupport\
  - copy C:\msys64\mingw32\share\qt5\plugins\printsupport\windowsprintersupport.dll %RS_DEPLOY%\printsupport\

  - mkdir %RS_DEPLOY%\iconengines\
  - copy C:\msys64\mingw32\share\qt5\plugins\iconengines\qsvgicon.dll %RS_DEPLOY%\iconengines\

  - mkdir %RS_DEPLOY%\bearer\
  - copy C:\msys64\mingw32\share\qt5\plugins\bearer\qgenericbearer.dll %RS_DEPLOY%\bearer\

  - mkdir %RS_DEPLOY%\mediaservice\
  - copy C:\msys64\mingw32\share\qt5\plugins\mediaservice\qtmedia_audioengine.dll %RS_DEPLOY%\mediaservice\
  - copy C:\msys64\mingw32\share\qt5\plugins\mediaservice\dsengine.dll %RS_DEPLOY%\mediaservice\

  - mkdir %RS_DEPLOY%\styles\
  - copy C:\msys64\mingw32\share\qt5\plugins\styles\qwindowsvistastyle.dll %RS_DEPLOY%\styles\

  - mkdir %RS_DEPLOY%\imageformats\
  - copy C:\msys64\mingw32\share\qt5\plugins\imageformats\qwebp.dll %RS_DEPLOY%\imageformats\
  - copy C:\msys64\mingw32\share\qt5\plugins\imageformats\qicns.dll %RS_DEPLOY%\imageformats\
  - copy C:\msys64\mingw32\share\qt5\plugins\imageformats\qjpeg.dll %RS_DEPLOY%\imageformats\
  - copy C:\msys64\mingw32\share\qt5\plugins\imageformats\qtiff.dll %RS_DEPLOY%\imageformats\
  - copy C:\msys64\mingw32\share\qt5\plugins\imageformats\qtga.dll %RS_DEPLOY%\imageformats\
  - copy C:\msys64\mingw32\share\qt5\plugins\imageformats\qjp2.dll %RS_DEPLOY%\imageformats\
  - copy C:\msys64\mingw32\share\qt5\plugins\imageformats\qico.dll %RS_DEPLOY%\imageformats\
  - copy C:\msys64\mingw32\share\qt5\plugins\imageformats\qwbmp.dll %RS_DEPLOY%\imageformats\
  - copy C:\msys64\mingw32\share\qt5\plugins\imageformats\qicns.dll %RS_DEPLOY%\imageformats\
  - copy C:\msys64\mingw32\share\qt5\plugins\imageformats\qgif.dll %RS_DEPLOY%\imageformats\
  - copy C:\msys64\mingw32\share\qt5\plugins\imageformats\qsvg.dll %RS_DEPLOY%\imageformats\

  - mkdir %RS_DEPLOY%\platforms\
  - copy C:\msys64\mingw32\share\qt5\plugins\platforms\qwindows.dll %RS_DEPLOY%\platforms\

  - mkdir %RS_DEPLOY%\audio\
  - copy C:\msys64\mingw32\share\qt5\plugins\audio\qtaudio_windows.dll %RS_DEPLOY%\audio\

  - windeployqt %RS_DEPLOY%\retroshare.exe

  - copy C:\msys64\mingw32\bin\libbz2*.dll %RS_DEPLOY%\
  - copy C:\msys64\mingw32\bin\libeay32.dll %RS_DEPLOY%\
  - copy C:\msys64\mingw32\bin\libminiupnpc.dll %RS_DEPLOY%\
  - copy C:\msys64\mingw32\bin\libsqlcipher*.dll %RS_DEPLOY%\
  - copy C:\msys64\mingw32\bin\libsqlite3*.dll %RS_DEPLOY%\
  - copy C:\msys64\mingw32\bin\ssleay32.dll %RS_DEPLOY%\
  - copy C:\msys64\mingw32\bin\zlib*.dll %RS_DEPLOY%\
  - copy C:\msys64\mingw32\bin\libgcc_s_dw2*.dll %RS_DEPLOY%\
  - copy C:\msys64\mingw32\bin\libstdc*.dll %RS_DEPLOY%\
  - copy C:\msys64\mingw32\bin\libwinpthread*.dll %RS_DEPLOY%\
  - copy C:\msys64\mingw32\bin\libicu*.dll %RS_DEPLOY%\
  - copy C:\msys64\mingw32\bin\libpcre*.dll %RS_DEPLOY%\
  - copy C:\msys64\mingw32\bin\libharfbuzz*.dll %RS_DEPLOY%\
  - copy C:\msys64\mingw32\bin\libpng*.dll %RS_DEPLOY%\
  - copy C:\msys64\mingw32\bin\libfreetype*.dll %RS_DEPLOY%\
  - copy C:\msys64\mingw32\bin\libglib*.dll %RS_DEPLOY%\
  - copy C:\msys64\mingw32\bin\libgraphite2.dll %RS_DEPLOY%\
  - copy C:\msys64\mingw32\bin\libintl*.dll %RS_DEPLOY%\
  - copy C:\msys64\mingw32\bin\libiconv*.dll %RS_DEPLOY%\
  - copy C:\msys64\mingw32\bin\libjasper*.dll %RS_DEPLOY%\
  - copy C:\msys64\mingw32\bin\libjpeg*.dll %RS_DEPLOY%\
  - copy C:\msys64\mingw32\bin\libtiff*.dll %RS_DEPLOY%\
  - copy C:\msys64\mingw32\bin\libwebp*.dll %RS_DEPLOY%\
  - copy C:\msys64\mingw32\bin\libwebpdemux*.dll %RS_DEPLOY%\
  - copy C:\msys64\mingw32\bin\liblzma*.dll %RS_DEPLOY%\

## Needed for libresapi http
  - copy C:\msys64\mingw32\bin\libmicrohttpd*.dll %RS_DEPLOY%\
  - copy C:\msys64\mingw32\bin\libgnutls*.dll %RS_DEPLOY%\
  - copy C:\msys64\mingw32\bin\libgmp*.dll %RS_DEPLOY%\
  - copy C:\msys64\mingw32\bin\libhogweed*.dll %RS_DEPLOY%\
  - copy C:\msys64\mingw32\bin\libidn2*.dll %RS_DEPLOY%\
  - copy C:\msys64\mingw32\bin\libnettle*.dll %RS_DEPLOY%\
  - copy C:\msys64\mingw32\bin\libp11-kit*.dll %RS_DEPLOY%\
  - copy C:\msys64\mingw32\bin\libtasn1*.dll %RS_DEPLOY%\
  - copy C:\msys64\mingw32\bin\libunistring*.dll %RS_DEPLOY%\
  - copy C:\msys64\mingw32\bin\libffi*.dll %RS_DEPLOY%\

  - find C:\projects\RetroShare >> filelist.txt

# to disable automatic builds
#build: off

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

artifacts:
  - path: $(RS_DEPLOY)
  - path: '**\*.exe'
  - path: filelist.txt
#
#  # pushing a single file
#  - path: test.zip
#
#  # pushing a single file with environment variable in path and "Deployment name" specified
#  - path: MyProject\bin\$(configuration)
#    name: myapp
#
#  # pushing entire folder as a zip archive
#  - path: logs


#---------------------------------#
#     deployment configuration    #
#---------------------------------#
#No deployment under unknown  computer!!!

#---------------------------------#
#        global handlers          #
#---------------------------------#

# on successful build
#on_success:
#  - do something

# on build failure
#on_failure:
#  - do something

# after build failure or success
#on_finish:
#  - do something

  
#---------------------------------#
#         notifications           #
#---------------------------------#
  
notifications:

  # Email
  - provider: Email
    to:
      - retrosharephenom@gmail.com
    subject: 'Build {{status}}'                  # optional
    message: "{{message}}, {{commitId}}, ..."    # optional
    on_build_status_changed: true
