version: '{build}'
skip_tags: true

environment:
  access_token:
    secure: DOOS4g7CT8ctOgiMr62K56qQ1FO6s2ESpqNZlhf8F4nomemvvwxV/pRj9nbKmtjR

install:
  - 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-alpha12/premake-5.0.0-alpha12-windows.zip ; exit 0"
  - 7z x premake-5.0.0-alpha12-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.8.1.tar.bz2 ; exit 0"
  - tar xf freetype-2.8.1.tar.bz2
  - move freetype-2.8.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.4.tar.gz ; exit 0"
  - tar xf lua-5.3.4.tar.gz
  - move lua-5.3.4\src lua
  
  - bash -c "curl --retry 5 --connect-timeout 30 --location --remote-header-name --remote-name https://www.sqlite.org/2017/sqlite-amalgamation-3210000.zip ; exit 0"
  - 7z x sqlite-amalgamation-3210000.zip
  - move sqlite-amalgamation-3210000 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 vs2015
  
configuration: Release

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

after_build:
  - mv bin\release\ygopro.exe .
  #- mv irrklang\bin\win32-visualStudio\irrKlang.dll .
  #- mv irrklang\bin\win32-visualStudio\ikpMP3.dll .
  - mkdir pics
  - mkdir replay
  - bash -c "curl --retry 5 --connect-timeout 30 --location --remote-header-name --remote-name https://github.com/mycard/ygopro-database/raw/master/locales/zh-CN/cards.cdb ; exit 0"
  - bash -c "curl --retry 5 --connect-timeout 30 --location --remote-header-name --remote-name https://github.com/mycard/ygopro-starter-pack/archive/master.zip ; exit 0"
  - 7z x ygopro-starter-pack-master.zip
  - xcopy /E ygopro-starter-pack-master\* .
  #- 7z a ygopro-ver.233.7z ygopro.exe irrKlang.dll ikpMP3.dll LICENSE README.md lflist.conf strings.conf system.conf cards.cdb script textures deck single pics replay -xr!.git*
  - 7z a ygopro-ver.233.7z ygopro.exe LICENSE README.md lflist.conf strings.conf system.conf cards.cdb script textures deck single pics replay -xr!.git*

  - git config --global credential.helper store
  - ps: Add-Content "$env:USERPROFILE\.git-credentials" "https://$($env:access_token):x-oauth-basic@github.com`n"
  - bash -c "git tag -d latest ; exit 0"
  - git tag latest HEAD
  - git push -f origin latest

test: off

artifacts:
  - path: ygopro.exe
    name: ygopro
  - path: ygopro-ver.233.7z
    name: ygopro-ver.233

deploy:
    release: latest
    description: 'Automatic build by Appveyor.\nUpdated on $(APPVEYOR_REPO_COMMIT_TIMESTAMP).'
    provider: GitHub
    auth_token: $(access_token)
    force_update: true
    on:
        branch: test

cache:
  - premake-5.0.0-alpha12-windows.zip
  - libevent-2.0.22-stable.tar.gz
  - freetype-2.8.1.tar.bz2
  - irrlicht-1.8.4.zip
  - lua-5.3.4.tar.gz
  - sqlite-amalgamation-3210000.zip
  - irrKlang-32bit-1.5.0.zip
