branches:
  only:
    - "master"
    
dist: trusty
sudo: false

language: generic

before_install:
  - echo "Installing $ENGINE $ENGINE_VERSION from $ENGINE_ARCHIVE_URL"
  - if [[ $ENGINE_ARCHIVE_URL == *.tar.bz2 ]]; then
      wget $ENGINE_ARCHIVE_URL --output-document=engine.tar.bz2;
      bunzip2 engine.tar.bz2;
    elif [[ $ENGINE_ARCHIVE_URL == *.tar.gz ]]; then
      wget $ENGINE_ARCHIVE_URL --output-document=engine.tar.gz;
      gunzip engine.tar.gz;
    elif [[ $ENGINE_ARCHIVE_URL == *.zip ]]; then
      wget $ENGINE_ARCHIVE_URL --output-document=engine.zip;
    else
      echo "Unsupported compression type for url $ENGINE_ARCHIVE_URL";
    fi
  - if [[ $ENGINE_ARCHIVE_URL == *.tar.* ]]; then
      mkdir engine;
      tar --strip-components=1 -xvf engine.tar -C engine;
    else
      export ENGINE_NAME="$CASPERJS_ENGINE-$ENGINE_VERSION";
      unzip engine.zip && mv $ENGINE_NAME engine;
    fi
  - if [[ $CASPERJS_ENGINE == 'phantomjs' ]]; then
      export ENGINE_EXECUTABLE="engine/bin/phantomjs";
    elif [[ $CASPERJS_ENGINE == 'slimerjs' ]]; then
      export ENGINE_EXECUTABLE="engine/slimerjs";
    else
      echo "Unsupported engine $CASPERJS_ENGINE";
    fi
  - ls -la $ENGINE_EXECUTABLE && $ENGINE_EXECUTABLE --version;

apt_targets:
  - &apt_cs [mono-devel, mono-mcs]

before_script:
  - "npm install -g eslint@v1.10.1"

script:
  - if [ "$ENGINE_XVFB" == "1" ]; then
      xvfb-run -a make "$MAKE_TEST_COMMAND";
    else
      make "$MAKE_TEST_COMMAND";
    fi

env:
  global:
    - ENGINE_FLAGS="--local-to-remote-url-access=yes --ignore-ssl-errors=yes"

matrix:
  include:
    - env: >
        CASPERJS_ENGINE="phantomjs" ENGINE_VERSION="1.9.1" MAKE_TEST_COMMAND="test-dotNET"
        ENGINE_ARCHIVE_URL="https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/phantomjs/phantomjs-1.9.1-linux-x86_64.tar.bz2"
      os: linux
      addons: {apt: {packages: *apt_cs}}
    - env: >
        CASPERJS_ENGINE="phantomjs" ENGINE_VERSION="1.9.1" MAKE_TEST_COMMAND="test"
        ENGINE_ARCHIVE_URL="https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/phantomjs/phantomjs-1.9.1-linux-x86_64.tar.bz2"
      os: linux
    - env: >
        CASPERJS_ENGINE="phantomjs" ENGINE_VERSION="1.9.2" MAKE_TEST_COMMAND="test-dotNET"
        ENGINE_ARCHIVE_URL="https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/phantomjs/phantomjs-1.9.2-linux-x86_64.tar.bz2"
      os: linux
      addons: {apt: {packages: *apt_cs}}
    - env: >
        CASPERJS_ENGINE="phantomjs" ENGINE_VERSION="1.9.2" MAKE_TEST_COMMAND="test"
        ENGINE_ARCHIVE_URL="https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/phantomjs/phantomjs-1.9.2-linux-x86_64.tar.bz2"
      os: linux
    - env: >
        CASPERJS_ENGINE="phantomjs" ENGINE_VERSION="1.9.7" MAKE_TEST_COMMAND="test-dotNET"
        ENGINE_ARCHIVE_URL="https://github.com/casperjs/phantomjs-builds/archive/v1.9.7.tar.gz"
      os: linux
      addons: {apt: {packages: *apt_cs}}
    - env: >
        CASPERJS_ENGINE="phantomjs" ENGINE_VERSION="1.9.7" MAKE_TEST_COMMAND="test"
        ENGINE_ARCHIVE_URL="https://github.com/casperjs/phantomjs-builds/archive/v1.9.7.tar.gz"
      os: linux
    - env: >
        CASPERJS_ENGINE="phantomjs" ENGINE_VERSION="1.9.8" MAKE_TEST_COMMAND="test-dotNET"
        ENGINE_ARCHIVE_URL="https://github.com/casperjs/phantomjs-builds/archive/v1.9.8.tar.gz"
      os: linux
      addons: {apt: {packages: *apt_cs}}
    - env: >
        CASPERJS_ENGINE="phantomjs" ENGINE_VERSION="1.9.8" MAKE_TEST_COMMAND="test"
        ENGINE_ARCHIVE_URL="https://github.com/casperjs/phantomjs-builds/archive/v1.9.8.tar.gz"
      os: linux
    # NOTE: a pre-compiled official 2.0.0 version for linux is not available yet
    # https://bitbucket.org/ariya/phantomjs/downloads
    - env: >
        CASPERJS_ENGINE="phantomjs" ENGINE_VERSION="2.1.1" MAKE_TEST_COMMAND="test"
        ENGINE_ARCHIVE_URL="https://github.com/casperjs/phantomjs-builds/archive/v2.1.1.tar.gz"
      os: linux
    - env: >
        CASPERJS_ENGINE="phantomjs" ENGINE_VERSION="2.1.1" MAKE_TEST_COMMAND="test-dotNET"
        ENGINE_ARCHIVE_URL="https://github.com/casperjs/phantomjs-builds/archive/v2.1.1.tar.gz"
      os: linux
      addons: {apt: {packages: *apt_cs}}
#    - env: >
#        CASPERJS_ENGINE="slimerjs" ENGINE_VERSION="0.8.4" MAKE_TEST_COMMAND="test-dotNET" ENGINE_XVFB="1"
#        ENGINE_ARCHIVE_URL="https://github.com/casperjs/slimerjs-builds/releases/download/v0.8.4/slimerjs-0.8.4-linux-x86_64.tar.bz2"
#      os: linux
#      addons: {apt: {packages: *apt_cs}}
#    - env: >
#        CASPERJS_ENGINE="slimerjs" ENGINE_VERSION="0.8.4" MAKE_TEST_COMMAND="test" ENGINE_XVFB="1"
#        ENGINE_ARCHIVE_URL="https://github.com/casperjs/slimerjs-builds/releases/download/v0.8.4/slimerjs-0.8.4-linux-x86_64.tar.bz2"
#      os: linux
#    - env: >
#        CASPERJS_ENGINE="slimerjs" ENGINE_VERSION="0.8.5" MAKE_TEST_COMMAND="test-dotNET" ENGINE_XVFB="1"
#        ENGINE_ARCHIVE_URL="https://github.com/casperjs/slimerjs-builds/releases/download/v0.8.5/slimerjs-0.8.5-linux-x86_64.tar.bz2"
#      os: linux
#      addons: {apt: {packages: *apt_cs}}
#    - env: >
#        CASPERJS_ENGINE="slimerjs" ENGINE_VERSION="0.8.5" MAKE_TEST_COMMAND="test" ENGINE_XVFB="1"
#        ENGINE_ARCHIVE_URL="https://github.com/casperjs/slimerjs-builds/releases/download/v0.8.5/slimerjs-0.8.5-linux-x86_64.tar.bz2"
#      os: linux
    - env: >
        CASPERJS_ENGINE="slimerjs" ENGINE_VERSION="0.9.5" MAKE_TEST_COMMAND="test-dotNET" ENGINE_XVFB="1"
        ENGINE_ARCHIVE_URL="https://github.com/casperjs/slimerjs-builds/releases/download/v0.9.5/slimerjs-0.9.5-linux-x86_64.tar.bz2"
      os: linux
      addons: {apt: {packages: *apt_cs}}
    - env: >
        CASPERJS_ENGINE="slimerjs" ENGINE_VERSION="0.9.5" MAKE_TEST_COMMAND="test" ENGINE_XVFB="1"
        ENGINE_ARCHIVE_URL="https://github.com/casperjs/slimerjs-builds/releases/download/v0.9.5/slimerjs-0.9.5-linux-x86_64.tar.bz2"
      os: linux
# TODO: slimerjs 0.9.6 coffeescript breaks
#    - CASPERJS_ENGINE="slimerjs" ENGINE_VERSION="0.9.6" MAKE_TEST_COMMAND="test-dotNET" ENGINE_XVFB="1"
#      ENGINE_ARCHIVE_URL="https://github.com/casperjs/slimerjs-builds/releases/download/v0.9.6/slimerjs-0.9.6-linux-x86_64.tar.bz2"
#      os: linux
#      addons: {apt: {packages: *apt_cs}}
#    - env: >
#        CASPERJS_ENGINE="slimerjs" ENGINE_VERSION="0.9.6" MAKE_TEST_COMMAND="test" ENGINE_XVFB="1"
#        ENGINE_ARCHIVE_URL="https://github.com/casperjs/slimerjs-builds/releases/download/v0.9.6/slimerjs-0.9.6-linux-x86_64.tar.bz2"
#      os: linux
    - env: >
        CASPERJS_ENGINE="slimerjs" ENGINE_VERSION="0.10.0" MAKE_TEST_COMMAND="test" ENGINE_XVFB="1"
        ENGINE_ARCHIVE_URL="https://github.com/casperjs/slimerjs-builds/releases/download/v0.10.0/slimerjs-0.10.0.zip"
      os: linux
      addons: 
         firefox: "45.0"
    - env: >
        CASPERJS_ENGINE="slimerjs" ENGINE_VERSION="0.10.3" MAKE_TEST_COMMAND="test" ENGINE_XVFB="1"
        ENGINE_ARCHIVE_URL="https://github.com/casperjs/slimerjs-builds/releases/download/v0.10.3/slimerjs-0.10.3.zip"
      os: linux
      addons: 
         firefox: "52.0"
    - env: >
        CASPERJS_ENGINE="slimerjs" ENGINE_VERSION="1.0.0" MAKE_TEST_COMMAND="test" ENGINE_XVFB="1"
        ENGINE_ARCHIVE_URL="https://github.com/casperjs/slimerjs-builds/releases/download/v1.0.0/slimerjs-1.0.0.zip"
      os: linux
      addons: 
         firefox: "57.0"
    - env: >
        CASPERJS_ENGINE="slimerjs" ENGINE_VERSION="1.0.0" MAKE_TEST_COMMAND="test-headless"
        ENGINE_ARCHIVE_URL="https://github.com/casperjs/slimerjs-builds/releases/download/v1.0.0/slimerjs-1.0.0.zip"
      os: linux
      addons: 
         firefox: "57.0"         

notifications:
  irc:
    channels:
      - "irc.freenode.org#casperjs"
  slack: casperjs:jwoh8W8mOfMiBtWOHY9utob0
