version: '{build}'

environment:
  matrix:
    - locale: zh-CN
    - locale: ja-JP
    - locale: en-US

install:
  # fix tar xz
  - set PATH=%PATH%;C:\MinGW\msys\1.0\bin 
  
  # submodules
  - git submodule update --init --recursive
  
  # environment and system dependency
  - bash -c "curl --retry 5 --connect-timeout 30 --location --remote-header-name --remote-name https://github.com/premake/premake-core/releases/download/v5.0.0-alpha10/premake-5.0.0-alpha10-windows.zip ; exit 0"
  - 7z x premake-5.0.0-alpha10-windows.zip
  
  - bash -c "curl --retry 5 --connect-timeout 30 --location --remote-header-name --remote-name https://github.com/libevent/libevent/releases/download/release-2.0.22-stable/libevent-2.0.22-stable.tar.gz ; exit 0"
  - tar xf libevent-2.0.22-stable.tar.gz
  - move libevent-2.0.22-stable event
  - xcopy /E event\WIN32-Code event\include
  
  - bash -c "curl --retry 5 --connect-timeout 30 --location --remote-header-name --remote-name http://downloads.sourceforge.net/freetype/freetype-2.7.tar.bz2 ; exit 0"
  - tar xf freetype-2.7.tar.bz2
  - move freetype-2.7 freetype
  
  - bash -c "curl --retry 5 --connect-timeout 30 --location --remote-header-name --remote-name http://downloads.sourceforge.net/irrlicht/irrlicht-1.8.4.zip ; exit 0"
  - 7z x irrlicht-1.8.4.zip
  - md irrlicht
  - move irrlicht-1.8.4\source\Irrlicht irrlicht\src
  - move irrlicht-1.8.4\include irrlicht\include
  
  - bash -c "curl --retry 5 --connect-timeout 30 --location --remote-header-name --remote-name https://www.lua.org/ftp/lua-5.2.4.tar.gz ; exit 0"
  - tar xf lua-5.2.4.tar.gz
  - move lua-5.2.4\src lua
  
  - bash -c "curl --retry 5 --connect-timeout 30 --location --remote-header-name --remote-name https://www.sqlite.org/2016/sqlite-amalgamation-3150200.zip ; exit 0"
  - 7z x sqlite-amalgamation-3150200.zip
  - move sqlite-amalgamation-3150200 sqlite3

  # let premake happy
  - xcopy /E premake\* .
  
  # patch irrlicht
  - patch -p1 < irrlicht\irrlicht.patch
  
  # premake
  - premake5 vs2015
  
configuration: Release

build:
    project: build/ygo.sln
    parallel: true

after_build:
  - mv bin\release\ygopro.exe .
  - curl --location --retry 5 https://github.com/moecube/ygopro-database/archive/master.tar.gz | tar --strip-components=1 -zxf - ygopro-database-master/locales
  - cp locales/%locale%/* .
  - mkdir replay
  - mkdir pics
  - curl --location --retry 5 --output ygopro-images-%locale%.zip https://github.com/moecube/ygopro-images/releases/download/latest/ygopro-images-%locale%.zip
  - unzip -q -d pics ygopro-images-%locale%.zip
  - curl --location --retry 5 --output ygopro-starter-pack-master.zip https://github.com/moecube/ygopro-starter-pack/archive/master.zip
  - unzip -q ygopro-starter-pack-master.zip
  - mv ygopro-starter-pack-master/* .
  - tar -zcf ygopro-%APPVEYOR_REPO_TAG_NAME%-win32-%locale%.tar.gz --format=posix --exclude='.git*' ygopro.exe LICENSE README.md lflist.conf strings.conf system.conf cards.cdb script textures deck single pics replay

test: off

artifacts:
  - path: ygopro-$(APPVEYOR_REPO_TAG_NAME)-win32-$(locale).tar.gz
    name: ygopro
    
deploy:
  description: 'Automatic build'
  provider: GitHub
  auth_token:
    secure: itZ9Z1dxEpfPJLdTs/PiY98pVZ3GCLNWfid7eAu7SL88Jl9AIrf/3rviKFEbsnoY # your encrypted token from GitHub
  on:
    appveyor_repo_tag: true        # deploy on tag push only

branches:
  only:
    - master
    - /\d+\..+/

cache:
  - premake-5.0.0-alpha10-windows.zip
  - libevent-2.0.22-stable.tar.gz
  - freetype-2.7.tar.bz2
  - irrlicht-1.8.4.zip
  - lua-5.2.4.tar.gz
  - sqlite-amalgamation-3150200.zip
