language: cpp

compiler:
  - gcc

# Prebuild S3 keys
env:
  global:
    # accessKeyId
    - secure: "gj5FMwUZkSneMLBN68BY3fl/YdBxI5Ou5Ohf0ky+E1tArHhxWP8KWr4FjK+bHaP0l3QJRuqE4DZvIAEnfIt+XIZrvNRzR11o3D+KOyWEJPMQo2xmsFbvM2z4E8lHMAiY1QPYiAgBV1XM61E/EgU0KB0iIxXxuwkp22iy/t8q5Dus4mk4KR2QnpCxhjowGbSkER4QH5BZy+EH3NoVX9y2Q7jJnE+cQKdceVMHu3r/E8cdeFZH/q9dpZmYt/uvQbbtI4cIhPjaEmxYsK5/Vwj/q19OlZvuDN8QWyNP1/QjJx+F1IBSBz4lwreswQLOrnp6aeANiWzNDkz/gfP9KkUBOcq1zqIIdN9jkwHcOMmo/bGnk/WuwUM7FK5x2GacIlfFEXVhEnpRHHdbF8Vnt+geTiGl6dAaYjEBCqXUCFNpZ5+YFX6RC1oOw6Z1bcDks6SJYznxjEEn14w8d0bAL0eqms//CChSEmL/77aWAAGcd+Nz+iQMkFWIgbIOo9pOZU4W3WVqVbbYiILkcvs53c9r6lY0EIPRX1YY2VrYLmkE87CHg7eZCCmrGrsHMySS96F7phv7fQwFPsVE+NDNnI8E1jFxsrY5m5TmGBmt4Tm10DvvgxgtaUguGuKDY2uEZr8LF5u7oWXmg+vAusMpZnjCsgO4udMhTwnoHdNvH0Fxm7Q="
    # secretKey
    - secure: "fDjbyxQSzAIuNbCzPfsmx5Qt96w5FCj+Gft8qatXsSxch7EegCgqBsv58GnrhMFxTrN7zmBCQ0LH9BUCNcafjR2mMa5WFWNHqmaW1bOZk8jBTphV68bhtSfVGnHYNmsK+ah3eQoRwrdygsPUOhc1+2FWxCdrC1xluhP0ybBMGcl/HBCbfzElFSca8NueJx3GXsMWjmqr3hhDGY8UExnPa5IjXEstdCPmWxmrrpftVxtqrUVsD+VLPdS0Fvd48ysZGm6mJ+L4ck/6S2HYDR1LImlVfUrRqxVi+yislvHuMrqKazjdubMnuGpo3tESciocRMKhNicumH4HpHqKZoS1dpinP4FoETjo4+LveRQRA0ex1/ihyCQPTH3t9iJN8oN9Z02/jFPJIXZAzzImTCizZp7lyKwBUiCCOfJkXy5qbMlriQIXuf59rU/pDR4yu9YAzJcobhdqPyz0ukWLabfqzsjW2DVtWptjSr397TCb6w+oPjjH2PofWiuFz1CmpzBK4liMTyFRi5bwbnL0JYrJs84meyL/FlSgi0Ez14f303avQYVIj0L9Pmb9WUt4i+clojeCMJSun0W27DNSd6qVX8LKf5lR3sq9M3jmZrW7Imy1dgOvC9Dju/UN2vjbE3SNzzIB7E6meda3PMTHVq9Rub+DngH2GHET1V8oqoIlFqk="

addons:
  apt:
    sources:
    - ubuntu-toolchain-r-test
    packages:
    - g++-6
    - libc6-dev # for libiconv which is needed by libgdal

matrix:
  include:
    # OSX
    - os: osx
      env: NODE_NVM_VERSION="15" TARGET=STATIC
    - os: osx
      env: NODE_NVM_VERSION="15" TARGET=SHARED
    - os: osx
      env: NODE_NVM_VERSION="15" TARGET=TRUNK
    - os: osx
      env: NODE_NVM_VERSION="14" TARGET=STATIC
    - os: osx
      env: NODE_NVM_VERSION="14" TARGET=SHARED
    - os: osx
      env: NODE_NVM_VERSION="14" TARGET=TRUNK
    - os: osx
      env: NODE_NVM_VERSION="13" TARGET=STATIC
    - os: osx
      env: NODE_NVM_VERSION="13" TARGET=SHARED
    - os: osx
      env: NODE_NVM_VERSION="13" TARGET=TRUNK
    - os: osx
      env: NODE_NVM_VERSION="12" TARGET=STATIC
    - os: osx
      env: NODE_NVM_VERSION="12" TARGET=SHARED
    - os: osx
      env: NODE_NVM_VERSION="12" TARGET=TRUNK
    - os: osx
      env: NODE_NVM_VERSION="11" TARGET=STATIC
    - os: osx
      env: NODE_NVM_VERSION="11" TARGET=SHARED
    - os: osx
      env: NODE_NVM_VERSION="11" TARGET=TRUNK
    - os: osx
      env: NODE_NVM_VERSION="10" TARGET=STATIC
    - os: osx
      env: NODE_NVM_VERSION="10" TARGET=SHARED
    - os: osx
      env: NODE_NVM_VERSION="10" TARGET=TRUNK

    # Linux
    - os: linux
      env: NODE_NVM_VERSION="15" TARGET=STATIC
    - os: linux
      env: NODE_NVM_VERSION="15" TARGET=SHARED
    - os: linux
      env: NODE_NVM_VERSION="15" TARGET=TRUNK
    - os: linux
      env: NODE_NVM_VERSION="14" TARGET=STATIC
    - os: linux
      env: NODE_NVM_VERSION="14" TARGET=SHARED
    - os: linux
      env: NODE_NVM_VERSION="14" TARGET=TRUNK
    - os: linux
      env: NODE_NVM_VERSION="13" TARGET=STATIC
    - os: linux
      env: NODE_NVM_VERSION="13" TARGET=SHARED
    - os: linux
      env: NODE_NVM_VERSION="13" TARGET=TRUNK
    - os: linux
      env: NODE_NVM_VERSION="12" TARGET=STATIC
    - os: linux
      env: NODE_NVM_VERSION="12" TARGET=SHARED
    - os: linux
      env: NODE_NVM_VERSION="12" TARGET=TRUNK
    - os: linux
      env: NODE_NVM_VERSION="11" TARGET=STATIC
    - os: linux
      env: NODE_NVM_VERSION="11" TARGET=SHARED
    - os: linux
      env: NODE_NVM_VERSION="11" TARGET=TRUNK
    - os: linux
      env: NODE_NVM_VERSION="10" TARGET=STATIC
    - os: linux
      env: NODE_NVM_VERSION="10" TARGET=SHARED
    - os: linux
      env: NODE_NVM_VERSION="10" TARGET=TRUNK

  allow_failures:
    - env: NODE_NVM_VERSION="15" TARGET=TRUNK
    - env: NODE_NVM_VERSION="14" TARGET=TRUNK
    - env: NODE_NVM_VERSION="13" TARGET=TRUNK
    - env: NODE_NVM_VERSION="12" TARGET=TRUNK
    - env: NODE_NVM_VERSION="11" TARGET=TRUNK
    - env: NODE_NVM_VERSION="10" TARGET=TRUNK

before_install:
  - if [[ $TRAVIS_OS_NAME == "linux" ]]; then export CXX=g++-6 CXXFLAGS=-std=c++11 CC=gcc-6; fi
  - COMMIT_MESSAGE=$(git show -s --format=%B $TRAVIS_COMMIT | tr -d '\n')
  - PUBLISH_BINARY=false
  - if test "${COMMIT_MESSAGE#*'[publish binary]'}" != "$COMMIT_MESSAGE" && test "${TRAVIS_BRANCH}" == "master" && test "${TRAVIS_PULL_REQUEST}" == "false"; then PUBLISH_BINARY=true; fi;
  - REPUBLISH_BINARY=false
  - if test "${COMMIT_MESSAGE#*'[republish binary]'}" != "$COMMIT_MESSAGE" && test "${TRAVIS_BRANCH}" == "master" && test "${TRAVIS_PULL_REQUEST}" == "false"; then REPUBLISH_BINARY=true; fi;
  - git clone https://github.com/creationix/nvm.git ../.nvm && source ../.nvm/nvm.sh
  - nvm install $NODE_NVM_VERSION
  - nvm use $NODE_NVM_VERSION
  - node --version
  - npm --version
  - $CXX --version
  - NPM_CACHE=$(npm config get cache)
  - echo $NPM_CACHE
  - if [ -d $NPM_CACHE ]; then sudo chown -R $USER $NPM_CACHE; fi;

install:
  - if [[ "${TARGET}" == "TRUNK" ]]; then ./scripts/gdal-trunk.sh; fi;
  - if [[ "${TARGET}" == "SHARED" && "$(uname -s)" == "Linux" ]]; then sudo apt-get -qq update; sudo apt-get --force-yes -qq install libgdal-dev libc6-dev; fi;
  - if [[ "${TARGET}" == "SHARED" || "${TARGET}" == "TRUNK" ]]; then npm install --build-from-source --shared_gdal; fi;
  - if [[ "${TARGET}" == "SHARED" || "${TARGET}" == "TRUNK" ]]; then gdal-config --version --version; fi;
  - if [[ "${TARGET}" == "STATIC" ]]; then npm install --build-from-source > /dev/null; fi;
  - npm test

script:
  - ./node_modules/.bin/node-pre-gyp package testpackage
  - npm test
  - if [[ "${TARGET}" == "STATIC" && "${PUBLISH_BINARY}" == "true" ]]; then ./node_modules/.bin/node-pre-gyp publish; rm -rf {build,lib/binding}; ./node_modules/.bin/node-pre-gyp install --fallback-to-build=false; npm test; fi
  - if [[ "${TARGET}" == "STATIC" && "${REPUBLISH_BINARY}" == "true" ]]; then ./node_modules/.bin/node-pre-gyp unpublish publish; rm -rf {build,lib/binding}; ./node_modules/.bin/node-pre-gyp install --fallback-to-build=false; npm test; fi
