branches:
  only:
  - master

environment:
  matrix:
  - BUILD_SYSTEM: CMake
    GENERATOR: Visual Studio 14 2015 Win64

  - BUILD_SYSTEM: CMake
    GENERATOR: Visual Studio 14 2015

  - BUILD_SYSTEM: Python
    PYTHON: "C:\\Python27"
    PYTHON_VERSION: "2.7.x"
    PYTHON_ARCH: "32"

  - BUILD_SYSTEM: Python
    PYTHON: "C:\\Python36-x64"
    PYTHON_VERSION: "3.6.x"
    PYTHON_ARCH: "64"

  - BUILD_SYSTEM: make
    ARCH: "i686"

  - BUILD_SYSTEM: make
    ARCH: "x86_64"

install:
- IF "%BUILD_SYSTEM%"=="Python" (
    SET "PATH=%PYTHON%;%PYTHON%\Scripts;%PATH%" &&
    pip install --disable-pip-version-check --user --upgrade pip &&
    pip install --upgrade setuptools
  )
- IF "%BUILD_SYSTEM%"=="make" (
    IF "%ARCH%"=="i686" (
      SET "TOOLCHAIN=i686-6.3.0-posix-dwarf-rt_v5-rev1\mingw32"
    ) ELSE (
      SET "TOOLCHAIN=x86_64-6.3.0-posix-seh-rt_v5-rev1\mingw64"
    )
  )

before_build:
- IF "%BUILD_SYSTEM%"=="CMake" ( mkdir builddir && cd builddir && cmake -G "%GENERATOR%" .. )
- IF "%BUILD_SYSTEM%"=="make" (
    SET "CC=gcc" &&
    SET "PATH=C:\mingw-w64\%TOOLCHAIN%\bin;%PATH%" &&
    COPY C:\msys64\usr\bin\make.exe C:\mingw-w64\%TOOLCHAIN%\bin\make.exe &&
    FOR /f %%i in ('C:\cygwin64\bin\date.exe +%%Y-%%m-%%d') DO SET "RELEASE_DATE=%%i"
  )

build_script:
- IF "%BUILD_SYSTEM%"=="CMake" ( cmake --build . --config Debug )
- IF "%BUILD_SYSTEM%"=="Python" ( python setup.py build_ext )
- IF "%BUILD_SYSTEM%"=="make" (
    sh -c "make brotli" &&
    cd bin && 7z a -tzip -mx9 brotli-win-%ARCH%-%RELEASE_DATE%.zip brotli.exe &&
    appveyor PushArtifact brotli-win-%ARCH%-%RELEASE_DATE%.zip && cd ..
  )

test_script:
- IF "%BUILD_SYSTEM%"=="CMake" ( ctest --output-on-failure --interactive-debug-mode 0 -C Debug )
- IF "%BUILD_SYSTEM%"=="Python" ( python setup.py test )
- IF "%BUILD_SYSTEM%"=="make" ( sh -c "make test" )

deploy:
- provider: BinTray
  on:
    branch: master
  username: eustas
  api_key:
    secure: B3rM8JYeIHIw6BfOjHggAeyTmxEf8ZDYmyF9gCwqyWaxyxECD9BuN50SiV2KE/RI
  subject: eustas
  repo: brotli
  package: bin
  version: snapshot
  publish: true
  override: true