# 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.
#   - Full sample file at: https://www.appveyor.com/docs/appveyor-yml/

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

version: 1.0.{build}-{branch}

# Maximum number of concurrent jobs for the project
max_jobs: 1

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

cache:
  - C:\tools\vcpkg\installed\
  - C:\tools\vcpkg\packages\

# Build worker image (VM template)
image: Visual Studio 2017

# save the cache even if the build fails
environment:
  VCPKG_DIR: C:\tools\vcpkg
  APPVEYOR_SAVE_CACHE_ON_ERROR: true

# scripts that are called at very beginning, before repo cloning
init:
  - git config --global core.autocrlf input

# clone directory
clone_folder: c:\projects\citus

# doesn't checkout the entire history, uses github API to download a zip of the repo
shallow_clone: true                 # default is "false"

# scripts which run after cloning repository
install:
  # add flex/bison to path
  - set PATH=%PATH%;C:\msys64\usr\bin
  - flex --version
  - bison --version
  # make postgres think we're a contrib module
  - git clone -b REL_10_STABLE https://github.com/postgres/postgres C:\projects\postgres
  - git -C C:\projects\postgres apply C:\projects\citus\windows\Mkvcbuild.pm.patch
  # only build Citus, don't build the other contrib modules
  - git -C C:\projects\postgres apply C:\projects\citus\windows\Mkvcbuild-minimize.patch
  - rmdir /s /q C:\projects\postgres\contrib
  - mkdir C:\projects\postgres\contrib
  - xcopy /i /e C:\projects\citus C:\projects\postgres\contrib\citus
  - '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"'
  # we need this for usage reporting
  - vcpkg install curl:x64-windows & exit 0

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

platform: x64
configuration:
  - Release

build_script:
  - ps: cd C:\projects\postgres\src\tools\msvc
  - build RELEASE

#---------------------------------#
#       tests configuration       #
#---------------------------------#
before_test:
  - ps: cd C:\projects\postgres\src\tools\msvc
  - install C:\projects\pgsql
  - cd C:\projects\postgres\contrib\citus\src\backend\distributed
  - copy citus--*.sql C:\projects\pgsql\share\extension\
  - perl install.pl C:\projects\pgsql

test_script:
  - ps: cd C:\projects\postgres\contrib\citus\src\test\regress
  - perl pg_regress_multi.pl --bindir=C:\projects\pgsql\bin --load-extension=citus -- --schedule=multi_schedule

on_failure:
  - ps: cd C:\projects\postgres\contrib\citus\src\test\regress
  - type regression.diffs
