version: '1.0.0-{build}'

branches:
  only:
  - master
  - webviewprinter
  - /\d+\.\d+\.\d+(-\d+)?/

configuration: Release

platform:
- x64
  
environment:
  global:
      GDRIVE_REFRESH_TOKEN:
        secure: +J2q/4lkiBXik5Ttvt06vpNiWBjNIXx+jFnYw1rOR9sLkyksyXGj+NeNKQB8kPwE

  matrix:
    - job_name: "PageEdit macOS Mojave"
      APPVEYOR_BUILD_WORKER_IMAGE: macOS-Mojave

    - job_name: "PageEdit Ubuntu 1804 x64"
      APPVEYOR_BUILD_WORKER_IMAGE: Ubuntu1804

    - job_name: "PageEdit VS2019 x64"
      APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019

#matrix:
#  exclude:
#    - job_name: "Sigil macOS Mojave"
#      APPVEYOR_BUILD_WORKER_IMAGE: macOS-Mojave
#    - job_name: "Sigil Ubuntu 1804 x64"
#      APPVEYOR_BUILD_WORKER_IMAGE: Ubuntu1804
#    - job_name: "Sigil VS2019 x64"
#      APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019

init:
  - cmd: echo NUMBER_OF_PROCESSORS=%NUMBER_OF_PROCESSORS%
  - sh: echo _NPROCESSORS_ONLN=$(getconf _NPROCESSORS_ONLN)
  - cmd: set /p RedistVersion=<"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\Microsoft.VCRedistVersion.default.txt"
  - ps: $commit = $env:APPVEYOR_REPO_COMMIT.SubString(0,7)
  - ps: $timestamp = $env:APPVEYOR_REPO_COMMIT_TIMESTAMP.SubString(0,10)
  - ps: Update-AppveyorBuild -Version ("{0}-{1}-{2}" -f $env:APPVEYOR_REPO_BRANCH, $commit, $timestamp)
  # Skip after build stuff unless '[deploy]' is in the commit message
  - ps: $deploy = $env:APPVEYOR_REPO_COMMIT_MESSAGE -match '.*?\[deploy\].*?'
  - ps: if(($deploy -eq $true) -and (-not $env:APPVEYOR_PULL_REQUEST_NUMBER) ) {$env:DEPLOY_INSTALLERS = $true}

clone_script:
- ps: >-
    if(-not $env:APPVEYOR_PULL_REQUEST_NUMBER) {
      git clone -q --depth=1 --branch=$env:APPVEYOR_REPO_BRANCH https://github.com/$env:APPVEYOR_REPO_NAME.git $env:APPVEYOR_BUILD_FOLDER
      git checkout -qf $env:APPVEYOR_REPO_COMMIT
    } else {
      git clone -q --depth=1 https://github.com/$env:APPVEYOR_REPO_NAME.git $env:APPVEYOR_BUILD_FOLDER
      git fetch -q origin +refs/pull/$env:APPVEYOR_PULL_REQUEST_NUMBER/merge:
      git checkout -qf FETCH_HEAD
    }
    
    Set-Location $env:APPVEYOR_BUILD_FOLDER

only_commits:
  files:
    - CMakeLists.txt
    - .appveyor.yml
    - installer/PageEdit.iss
    - ci_scripts/
    - javascript/
    - '**/*.cpp'
    - '**/*.h'
    - '**/*.ui'

for:
  # Windows
  - matrix:
      only:
        - job_name:  "PageEdit VS2019 x64"

    cache:
      - C:\ProgramData\chocolatey\bin -> appveyor.yml
      - C:\ProgramData\chocolatey\lib -> appveyor.yml
      - C:\Python38-x64\Lib\site-packages -> appveyor.yml

    environment:
      GDRIVE_DIR:
        secure: igOA10tmVbccXE8T92NCKPGcsixGGzyu69QmsBGw6seBOqcQ8+XXm0vjkoLMtrLF
      INNO: C:\Program Files (x86)\Inno Setup 6
      REDIST: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Redist\MSVC\%RedistVersion%\vcredist_%PLATFORM%.exe
      DOWNLOADQT: https://github.com/dougmassay/win-qtwebkit-5.212/releases/download/v5.212-1/MyQt%PLATFORM%_5.12.9_VS2017_WE.7z
      GDRIVE: https://github.com/dougmassay/win-qtwebkit-5.212/releases/download/v5.212-1/gdrive-windows-x64.exe
      QT: C:\MyQtx64_WE\Qt5.12.9
      PYTHON: C:\Python38-x64
      CMAKE64BIT: -DWIN_INSTALLER_USE_64BIT_CRT=1
    
    install:
      - ps: if($env:DEPLOY_INSTALLERS) {echo 'Deployment= $env:DEPLOY_INSTALLERS'}
      - cmd: choco install ninja
      - cmd: cp '%REDIST%' installer/
      - cmd: cd ..\..
      - cmd: curl.exe -L -o webkit.7z %DOWNLOADQT%
      - cmd: 7z x webkit.7z -y
      - cmd: set PATH=%PYTHON%;%PYTHON%\Scripts;%QT%\bin;%INNO%;%PATH%
      - cmd: echo 'PATH = %PATH%'

    before_build:
      - cmd: mkdir %APPVEYOR_BUILD_FOLDER%\build
      - cmd: cd %APPVEYOR_BUILD_FOLDER%\build
      - cmd: curl.exe -L -o gdrive.exe %GDRIVE%
      - cmd: set PATH=%APPVEYOR_BUILD_FOLDER%\build;%PATH%
      - cmd: gdrive.exe version
      - cmd: qmake -v
      - cmd: call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" %PLATFORM% -vcvars_ver=14.1
      - cmd: cmake .. -G "Ninja" -DCMAKE_BUILD_TYPE=%configuration% -DDEPLOY_SFX=1 -DQt5_DIR=%QT%\lib\cmake\Qt5 %CMAKE64BIT%

    build_script:
      - cmd: ninja -j%NUMBER_OF_PROCESSORS%

    after_build:
      - ps: >-
          if($env:DEPLOY_INSTALLERS) {
            echo 'Deploying installer'
            ninja -j2 deployinstaller
          }else {echo 'No deployment specified'}

    deploy_script:
      - ps: if($env:DEPLOY_INSTALLERS) {python ../ci_scripts/gddeploy.py}

  # Linux
  - matrix:
      only:
        - job_name: "PageEdit Ubuntu 1804 x64"

    stack: python 3

    install:
      - |
        sudo apt-get remove -y --purge man-db
        sudo apt-get update -qq
        sudo apt-get install -y zlib1g-dev cmake cmake-data build-essential ninja
        sudo apt-get install -y qtbase5-dev qttools5-dev qttools5-dev-tools qtwebengine5-dev qt5-default qtchooser
      - sh: which qmake
      - sh: qmake -v
      - sh: gcc --version
    
    before_build:
      - sh: mkdir $APPVEYOR_BUILD_FOLDER/build
      - sh: cd $APPVEYOR_BUILD_FOLDER/build
      - sh: pwd
      - sh: |-
          cmake .. -G "Ninja" \
          -DCMAKE_C_COMPILER=clang \
          -DCMAKE_CXX_COMPILER=clang++ \
          -DCMAKE_BUILD_TYPE=Debug

    build_script:
      - sh: ninja -j$(getconf _NPROCESSORS_ONLN)

# Mac
  - matrix:
      only:
        - job_name: "PageEdit macOS Mojave"
  
    environment:
      GDRIVE_DIR:
        secure: w7+5ow7jVVgHRkrwnxImJXbustFtv1TpVRxnskIP7O7Fpxj1Tgp1wXQ5urbnzBvs
      HOMEBREW_NO_AUTO_UPDATE: 1
      HOMEBREW_NO_INSTALL_CLEANUP: 1
      MACOSX_DEPLOYMENT_TARGET: 10.12
      DOWNLOADQT: https://github.com/kevinhendricks/BuildSigilOnMac/releases/download/for_sigil_1.0.0/Qt5129.tar.xz
      DOWNLOADSDK: https://github.com/phracker/MacOSX-SDKs/releases/download/10.15/MacOSX10.14.sdk.tar.xz

    stack: python 3
    
    install:
      - ps: if($env:DEPLOY_INSTALLERS) {echo 'Deployment= $env:DEPLOY_INSTALLERS'}
      - sh: brew install gdrive
      - sh: brew install wget
      - sh: pwd
      - sh: cd ~
      - sh: wget $DOWNLOADQT
      - sh: tar xzf Qt5129.tar.xz
      - sh: export MYQTHOME=${HOME}/Qt5129
      - sh: export PATH=${PATH}:${MYQTHOME}/bin
      - sh: export PATH=${HOME}/venv3.8/bin:${PATH}
      - sh: cd ${MYQTHOME}/bin && echo [Paths] > qt.conf && echo Prefix=.. >> qt.conf
      - sh: cd /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs
      - sh: sudo wget $DOWNLOADSDK
      - sh: sudo tar xzf MacOSX10.14.sdk.tar.xz
      - sh: export Qt5_DIR=${MYQTHOME}/lib/cmake/Qt5
      - sh: export Qt5_Dir=${MYQTHOME}/lib/cmake/Qt5
      - sh: export QT_PLUGIN_PATH=${MYQTHOME}/plugins
      - sh: qmake -v

    before_build:
      - sh: mkdir $APPVEYOR_BUILD_FOLDER/build
      - sh: cd $APPVEYOR_BUILD_FOLDER/build
      - sh: pwd
      - sh: |-
          cmake -DCMAKE_OSX_DEPLOYMENT_TARGET=10.12 \
          -DCMAKE_BUILD_TYPE=Release \
          -DCMAKE_CXX_FLAGS=-Wno-inconsistent-missing-override \
          -DCMAKE_PREFIX_PATH=${MYQTHOME}/lib/cmake \
          -DCMAKE_OSX_SYSROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/ ../

    build_script:
      - sh: make -j$(getconf _NPROCESSORS_ONLN)

    after_build:
      - ps: >-
          if($env:DEPLOY_INSTALLERS) {
            echo 'Deploying App'
            make addframeworks
            cd ./bin
            tar -cJf PageEdit.tar.xz PageEdit.app
            cd ../
          } else {echo 'No deployment specified'}

    deploy_script:
      - ps: if($env:DEPLOY_INSTALLERS) {python3 ../ci_scripts/gddeploy.py}
