sudo: required
dist: xenial
language: haxe

env:
  global:
    # deploy_key_decrypt
    - secure: "cWYcbB7z97sW4yZtz9qcYrEhFZktNjQMOraPm7Vy0FsCMqb4r314Fk8rJze+yDbOKGdsIz6VNHE8nlsQN3EgGiVFJnF8xv6GAlfHPuaVomP2vO7W0A+l7xVy2/326MQJP8JoMgdebDi71yxKeEhYA+mVliI9qql9yfD2YOBmilQ="

.before_install: &before_install
  # https://github.com/travis-ci/travis-ci/issues/7008
  - sudo /etc/init.d/mysql stop || true

matrix:
  include:
    # haxe development
    - os: linux
      haxe: development
      env:
        - USE_DOCKER=1
      services: [docker]
      before_install: *before_install
    # haxe 3.4.4
    - os: linux
      haxe: 3.4.4
      env:
        - USE_DOCKER=1
        - DEPLOY=1
      services: [docker]
      before_install: *before_install
    # haxe 3.2.1
    - os: linux
      haxe: 3.2.1
      env:
        - USE_DOCKER=1
      services: [docker]
      before_install: *before_install
    # haxe 3.1.3
    - os: linux
      haxe: 3.1.3
      env:
        - USE_DOCKER=1
      services: [docker]
      before_install: *before_install
    # Mac
    - os: osx
      haxe: development
    - os: osx
      haxe: 3.4.4
    - os: osx
      haxe: 3.2.1
    - os: osx
      haxe: 3.1.3

install:
  - if [ "${TRAVIS_OS_NAME}" = "osx" ]; then
      brew update;
    fi
  - neko run.n setup haxelib_global
  - haxe libs.hxml
  # copy aws.ndll to the right place
  - if [ "${TRAVIS_OS_NAME}" = "osx" ]; then
      sudo cp $(neko run.n config)/aws-sdk-neko/*/ndll/Mac64/aws.ndll ${NEKOPATH}/aws.ndll;
    fi;
  - if [ "${TRAVIS_OS_NAME}" = "linux" ]; then
      sudo cp $(neko run.n config)/aws-sdk-neko/*/ndll/Linux64/aws.ndll ${NEKOPATH}/aws.ndll;
    fi;
  - neko run.n list
  - neko run.n version
  - neko run.n run tora > ~/tora.log 2>&1 &

script:
  # run our CI script
  - haxe ci.hxml || (echo "[BUILD FAILED]" && echo "Tora log:" && cat ~/tora.log && false)

deploy:
  skip_cleanup: true
  provider: elasticbeanstalk
  access_key_id: $AWS_ACCESS_KEY
  secret_access_key: $AWS_SECRET_KEY
  region: $AWS_REGION
  app: $EB_APP
  env: ${TRAVIS_BRANCH}-lib-haxe-org
  bucket_name: $EB_BUCKET
  zip_file: eb.zip
  on:
    all_branches: true
    condition: $AWS_ACCESS_KEY && $DEPLOY && ($TRAVIS_BRANCH = master || $TRAVIS_BRANCH = development)
