version: build {build}

# Skipping commits affecting specific files (GitHub only).
# More details here: https://www.appveyor.com/docs/appveyor-yml and https://www.appveyor.com/docs/how-to/filtering-commits
skip_commits:
  files:
    - .ci/travis-*
    - .github/
    - .tx/
    - webclient/
    - .clang-format
    - .*ignore
    - .codacy.yml
    - .gitlab-ci.yml
    - .travis.yml
    - '**/*.md'
    - Dockerfile
    - LICENSE

skip_branch_with_pr: true

clone_depth: 50    #same as travis, see https://www.appveyor.com/blog/2014/06/04/shallow-clone-for-git-repositories/

image: Visual Studio 2017

cache:
    - c:\Tools\vcpkg\installed

environment:
    matrix:
        - target_arch: win64
          qt_ver: 5.9\msvc2017_64
          cmake_generator: Visual Studio 15 2017 Win64
          cmake_toolset: v141,host=x64
          vcpkg_arch: x64

        - target_arch: win32
          qt_ver: 5.9\msvc2015 # Qt doesn't provide a msvc2017_32
          cmake_generator: Visual Studio 15 2017
          cmake_toolset: v141
          vcpkg_arch: x86

install:
    - vcpkg remove --outdated --recurse
    - vcpkg install openssl protobuf liblzma zlib --triplet %vcpkg_arch%-windows

services:
    - mysql

build_script:
    - ps: |
        New-Item -ItemType directory -Path $env:APPVEYOR_BUILD_FOLDER\build
        Set-Location -Path $env:APPVEYOR_BUILD_FOLDER\build
        $vcpkgbindir = "C:\Tools\vcpkg\installed\$env:vcpkg_arch-windows\bin"
        $mysqldll = "c:\Program Files\MySQL\MySQL Server 5.7\lib\libmysql.dll"
        cmake --version
        cmake .. -G "$env:cmake_generator" -T "$env:cmake_toolset" "-DCMAKE_TOOLCHAIN_FILE=c:/tools/vcpkg/scripts/buildsystems/vcpkg.cmake" "-DCMAKE_PREFIX_PATH=c:/Qt/$env:qt_ver;$vcpkgbindir" "-DWITH_SERVER=1" "-DMYSQLCLIENT_LIBRARIES=$mysqldll"
    - msbuild PACKAGE.vcxproj /p:Configuration=Release
    - ps: |
        $exe = dir -name *.exe
        $new_name = $exe.Replace(".exe", "-${env:target_arch}.exe")
        Push-AppveyorArtifact $exe -FileName $new_name
        $cmake_name = $exe.Replace(".exe", "-${env:target_arch}.cmake.txt")
        Push-AppveyorArtifact CMakeCache.txt -FileName $cmake_name
        $json = New-Object PSObject
        (New-Object PSObject | Add-Member -PassThru NoteProperty bin $new_name | Add-Member -PassThru NoteProperty cmake $cmake_name | Add-Member -PassThru NoteProperty commit $env:APPVEYOR_REPO_COMMIT) | ConvertTo-JSON | Out-File -FilePath "latest-$env:target_arch" -Encoding ASCII
        Push-AppveyorArtifact "latest-$env:target_arch"
        $version = $matches['content']

test: off


# Builds for pull requests skip the deployment step altogether
deploy:
# Deploy configuration for "beta" releases
  - provider: GitHub
    auth_token:
      secure: p+7wPVry2XEa6TBm9XH8IaQZbBmXQ/J2ldbGmcIxUZD3NkkPrSRRlmE7Of1CBBIO
    tag: "$(APPVEYOR_REPO_TAG_NAME)"
    release: "Cockatrice $(APPVEYOR_REPO_TAG_NAME)"
    description: "Beta release of Cockatrice"
    artifact: /.*\.exe/
    force_update: true
    draft: false
    prerelease: true
    on:
      APPVEYOR_REPO_TAG: true
      APPVEYOR_REPO_TAG_NAME: /([0-9]|[1-9][0-9])(\.([0-9]|[1-9][0-9])){2}-beta(\.([2-9]|[1-9][0-9]))?$/    # regex to match semver naming convention for beta pre-releases

# Deploy configuration for "stable" releases
  - provider: GitHub
    auth_token:
       secure: p+7wPVry2XEa6TBm9XH8IaQZbBmXQ/J2ldbGmcIxUZD3NkkPrSRRlmE7Of1CBBIO
    tag: "$(APPVEYOR_REPO_TAG_NAME)"
    release: "Cockatrice $(APPVEYOR_REPO_TAG_NAME)"
    artifact: /.*\.exe/
    force_update: true
    draft: false
    prerelease: false
    on:
      APPVEYOR_REPO_TAG: true
      APPVEYOR_REPO_TAG_NAME: /([0-9]|[1-9][0-9])(\.([0-9]|[1-9][0-9])){2}$/    # regex to match semver naming convention for stable full releases


# Announcements of build image updates: https://www.appveyor.com/updates/
# Official validator for ".appveyor.yml" config file: https://ci.appveyor.com/tools/validate-yaml
# AppVeyor config documentation: https://www.appveyor.com/docs/build-configuration/
