version: '{build}'
image: Visual Studio 2019

environment:
  matrix:
    - locale: zh-CN
#    - locale: ja-JP
    - locale: en-US
  irrklang_pro: 1
  access_token:
    secure: LTri8weHSdlUoXbLVawx5A4JluBWEMf6cfWWt0UeXNn7kV/bkcMEsFTWDgh1mcVy

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-alpha14/premake-5.0.0-alpha14-windows.zip ; exit 0"
  - 7z x premake-5.0.0-alpha14-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.10.1.tar.gz ; exit 0"
  - tar xf freetype-2.10.1.tar.gz
  - move freetype-2.10.1 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.3.5.tar.gz ; exit 0"
  - tar xf lua-5.3.5.tar.gz
  - move lua-5.3.5\src lua

  - bash -c "curl --retry 5 --connect-timeout 30 --location --remote-header-name --remote-name https://www.sqlite.org/2020/sqlite-amalgamation-3310100.zip ; exit 0"
  - 7z x -y sqlite-amalgamation-3310100.zip
  - move sqlite-amalgamation-3310100 sqlite3

  - git clone --depth=1 https://%access_token%@github.com/purerosefallen/irrklang
  - mv -f irrklang/plugins/ikpmp3 .

  # let premake happy
  - xcopy /E premake\* .
  
  # patch irrlicht
  - patch -p0 < irrlicht\irrlicht.patch
  
  # premake
  - premake5 vs2019
  
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 http://amagyjs.ygo233.com:8080/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/* .
  - curl --location --retry 5 --output ygopro-sounds-master.zip https://github.com/moecube/ygopro-sounds/archive/master.zip
  - unzip -q ygopro-sounds-master.zip
  - cp -rf ygopro-sounds-master/sound .
  - 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 sound

test: off

artifacts:
  - path: ygopro-$(APPVEYOR_REPO_TAG_NAME)-win32-$(locale).tar.gz
    name: ygopro
    
deploy:
  description: 'Automatic build'
  provider: GitHub
  auth_token: $(access_token)
  on:
    appveyor_repo_tag: true        # deploy on tag push only

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

cache:
  - premake-5.0.0-alpha14-windows.zip
  - libevent-2.0.22-stable.tar.gz
  - freetype-2.10.1.tar.gz
  - irrlicht-1.8.4.zip
  - lua-5.3.5.tar.gz
  - sqlite-amalgamation-3310100.zip
