#---------------------------------#
#      general configuration      #
#---------------------------------#

# version format
version: 0.6.4.{build}

# branches to build
branches:
  # whitelist
  only:
    - master
    # - /v\d*\.\d*\.\d*/

# Skipping commits with particular message or from specific user
skip_commits:
  message: /Created.*\.(png|jpg|jpeg|bmp|gif|md)/       # Regex for matching commit message
  files:
    - '*.md'
    - '*.txt'
    - 'LICENSE'
    - '.gitignore'

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

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

environment:
  APPVEYOR_YML_DISABLE_PS_LINUX: true
  matrix:
    # Windows 7 or later
    - APPVEYOR_JOB_NAME: for Windows (7 or later)
      APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
      COMPILER: C:\Qt\Tools\mingw810_32\bin
      QT: C:\Qt\5.15.2\mingw81_32\bin
      PLATFORM: windows
      DEST: BambooTracker-v%APPVEYOR_BUILD_VERSION%-dev-windows-7-32bit.zip
      MAKE: mingw32-make
      RELEASE_BUILD: false
    # Windows XP (Debug)
    # - APPVEYOR_JOB_NAME: for Windows XP
    #   APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013
    #   COMPILER: C:\Qt\Tools\mingw492_32\bin
    #   QT: C:\Qt\5.5\mingw492_32\bin
    #   PLATFORM: windows-xp
    #   DEST: BambooTracker-v%APPVEYOR_BUILD_VERSION%-dev-windows-xp-32bit.zip
    #   MAKE: mingw32-make
    #   RELEASE_BUILD: false
    # Windows XP (Release)
    # - APPVEYOR_JOB_NAME: for Windows XP (Release)
    #   APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013
    #   COMPILER: C:\Qt\Tools\mingw492_32\bin
    #   QT: C:\Qt\5.5\mingw492_32\bin
    #   PLATFORM: windows-xp
    #   DEST: BambooTracker-v%APPVEYOR_BUILD_VERSION%-windows-xp-32bit.zip
    #   MAKE: mingw32-make
    #   RELEASE_BUILD: true
    # macOS Monterey
    - APPVEYOR_JOB_NAME: for macOS
      APPVEYOR_BUILD_WORKER_IMAGE: macos-monterey
      PLATFORM: macos
      DEST: BambooTracker-v$APPVEYOR_BUILD_VERSION-dev-macos-64bit.zip
      MAKE: make
      RELEASE_BUILD: false

for:
-
  # Debug
  matrix:
    only:
      - RELEASE_BUILD: false
  skip_tags: true
# -
#   # Release
#   matrix:
#     only:
#       - RELEASE_BUILD: true
#   skip_non_tags: true

# scripts that run after cloning repository
install:
  - git submodule init
  - git submodule update

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

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

# scripts to run before build
before_build:
  - ps: $env:Path = "$env:QT;$env:COMPILER;$env:Path"
  - sh: |
      # Update outdated cacerts
      curl --insecure --remote-name https://curl.se/ca/cacert.pem
      sudo mv cacert.pem /etc/ssl/cert.pem

      export HOMEBREW_NO_INSTALL_CLEANUP=1
      brew update

      # Download failed: Homebrew-installed `curl` is not installed
      brew install curl
      brew install pkg-config jack p7zip

      export PATH="$HOME/Qt/6.5/macos/bin:$PATH"
      export PKG_CONFIG_PATH="/usr/local/opt/jack/lib/pkgconfig"${PKG_CONFIG_PATH:+':'}$PKG_CONFIG_PATH

# to run your custom scripts instead of automatic MSBuild
build_script:
  - ps: |
      $QMAKE_CONFIGS = if ($env:RELEASE_BUILD -ieq "true") { "CONFIG+=release CONFIG-=debug" } else { "CONFIG-=release CONFIG+=debug CONFIG+=console CONFIG+=nostrip" }
      echo $QMAKE_CONFIGS
      Invoke-Expression ("qmake.exe Project.pro PREFIX=$pwd\target " + $QMAKE_CONFIGS)
      Invoke-Expression ($env:MAKE + " qmake_all")
      Invoke-Expression ($env:MAKE + " -j2")
  - sh: |
      qmake Project.pro PREFIX="$APPVEYOR_BUILD_FOLDER"/target CONFIG-=release CONFIG+=debug CONFIG+=console CONFIG+=nostrip CONFIG+=install_flat CONFIG+=use_jack CONFIG+=no_warnings_are_errors
      $MAKE qmake_all
      $MAKE -j2

# scripts to run after build (working directory and environment changes are persisted from the previous steps)
after_build:
  - ps: Invoke-Expression ($env:MAKE + " install")
  - sh: $MAKE install
  - cd target
  # Port of scripts/package_windows.sh to PowerShell
  - ps: |
      Copy-Item -Recurse ..\*.md .
      $HELP_OUT = (windeployqt.exe -h)
      $DEPLOY_OPTS = "-verbose=2"
      $PLUGIN_OPTS = @("--no-quick-import","--no-system-d3d-compiler","--no-webkit2","--no-opengl-sw","--no-virtualkeyboard","--no-angle")
      $PLUGIN_OPTS | ForEach{If ($HELP_OUT | Select-String $_) { $DEPLOY_OPTS = $DEPLOY_OPTS + " " + $_ }}
      $EXLIB_OPTS = @("svg")
      $EXLIB_OPTS | ForEach{If ($HELP_OUT | Select-String $_) { $DEPLOY_OPTS = $DEPLOY_OPTS + " --no-" + $_ }}
      Invoke-Expression ("windeployqt.exe BambooTracker.exe " + $DEPLOY_OPTS)
      Copy-Item -Recurse translations\*.qm lang
      # Save qico* library for working .ico support!
      Move-Item imageformats\*qico* .\
      Remove-Item -Recurse -Force imageformats\*,translations
      Move-Item *qico* imageformats\
  - sh: bash ../scripts/package_osx.sh
  - cd ..
  - ps: |
      $DEV_LAB = if ($env:RELEASE_BUILD -ieq "true") { "-" } else { "-dev-" }
      mv target BambooTracker-v"$env:APPVEYOR_BUILD_VERSION$DEV_LAB$env:PLATFORM"
      7z a -tzip "$env:DEST" BambooTracker-v"$env:APPVEYOR_BUILD_VERSION$DEV_LAB$env:PLATFORM"
  - sh: |
      mv target BambooTracker-v"$APPVEYOR_BUILD_VERSION"-dev-"$PLATFORM"
      7z a -tzip "$DEST" BambooTracker-v"$APPVEYOR_BUILD_VERSION"-dev-"$PLATFORM"

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

artifacts:
  # pushing a single file
  - path: $(DEST)
