version: ci.{build}
clone_depth: 1
skip_tags: true
branches:
  only:
    - master

image:
  - macos-monterey
  - Ubuntu2204
  - Visual Studio 2019

environment:
  APPVEYOR_SAVE_CACHE_ON_ERROR: true
  GC_GOOGLE_CALENDAR_CLIENT_SECRET:
    secure: hwjHTrSAMEbKd9PA+5x/zI4x5Uk4KQm1hdfZzkwiu8k=
  GC_GOOGLE_DRIVE_CLIENT_ID:
    secure: mNqG+pqpMl21ZFVvAMKvhm2rfOdv42fFpnLwfrvX5QqpWVcHEeBuUFeJeUAZfTR0GQGfWfPOEmhb9CG0W1ZJ05TIyb+kTLrWF7iijCiVR6s=
  GC_GOOGLE_DRIVE_CLIENT_SECRET:
    secure: T+BaB/L7x4dPPf592e0kfw4sTlAslUXl10irJqiUjpY=
  GC_GOOGLE_DRIVE_API_KEY:
    secure: oxTAhK/kiLUsXdYvITAgzSqeB5FRcL+XANFuAYpoW5P/xBb7XaLbNnL2gyrmzQeG
  GC_CLOUD_OPENDATA_SECRET:
    secure: 6fPhBiHKvJeOMqXdHGqpkPS+NpUDMczEXjedx8GcjbHr82ISX+gwSuXfOUDLq/S9
  GC_NOKIA_CLIENT_SECRET:
    secure: pvPWraDplrKeRNamt5MKga8fzDmI2+zgFx+y3lsQE6gmBadZU2xkTIc/xCaP7UPv2erNCmKivfMOh2NIcRmqvIHynDoifNVy2P61KyG5v3E=
  GC_DROPBOX_CLIENT_SECRET:
    secure: 7pCVnVEKKmSU4SZN6IFqUw==
  GC_STRAVA_CLIENT_SECRET:
    secure: n3cMS1yy709xhSnTeWABMsoAIkJzy5euh3Pw4ehv0BzszJKoWkypF0cyW8RXSm3M
  GC_CYCLINGANALYTICS_CLIENT_SECRET:
    secure: UY+m3YypNNLUzKyGdrLw8xdCvxuQWRZi9EHS3j1ubLC4qyRL7iEVW6ubumfdh6gT
  GC_CLOUD_DB_BASIC_AUTH:
    secure: OEBetrOnXjsY7wN8hYqmMj6482oDORmAmCq8PI7mfnfiWE6Z4jB676JvgdNlP98q
  GC_CLOUD_DB_APP_NAME:
    secure: bpkyuw/BsJw0OrpuBqQwZ46CHbhkbmcjcMttVtfJoZU=
  GC_POLARFLOW_CLIENT_SECRET:
    secure: h2JdlC1i4QOmwpkz+Xxbrw==
  GC_SPORTTRACKS_CLIENT_SECRET:
    secure: n6a8nJgqMyg+VsVeoIIR8TFzxyDFVi2w/ggetQk5agY=
  GC_RWGPS_API_KEY:
    secure: uUtCyF5ByZ1VYJOztUngIA==
  GC_NOLIO_CLIENT_ID:
    secure: /OFVjEBwU7o3SItIQVf/YlJ8XErxneXIT2N0JyPMSXR1tCbdZVWixMHpqKNWoNk4
  GC_NOLIO_SECRET:
    secure: mmMksvVnfBiXufBDn2gAhQY53n0J9BokSCtDY51uU918QJ/LL4XOojtJp5tMFn8T7ugyDhNASpqZXiK55vxSD53vm+tjufpfzppKEeh93Babvc/VrndLB1X/RZCRUQTR6rka05fYl4e0eBzP1H091A==
  GC_XERT_CLIENT_SECRET:
    secure: /1rVLT8LyJCZ4xNJ5W+NtAcZ1rtKaUjW9SYm/T3gHoc=
  GC_AZUM_CLIENT_SECRET:
    secure: 2ZpXsA3TQv1zftYVyZSF6f83ftCzza+K22ZX1doj7Yc/5dmGl1bnsSeVChJgJ8lQ2fRPYpdmun9cjqwcrtG/zXTTsYuTvYWegHz/4Y0u6Mg=
  GC_TRAINERDAY_API_KEY:
    secure: nDgxUdgLkp0+gaxKRCaAVD5WYAl9pLmOnZ9JLSx3ulqT346nieakd02V3Q7dZYEU

init:

# Windows
# Setup QT 6.8 - 64Bit
- cmd: set QTDIR=C:\Qt\6.8\msvc2022_64
- cmd: set PATH=%QTDIR%\bin;%PATH%
- cmd: qmake --version
# Setup MSVC - VS 2019
- cmd: call c:\"Program Files (x86)"\"Microsoft Visual Studio"\2019\Community\VC\Auxiliary\Build\vcvarsall.bat amd64
# Setup NSIS
- cmd: set PATH=%PATH%;C:\"Program Files (x86)"\NSIS
# install Python 3.7
- cmd: appveyor DownloadFile "https://www.python.org/ftp/python/3.7.9/python-3.7.9-amd64.exe"
- cmd: python-3.7.9-amd64.exe /quiet InstallAllUsers=1 PrependPath=1 TargetDir="C:\Python37-x64"
- cmd: c:\python37-x64\python --version
- cmd: del python-3.7.9-amd64.exe

# Linux / macOS
- sh: >-
    if $CI_LINUX; then
      export OS_NAME=linux
      # Setup QT 6.8
      export QTDIR=$HOME/Qt/6.8
      export LD_LIBRARY_PATH=$QTDIR:$LD_LIBRARY_PATH
      export PATH=$QTDIR/bin:$PATH
      qmake --version
    else
      export OS_NAME=macos
      # Setup QT 6.5
      export QTDIR=$HOME/Qt/6.5/macos
      export PATH=$QTDIR/bin:$PATH
      qmake --version
      # Setup Xcode 14.2
      sudo xcode-select -s /Applications/Xcode-14.2.0.app
    fi

cache:
- gc-ci-libs.zip -> appveyor.yml
- jom_1_1_3.zip
- sip-4.19.8 -> appveyor.yml
- C:\R
- C:\Python -> src\Python\requirements.txt
- c:\tools\vcpkg\installed\
- qwt -> qwt/qwtconfig.pri.in, appveyor.yml
- srmio -> appveyor.yml
- D2XX
- site-packages

install:

# Windows
# Get the libraries
- cmd: if not exist gc-ci-libs.zip appveyor DownloadFile "https://github.com/GoldenCheetah/WindowsSDK/releases/download/v0.1.1/gc-ci-libs.zip"
- cmd: 7z x -y gc-ci-libs.zip -oC:\libs
# GSL
- cmd: vcpkg install gsl:x64-windows

# Get config
- cmd: copy qwt\qwtconfig.pri.in qwt\qwtconfig.pri
- cmd: copy c:\libs\gcconfig64Qt6-Release.appveyor.pri src\gcconfig.pri

# Get jom
- cmd: if not exist jom_1_1_3.zip appveyor DownloadFile "https://download.qt.io/official_releases/jom/jom_1_1_3.zip"
- cmd: 7z x -y jom_1_1_3.zip -oc:\jom\
- cmd: set PATH=%PATH%;c:\jom\;

# Get R and add to config
- ps: >-
    if ($isWindows -And -not (Test-Path 'C:\R')) {
      # Lets use 4.1 until 4.2 issues are fixed
      #$rurl = $(ConvertFrom-JSON $(Invoke-WebRequest https://rversions.r-pkg.org/r-release-win).Content).URL
      $rurl = "https://cran.r-project.org/bin/windows/base/old/4.1.3/R-4.1.3-win.exe"
      Start-FileDownload $rurl "R-win.exe"
      Start-Process -FilePath .\R-win.exe -ArgumentList "/VERYSILENT /DIR=C:\R" -NoNewWindow -Wait
    }
- cmd: set PATH=%PATH%;c:\R\bin\;
- cmd: R --version
- cmd: echo DEFINES+=GC_WANT_R >> src\gcconfig.pri

# Get Python embeddable and install packages
- ps: >-
    if ($isWindows -And -not (Test-Path 'C:\Python')) {
      Start-FileDownload "https://www.python.org/ftp/python/3.7.9/python-3.7.9-embed-amd64.zip" Python.zip
      7z x Python.zip -oC:\Python\
      echo python37.zip . '' 'import site' | Out-File C:\Python\python37._pth -Encoding ascii
      mkdir C:\Python\lib\site-packages
      c:\python37-x64\python -m pip install --upgrade pip
      c:\python37-x64\python -m pip install -r src\Python\requirements.txt -t C:\Python\lib\site-packages
    }

# Get SIP and and install on Python
- ps: >-
    if ($isWindows -And -not (Test-Path 'sip-4.19.8')) {
      Start-FileDownload "https://sourceforge.net/projects/pyqt/files/sip/sip-4.19.8/sip-4.19.8.zip"
        7z x sip-4.19.8.zip
        cd sip-4.19.8
        c:\python37-x64\python --version
        c:\python37-x64\python configure.py
        jom -j2
        cd ..
    }
- cmd: cd sip-4.19.8 & nmake install & cd ..

# Add Python (avoiding collision between GC Context.h and Python context.h)
- cmd: echo DEFINES+=GC_WANT_PYTHON >> src\gcconfig.pri
- cmd: echo PYTHONINCLUDES=-ICore -I\"c:\python37-x64\include\" >> src\gcconfig.pri
- cmd: echo PYTHONLIBS=-L\"c:\python37-x64\libs\" -lpython37 >> src\gcconfig.pri

# GSL
- cmd: echo GSL_INCLUDES=c:\tools\vcpkg\installed\x64-windows\include >> src\gcconfig.pri
- cmd: echo GSL_LIBS=-Lc:\tools\vcpkg\installed\x64-windows\lib -lgsl -lgslcblas >> src\gcconfig.pri

# Linux / macOS
- sh: bash appveyor/$OS_NAME/install.sh

before_build:

# Windows
# Define GC version string, only for tagged builds
- cmd: if %APPVEYOR_REPO_TAG%==true echo DEFINES+=GC_VERSION=VERSION_STRING >> src\gcconfig.pri

# Enable CloudDB
- cmd: echo CloudDB=active >> src\gcconfig.pri

# Add Train Robot
- cmd: echo DEFINES+=GC_WANT_ROBOT >> src\gcconfig.pri

# Enable TrainerDay Query API; pagesize depends on the keys remote configuration
- cmd: echo DEFINES+=GC_WANT_TRAINERDAY_API >> src\gcconfig.pri
- cmd: echo DEFINES+=GC_TRAINERDAY_API_PAGESIZE=25 >> src\gcconfig.pri

# Avoid macro redefinition warnings
- cmd: echo DEFINES+=_MATH_DEFINES_DEFINED >> src\gcconfig.pri

# Avoid conflicts between Windows.h min/max macros and limits.h
- cmd: echo DEFINES+=NOMINMAX >> src\gcconfig.pri


# Linux / macOS
- sh: bash appveyor/$OS_NAME/before_build.sh
# Define GC version string, only for tagged builds
- sh: if $APPVEYOR_REPO_TAG; then echo DEFINES+=GC_VERSION=VERSION_STRING >> src/gcconfig.pri; fi

# Patch Secrets.h (Windows / Linux / macOS)
- ps: (Get-Content src\Core\Secrets.h) -replace '__GC_GOOGLE_CALENDAR_CLIENT_SECRET__', $env:GC_GOOGLE_CALENDAR_CLIENT_SECRET | Set-Content src\Core\Secrets.h
- ps: (Get-Content src\Core\Secrets.h) -replace '__GC_GOOGLE_DRIVE_CLIENT_ID__', $env:GC_GOOGLE_DRIVE_CLIENT_ID | Set-Content src\Core\Secrets.h
- ps: (Get-Content src\Core\Secrets.h) -replace '__GC_GOOGLE_DRIVE_CLIENT_SECRET__', $env:GC_GOOGLE_DRIVE_CLIENT_SECRET | Set-Content src\Core\Secrets.h
- ps: (Get-Content src\Core\Secrets.h) -replace '__GC_GOOGLE_DRIVE_API_KEY__', $env:GC_GOOGLE_DRIVE_API_KEY | Set-Content src\Core\Secrets.h
- ps: (Get-Content src\Core\Secrets.h) -replace 'OPENDATA_DISABLE', 'OPENDATA_ENABLE' | Set-Content src\Core\Secrets.h
- ps: (Get-Content src\Core\Secrets.h) -replace '__GC_CLOUD_OPENDATA_SECRET__', $env:GC_CLOUD_OPENDATA_SECRET | Set-Content src\Core\Secrets.h
- ps: (Get-Content src\Core\Secrets.h) -replace '__GC_WITHINGS_CONSUMER_SECRET__', $env:GC_WITHINGS_CONSUMER_SECRET | Set-Content src\Core\Secrets.h
- ps: (Get-Content src\Core\Secrets.h) -replace '__GC_NOKIA_CLIENT_SECRET__', $env:GC_NOKIA_CLIENT_SECRET | Set-Content src\Core\Secrets.h
- ps: (Get-Content src\Core\Secrets.h) -replace '__GC_DROPBOX_CLIENT_SECRET__', $env:GC_DROPBOX_CLIENT_SECRET | Set-Content src\Core\Secrets.h
- ps: (Get-Content src\Core\Secrets.h) -replace '__GC_STRAVA_CLIENT_SECRET__', $env:GC_STRAVA_CLIENT_SECRET | Set-Content src\Core\Secrets.h
- ps: (Get-Content src\Core\Secrets.h) -replace '__GC_CYCLINGANALYTICS_CLIENT_SECRET__', $env:GC_CYCLINGANALYTICS_CLIENT_SECRET | Set-Content src\Core\Secrets.h
- ps: (Get-Content src\Core\Secrets.h) -replace '__GC_CLOUD_DB_BASIC_AUTH__', $env:GC_CLOUD_DB_BASIC_AUTH | Set-Content src\Core\Secrets.h
- ps: (Get-Content src\Core\Secrets.h) -replace '__GC_CLOUD_DB_APP_NAME__', $env:GC_CLOUD_DB_APP_NAME | Set-Content src\Core\Secrets.h
- ps: (Get-Content src\Core\Secrets.h) -replace '__GC_POLARFLOW_CLIENT_SECRET__', $env:GC_POLARFLOW_CLIENT_SECRET | Set-Content src\Core\Secrets.h
- ps: (Get-Content src\Core\Secrets.h) -replace '__GC_SPORTTRACKS_CLIENT_SECRET__', $env:GC_SPORTTRACKS_CLIENT_SECRET | Set-Content src\Core\Secrets.h
- ps: (Get-Content src\Core\Secrets.h) -replace '__GC_RWGPS_API_KEY__', $env:GC_RWGPS_API_KEY | Set-Content src\Core\Secrets.h
- ps: (Get-Content src\Core\Secrets.h) -replace '__GC_NOLIO_CLIENT_ID__', $env:GC_NOLIO_CLIENT_ID | Set-Content src\Core\Secrets.h
- ps: (Get-Content src\Core\Secrets.h) -replace '__GC_NOLIO_SECRET__', $env:GC_NOLIO_SECRET | Set-Content src\Core\Secrets.h
- ps: (Get-Content src\Core\Secrets.h) -replace '__GC_XERT_CLIENT_SECRET__', $env:GC_XERT_CLIENT_SECRET | Set-Content src\Core\Secrets.h
- ps: (Get-Content src\Core\Secrets.h) -replace '__GC_AZUM_CLIENT_SECRET__', $env:GC_AZUM_CLIENT_SECRET | Set-Content src\Core\Secrets.h
- ps: (Get-Content src\Core\Secrets.h) -replace '__GC_TRAINERDAY_API_KEY__', $env:GC_TRAINERDAY_API_KEY | Set-Content src\Core\Secrets.h

build_script:

# Windows
- cmd: qmake.exe build.pro -r -spec win32-msvc
- cmd: if not exist qwt\lib\qwt.lib jom -j1 sub-qwt & exit /b 1
- cmd: jom -j4 sub-src

# Linux / macOS
- sh: qmake build.pro -r QMAKE_CXXFLAGS_WARN_ON+="-Wno-unused-private-field -Wno-c++11-narrowing -Wno-deprecated-declarations -Wno-deprecated-register -Wno-nullability-completeness -Wno-sign-compare -Wno-inconsistent-missing-override" QMAKE_CFLAGS_WARN_ON+="-Wno-deprecated-declarations -Wno-sign-compare"
- sh: if test ! -f qwt/lib/libqwt.a; then make sub-qwt; false; fi
- sh: make -j4 sub-src

after_build:

# Windows/macOS/Linux: set PUBLISH_BINARIES according to commit message
- ps: Set-AppveyorBuildVariable -Name 'PUBLISH_BINARIES' -Value false
- ps: if ($env:APPVEYOR_REPO_COMMIT_MESSAGE_EXTENDED -Match "\[publish binaries\]") { Set-AppveyorBuildVariable -Name 'PUBLISH_BINARIES' -Value true }

# Windows
- cmd: cd src\release

# copy dependencies
- cmd: windeployqt --release GoldenCheetah.exe
- cmd: copy c:\libs\10_Precompiled_DLL\usbexpress_3.5.1\USBXpress\USBXpress_API\Host\x64\SiUSBXp.dll
- cmd: copy c:\libs\10_Precompiled_DLL\libsamplerate64\lib\libsamplerate-0.dll
- cmd: copy c:\OpenSSL-Win64\bin\lib*.dll
- cmd: copy c:\OpenSSL-Win64\license.txt "OpenSSL License.txt"
- cmd: xcopy /s /i /e /q C:\Python .
- cmd: copy C:\Python\LICENSE.txt "PYTHON LICENSE.txt"
- cmd: copy c:\tools\vcpkg\installed\x64-windows\bin\gsl*.dll

# ReadMe, license and icon files
- cmd: copy ..\Resources\win32\ReadMe.txt
- cmd: echo GoldenCheetah is licensed under the GNU General Public License v2 > license.txt
- cmd: echo. >> license.txt
- cmd: type ..\..\COPYING >> license.txt
- cmd: copy ..\Resources\win32\gc.ico

# Installer script
- cmd: copy ..\Resources\win32\GC3.7-Master-W64-QT6.nsi

# Build the installer
- cmd: makensis GC3.7-Master-W64-QT6.nsi
- cmd: move GoldenCheetah_v3.7_64bit_Windows.exe ..\..\GoldenCheetah_v3.7_x64.exe
- cmd: cd ..\..

# Linux / macOS
- sh: bash appveyor/$OS_NAME/after_build.sh

test_script:

# Windows
- cmd: src\release\GoldenCheetah --version 2>GCversionWindows.txt
- cmd: git log -1 >> GCversionWindows.txt
- ps: if ($isWindows) { CertUtil -hashfile GoldenCheetah_v3.7_x64.exe sha256 | Select-Object -First 2 | Add-Content GCversionWindows.txt }
- cmd: type GCversionWindows.txt

# Linux / macOS
- sh: >-
    if $CI_LINUX; then
      ./GoldenCheetah_v3.7_x64.AppImage --version 2>GCversionLinux.txt
      git log -1 >> GCversionLinux.txt
      shasum -a 256 GoldenCheetah_v3.7_x64.AppImage | cut -f 1 -d ' '  >> GCversionLinux.txt
      cat GCversionLinux.txt
    else
      src/GoldenCheetah.app/Contents/MacOS/GoldenCheetah --version 2>GCversionMacOS.txt
      git log -1 >> GCversionMacOS.txt
      shasum -a 256 GoldenCheetah_v3.7_x64.dmg | cut -f 1 -d ' ' >> GCversionMacOS.txt
      cat GCversionMacOS.txt
    fi

artifacts:
# Windows
- path: GoldenCheetah_v3.7_x64.exe
  name: GCwindowsInstaller
- path: GCversionWindows.txt
  name: GCversionWindows
# macOS
- path: GoldenCheetah_v3.7_x64.dmg
  name: GCmacOSpackage
- path: GCversionMacOS.txt
  name: GCversionMacOS
# Linux
- path: GoldenCheetah_v3.7_x64.AppImage
  name: GClinuxAppImage
- path: GCversionLinux.txt
  name: GCversionLinux

deploy:
# deploy continuous builds to GitHub release
  - provider: GitHub
    auth_token:
      secure: 807DE/9vib/Kjz5Tah/Zc6zkoigLEWRzASw/DUWjLwZ5d8HHomXqWQ7iln4VtOqL
    tag: snapshot
    release: 'Snapshot Builds'
    description: ''
    artifact: GCwindowsInstaller, GCversionWindows, GCmacOSpackage, GCversionMacOS, GClinuxAppImage, GCversionLinux
    draft: false
    prerelease: true
    force_update: true
    on:
      PUBLISH_BINARIES: true
      APPVEYOR_REPO_NAME: "GoldenCheetah/GoldenCheetah"
