sudo: false
dist: xenial

branches:
  only:
    - master
    - /^v\d+\.\d+\.\d+(-alpha\.\d+)?$/

compiler: clang
language: node_js

# Stage order; the default stage is "test", which in our case is actually building and deploying
stages:
  - "Extended testing"
  - test
  - "Deploy documentation"

env:
  - TARGET_ARCH="x64"
  - TARGET_ARCH="ia32"

node_js:
  - "12"
  - "10"
  - "8"

os:
  - linux
  - osx

jobs:
  exclude:
    - os: osx
      env: TARGET_ARCH="ia32"
  include:
    - stage: "Extended testing"
      os: linux
      dist: xenial
      node_js: "8"
      env: TARGET_ARCH="x64" EXTENDED_TESTING="false" SKIP_DEPLOY="true"
    - stage: "Deploy documentation"
      os: linux
      dist: xenial
      node_js: "8"
      env: TARGET_ARCH="x64" DEPLOY_DOCUMENTATION="true"


git:
  depth: 5

addons:
  apt:
    sources:
      - ubuntu-toolchain-r-test
    packages:
      - build-essential
      - libssl-dev
      - gcc-4.9-multilib
      - g++-4.9-multilib
      - lcov

before_install:
  - export CC=clang
  - export CXX=clang++
  - export npm_config_clang=1
  - export JOBS=4

  - if [ -z "$TRAVIS_TAG" ] && [ "$EXTENDED_TESTING" == "true" ]; then
      export GYP_DEFINES="coverage=1 use_obsolete_asm=true";
      export CC=/usr/bin/gcc-4.9;
      export CXX=/usr/bin/g++-4.9;
      export npm_config_clang=0;
      wget http://downloads.sourceforge.net/ltp/lcov-1.10.tar.gz;
      tar xvfz lcov-1.10.tar.gz;
    else
      export GYP_DEFINES="use_obsolete_asm=true";
    fi

install:
  - set -e;
  - travis_retry npm install;

# This is a random private key used purely for testing.
before_script:
  - echo -e "Host *\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
  - echo -e "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDBkHMoNRRkHYNE7EnQLdFxMgVcqGgNPYDhrWiLMlYuzpmEcUnhwW3zNaIa4J2JlGkRNgYZVia1Ic1V3koJPE3YO2+exAfJBIPeb6O1qDADc2hFFHzd28wmHKUkO61yzo2ZjDQfaEVtjN39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iMLeJuJcT/Jj0xmEUopHonGqEIcvg\nHg6cafE1is7d+l669bfjitlx+3muF2CYnylSN1LWHxIITVUj3BmcWqUCgYEAwZ45\nWdaHfK7G6GjI7liDQT4ZlslA8dmLv2Jl2ExBBMoY3m3Sre428z2ZFa4O/nsBYP0a\nDxgYmX20fQGcbPugKdCYHc7HkKbMU1GwiVCGpDYZCm2gJKTvam3dYNaiAfq5DyhP\nzDCZNJ5rrSMprXsuRv2O4c5u8qtJ5ByaOJBjOr0CgYBMlkAxzkpUssS5CaaZDiLv\nLbfEr3HRLjYdc5KpzLBQ8NpJzhmfiIJsK1Wf8B0qb2J1XJg2Oy0KwFOgPbWIoryY\nSg19Pq98Cdn1UWCOrSabr8ZIaKe55WTgGcc8/O3k6BsNfaO9PJZfSssNUlCCtml1\n18u+uo9RJPhPDBd7Gj7r8QKBgFraxWy7t24xkZMDgK4fiM/3tQhFvhz/CY2wPbxG\n5Ae8UfkmLcOCUfTIReqfd9fAnsAFZNIKa5izHRu/wsh9NwYIJSlvm8PsEVtTrPRy\nfgvWet+i24/2eYZGsag8b19gaLCNKQzXDT1czYg8RNVsRSX427BoLzXeXNkW9uNu\nFbI9AoGAV2kxcdcKS4BtNHKPeGgV87dM0DWhQaAtEXEIcQquFtba0lAXioGHg8U4\nzeiugl4Qzchwk5qd3wnZ4SOhx0s16/5gQDlnkbjFR6EREUnvLRwV92zBXUTOGIkh\nZ7Z4rcgUKlVAaHT3OHN/lTyqJG/ib+K4wZhbztl/ox+JUFsvD98=\n-----END RSA PRIVATE KEY-----" > ~/.ssh/id_rsa
  - chmod 600 ~/.ssh/id_rsa*
  - eval `ssh-agent -s`
  - ssh-add ~/.ssh/id_rsa
  - git config --global user.name "John Doe"
  - git config --global user.email johndoe@example.com

script:
    if [ -z "$TRAVIS_TAG" ] && [ "$EXTENDED_TESTING" == "true" ]; then
      travis_retry npm test && npm run cov && npm run coveralls;
    else
      travis_retry npm test;
    fi

after_success:
  - if [ -n "$TRAVIS_TAG" ] && [ "$EXTENDED_TESTING" != "true" ] && [ "$DEPLOY_DOCUMENTATION" != "true" ] && [ "$SKIP_DEPLOY" != "true" ]; then
      npm install -g node-pre-gyp;
      npm install -g aws-sdk;
      node lifecycleScripts/clean;
      node-pre-gyp package --target_arch=$TARGET_ARCH;
      node-pre-gyp publish --target_arch=$TARGET_ARCH;
    fi

  - if [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ -n "$TRAVIS_TAG" ] && [ "$DEPLOY_DOCUMENTATION" == "true" ]; then
      .travis/deploy-docs.sh;
    fi

notifications:
  slack:
    secure: KglNSqZiid9YudCwkPFDh+sZfW5BwFlM70y67E4peHwwlbbV1sSBPHcs74ZHP/lqgEZ4hMv4N2NI58oYFD5/1a+tKIQP1TkdIMuq4j2LXheuirA2HDcydOVrsC8kRx5XFGKdVRg/uyX2dlRHcOWFhxrS6yc6IxtxYWlRTD2SmEc=

  webhooks:
    urls:
      - https://webhooks.gitter.im/e/cbafdb27ad32ba746a73
    on_success: always  # options: [always|never|change] default: always
    on_failure: always  # options: [always|never|change] default: always
    on_start: false     # default: false
