version: '1.0.0-{build}'

branches:
  only:
  - master
  - appearance
  - /\d+\.\d+\.\d+(-\d+)?/
  
clone_folder: c:\project\sigil

image:
- Visual Studio 2017

configuration: Release

platform:
- x64

init:
  - set /p RedistVersion=<"C:\Program Files (x86)\Microsoft Visual Studio\2017\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)

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

install:
  - choco install ninja

environment:
  global:
      INNO: C:\Program Files (x86)\Inno Setup 5
      REDIST: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Redist\MSVC\%RedistVersion%\vcredist_%PLATFORM%.exe
      DOWNLOAD: https://github.com/dougmassay/win-qtwebkit-5.212/releases/download/v5.212-1/MyQt%PLATFORM%_5.12.6_VS2017_WE.7z
      GDRIVE: https://github.com/gdrive-org/gdrive/releases/download/2.1.0/gdrive-windows-x64.exe
      GDRIVE_REFRESH_TOKEN:
        secure: +J2q/4lkiBXik5Ttvt06vpNiWBjNIXx+jFnYw1rOR9sLkyksyXGj+NeNKQB8kPwE
      GDRIVE_DIR:
        secure: e/trZFJnPzo9saqwWWn6+E3ZPoItqflSviT92eeH3Qk76GuEHrPk9DrcG1bh3SNX
  matrix:
    - PYTHON: C:\Python37
      QT: C:\MyQt32\Qt5.12.2
      CMAKE64BIT:
    - PYTHON: C:\Python37-x64
      QT: C:\MyQtx64_WE\Qt5.12.6
      CMAKE64BIT: -DWIN_INSTALLER_USE_64BIT_CRT=1

matrix:
  exclude:
    - platform: x86
      PYTHON: C:\Python37
    - platform: x64
      PYTHON: C:\Python37
  fast_finish: true


only_commits:
  files:
    - CMakeLists.txt
    - appveyor.yml
    - installer/Sigil.iss
    - src/
    - internal/
    - cmake_extras/
    - 3rdparty/

before_build:
- cmd: |-
    rmdir c:\cygwin /s /q
    rmdir c:\Python35 /s /q
    rmdir c:\Python35-x64 /s /q
    cp '%REDIST%' installer/
    mkdir build
    cd ..\..
    curl.exe -L -o webkit.7z %DOWNLOAD%
    7z x webkit.7z -y
    set PATH=%PYTHON%;%PYTHON%\Scripts;%QT%\bin;%INNO%;%PATH%
    echo 'PATH = %PATH%'
    python -m pip install --upgrade pip
    pip3.7 install six==1.13.0
    pip3.7 install html5lib==1.0.1
    pip3.7 install regex==2019.11.1
    pip3.7 install css-parser==1.0.4
    pip3.7 install cssselect==1.0.3
    pip3.7 install chardet==3.0.4
    pip3.7 install pillow==6.2.1
    pip3.7 install PyQt5==5.12.3 PyQt5-sip==4.19.18
    pip3.7 install lxml==4.4.2
    cd project\sigil\build
    curl.exe -L -o gdrive.exe %GDRIVE%
    c:\project\sigil\build\gdrive.exe version
    call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" %PLATFORM%
    echo 'LIB = %LIB%'
    echo 'LIBPATH = %LIBPATH%'
    echo 'INCLUDE = %INCLUDE%'
    echo 'CL = %CL%'
    cmake .. -G "Ninja" -DCMAKE_BUILD_TYPE=%configuration% -DQt5_DIR=%QT%\lib\cmake\Qt5 %CMAKE64BIT%

    
build_script:
- cmd: |-
    ninja -j4
 

after_build:
- cmd: |-
    ninja -j4 makeinstaller

deploy_script:
- ps: >-
    if(-not $env:appveyor_pull_request_number) {
        python --version
        c:\project\sigil\build\gdrive.exe version
        python ..\ci_scripts\gddeploy.py
    }

#artifacts:
#    path: build\installer\*.exe

