sudo: required
dist: trusty
language: rust

branches:
  only:
  - master
  - /^beta-.*$/
  - /^stable-.*$/
  - /^beta$/
  - /^stable$/

git:
  depth: 3

matrix:
  include:
  - rust: stable
    env: RUN_TESTS="true" TEST_OPTIONS="--no-release"
  - rust: beta
    env: RUN_COVERAGE="true"
  - rust: stable
    env: RUN_DOCS="true"

env:
  global:
  - CXX="g++-4.8"
  - CC="gcc-4.8"
  - RUST_BACKTRACE="1"
  - RUN_TESTS="false"
  - RUN_COVERAGE="false"
  - RUN_DOCS="false"
  - TEST_OPTIONS=""
  - RUSTFLAGS="-D warnings"
  - TRAVIS_NODE_VERSION="6"
  # GH_TOKEN for documentation
  - secure: bumJASbZSU8bxJ0EyPUJmu16AiV9EXOpyOj86Jlq/Ty9CfwGqsSXt96uDyE+OUJf34RUFQMsw0nk37/zC4lcn6kqk2wpuH3N/o85Zo/cVZY/NusBWLQqtT5VbYWsV+u2Ua4Tmmsw8yVYQhYwU2ZOejNpflL+Cs9XGgORp1L+/gMRMC2y5Se6ZhwnKPQlRJ8LGsG1dzjQULxzADIt3/zuspNBS8a2urJwlHfGMkvHDoUWCviP/GXoSqw3TZR7FmKyxE19I8n9+iSvm9+oZZquvcgfUxMHn8Gq/b44UbPvjtFOg2yam4xdWXF/RyWCHdc/R9EHorSABeCbefIsm+zcUF3/YQxwpSxM4IZEeH2rTiC7dcrsKw3XsO16xFQz5YI5Bay+CT/wTdMmJd7DdYz7Dyf+pOvcM9WOf/zorxYWSBOMYy0uzbusU2iyIghQ82s7E/Ahg+WARtPgkuTLSB5aL1oCTBKHqQscMr7lo5Ti6RpWLxEdTQMBznc+bMr+6dEtkEcG9zqc6cE9XX+ox3wTU6+HVMfQ1ltCntJ4UKcw3A6INEbw9wgocQa812CIASQ2fE+SCAbz6JxBjIAlFUnD1lUB7S8PdMPwn9plfQgKQ2A5YZqg6FnBdf0rQXIJYxQWKHXj/rBHSUCT0tHACDlzTA+EwWggvkP5AGIxRxm8jhw=
  - KCOV_CMD="./kcov-master/tmp/usr/local/bin/kcov"

cache:
  apt: true
  directories:
  - $TRAVIS_BUILD_DIR/target
  - $TRAVIS_BUILD_DIR/kcov-master
  - $TRAVIS_BUILD_DIR/js/node_modules
  - $HOME/.cargo

addons:
  apt:
    sources:
    - ubuntu-toolchain-r-test
    packages:
    - libcurl4-openssl-dev
    - libelf-dev
    - libdw-dev
    - gcc-4.8
    - g++-4.8

install:
  - ([ "$RUN_COVERAGE" = "false" ]) || (test -x $KCOV_CMD) || (
      wget https://github.com/SimonKagstrom/kcov/archive/master.tar.gz &&
      tar xzf master.tar.gz &&
      mkdir -p kcov-master/build &&
      cd kcov-master/build &&
      cmake .. &&
      make && make install DESTDIR=../tmp &&
      cd
    )
  - nvm install $TRAVIS_NODE_VERSION && nvm use $TRAVIS_NODE_VERSION && ./js/scripts/install-deps.sh

script:
  - if [ "$RUN_TESTS" = "true" ]; then
      ./js/scripts/lint.sh &&
      ./js/scripts/test.sh &&
      ./test.sh $TEST_OPTIONS --verbose;
    fi
  - if [ "$RUN_COVERAGE" = "true" ]; then ./scripts/cov.sh "$KCOV_CMD"; fi

after_success: |
  [ $TRAVIS_BRANCH = master ] &&
  [ $TRAVIS_PULL_REQUEST = false ] &&
  [ "$RUN_DOCS" = "true" ] &&
  ./scripts/doc.sh &&
  pip install --user ghp-import &&
  /home/travis/.local/bin/ghp-import -n target/doc &&
  git push -fq https://${GH_TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git gh-pages
