language: cpp
os:
- linux
- osx
env:
  matrix:
  - locale: zh-CN
  - locale: en-US
  global:
  - USE_IRRKLANG: 1
sudo: required
dist: xenial
osx_image: xcode8
git:
  submodules: false
addons:
  ssh_known_hosts:
  - github.com
  apt:
    # sources:
    #   - ubuntu-toolchain-r-test
    packages:
      # - gcc-6
      # - g++-6
      - libfreetype6-dev
      - libevent-dev
      - libsqlite3-dev
      - libirrlicht-dev
      - libgl1-mesa-dev
      - libglu-dev
#  homebrew:
#    packages:
#      - freetype
#      - libevent
#      - sqlite
#      - lua
#      - dylibbundler
before_install:
- git submodule update --init --recursive
# - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo ln -s /usr/bin/gcc-6 /usr/local/bin/gcc; sudo ln -s /usr/bin/g++-6 /usr/local/bin/g++; fi
#  ls /usr/local/include ; sudo mv /usr/local/include /usr/local/include-bak; sudo mkdir /usr/local/include; chmod u+w /usr/local/include;
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; brew install freetype libevent sqlite lua dylibbundler; fi
#  ls /usr/local/include;
#  sudo rm -rf /usr/local/include/unistring;
#  sudo rm -rf /usr/local/include/lzma;
#  sudo rm -f /usr/local/include/CGAL/stddef.h; fi
#- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then curl --retry 5 --connect-timeout 30 --location --remote-header-name --remote-name http://downloads.sourceforge.net/irrlicht/irrlicht-1.8.4.zip; unzip irrlicht-1.8.4.zip ; cd irrlicht-1.8.4/ ; cp ../premake/irrlicht/irrlicht-mac.patch . ; patch -p1 < irrlicht-mac.patch ; cd source/Irrlicht/MacOSX/ ; xcodebuild -project MacOSX.xcodeproj ; cp build/Release/libIrrlicht.a /usr/local/lib/ ;  cp -r ../../../include /usr/local/include/irrlicht ; cd ../../../../ ; fi

- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then mkdir irrlicht ; cd irrlicht ; curl --retry 5 --location https://github.com/moecube/irrlicht/releases/download/test/irrlicht-mycard-mac.tar.gz | tar zfx - ; cp libIrrlicht.a /usr/local/lib/ ; sudo cp -r include /usr/local/include/irrlicht ; cd .. ; fi

# - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then curl --retry 5 --location https://www.lua.org/ftp/lua-5.3.5.tar.gz | tar zfx -; cd lua-5.3.5; sudo make linux install; cd .. ; fi

- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then curl --retry 5 --location https://github.com/premake/premake-core/releases/download/v5.0.0-alpha12/premake-5.0.0-alpha12-macosx.tar.gz | tar zfx -; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then curl --retry 5 --location https://github.com/premake/premake-core/releases/download/v5.0.0-alpha12/premake-5.0.0-alpha12-linux.tar.gz | tar zfx - ; fi

- git clone --depth=1 https://$IRRKLANG_ACCESS_KEY@github.com/purerosefallen/irrklang
- mv -f irrklang/plugins/ikpmp3 .
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then sudo cp -rf irrklang/bin/macosx-gcc/libirrklang.dylib /usr/local/lib/; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then cp -rf irrklang/bin/linux-gcc-64/libIrrKlang.so .; fi

script:
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then ./premake5 gmake --cc=clang; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then ./premake5 gmake; fi
- cd build
- make config=release ygopro
- cd ..
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then mv bin/release/ygopro ./; strip ygopro;
  fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
    mkdir -p ygopro.app/Contents/MacOS;
    mv bin/release/ygopro ygopro.app/Contents/MacOS;
    dylibbundler -x ygopro.app/Contents/MacOS/ygopro -b -d ygopro.app/Contents/Frameworks/ -p @executable_path/../Frameworks/ -cd;
    strip ygopro.app/Contents/MacOS/ygopro; mkdir ygopro.app/Contents/Resources;
    mv premake/gframe/ygopro.icns ygopro.app/Contents/Resources/Icon.icns;
    defaults write "$PWD/ygopro.app/Contents/Info.plist" "CFBundleIconFile" "Icon.icns";
    defaults write "$PWD/ygopro.app/Contents/Info.plist" "CFBundleIdentifier" "moe.mycard.ygopro";
    if [[ "$TRAVIS_PULL_REQUEST" == "false" ]]; then
      echo $CERTIFICATE | base64 --decode --output cert.p12;
      security create-keychain -p "" build.keychain; security unlock-keychain -p "" build.keychain;
      security import cert.p12 -k build.keychain -P "$CERTIFICATE_PASSWORD" -T /usr/bin/codesign;
      codesign --deep --keychain build.keychain --sign "$(security find-identity -v -p
      codesigning build.keychain | head -1 | grep -o '".*"' | tr -d '"')" ygopro.app;
    fi
  fi
before_deploy:
- 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/zh99998/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/* .
- 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 .
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then tar -zcf ygopro-$TRAVIS_TAG-$TRAVIS_OS_NAME-${locale}.tar.gz
  --format=posix --exclude='.git*' ygopro.app LICENSE README.md lflist.conf strings.conf
  system.conf cards.cdb script textures deck single pics replay sound; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then tar -zcf ygopro-$TRAVIS_TAG-$TRAVIS_OS_NAME-${locale}.tar.gz
  --format=posix --exclude='.git*' ygopro LICENSE README.md libIrrKlang.so lflist.conf strings.conf
  system.conf cards.cdb script textures deck single pics replay sound; fi
deploy:
  provider: releases
  file:
  - ygopro-$TRAVIS_TAG-$TRAVIS_OS_NAME-${locale}.tar.gz
  skip_cleanup: true
  on:
    tags: true
  api-key:
    secure: j7YxYAyoQr1albVJIypwloeJXtZMj11FtqmCDyJ8QGiFk2431o0KMNvN1tC2pK/x08ntN5iVzwEfWh7owDSBeu1HDJo7H7w69s5Rt3UfJE4bw5G2RM6PhG8ZQBwIPkXyXULPTjj3YQRFvcPdBusndQVPhFe/staGLa/t+KOzMyw=
branches:
  only:
  - master
  - /\d+\..+/
