language: cpp

matrix:
  fast_finish: true
  include:
    - os: linux
      sudo: required
      dist: trusty
      env: QT=true
      group: edge
    - os: linux
      sudo: required
      dist: trusty
      env: QT=false
      group: edge
    - os: osx
      osx_image: xcode8.3
      env: QT=true

# use ccache to speed up build times. on osx,
# we install it during the the before_install step
# with xcode, this requires an additional flag passed during the configuration phase.
# see README_MACOS.md for details.
cache:
 - ccache

before_install:
 - $TRAVIS_BUILD_DIR/.travis/before-install-$TRAVIS_OS_NAME.sh --qt=$QT

before_script:
 - mkdir BUILD && cd BUILD

 - $TRAVIS_BUILD_DIR/.travis/before-script-$TRAVIS_OS_NAME.sh --qt=$QT
# prep for testing
 - if [[ $QT == true ]]; then $TRAVIS_BUILD_DIR/.travis/qpm-prep.sh; fi

script:
 - $TRAVIS_BUILD_DIR/.travis/script-$TRAVIS_OS_NAME.sh
 - $TRAVIS_BUILD_DIR/.travis/test.sh
 - if [[ $TRAVIS_OS_NAME == osx ]]; then $TRAVIS_BUILD_DIR/.travis/package-osx.sh; fi

before_deploy:
 # required for github releases
 - git fetch --tags
 - export BUILD_PREFIX=$TRAVIS_REPO_SLUG/$TRAVIS_OS_NAME
 - export S3_BUILDS_LOCATION=builds/$BUILD_PREFIX
 - export S3_URL=https://supercollider.s3.amazonaws.com/$S3_BUILDS_LOCATION/SC-$TRAVIS_COMMIT.zip
 - export FWD_HTML='<html><head><meta http-equiv="refresh" content="0; url='$S3_URL'" /></head></html>'
 # put everything to be archived in artifacts/
 - mkdir -p "$HOME/artifacts/${TRAVIS_BRANCH%/*}"
 - mkdir -p "$HOME/artifacts/${TRAVIS_TAG%/*}"
 - echo $FWD_HTML > $HOME/artifacts/$TRAVIS_BRANCH-latest.html
 - 'if [[ $TRAVIS_TAG != "head" ]]; then echo $FWD_HTML > $HOME/artifacts/$TRAVIS_TAG.html; fi;'

deploy:
 # s3 upload - every commit
 - provider: s3
   access_key_id: $AWS_KEY
   secret_access_key: $AWS_SECRET
   bucket: supercollider
   local-dir: $HOME/artifacts
   upload-dir: $S3_BUILDS_LOCATION
   region: us-west-2
   skip_cleanup: true
   endpoint: s3-us-west-2.amazonaws.com
   acl: public_read
   on:
     condition: $TRAVIS_OS_NAME = osx && ! -z $AWS_KEY && ! -z $AWS_SECRET
     all_branches: true
 # github releases - only tags
 - provider: releases
   api_key: $GITHUB_KEY
   file: $HOME/artifacts/SC-$TRAVIS_COMMIT.zip
   prerelease: true
   skip_cleanup: true
   on:
     condition: $TRAVIS_OS_NAME = osx && ! -z $GITHUB_KEY
     tags: true
     all_branches: true

after_deploy:
 - "echo S3 Build Location: $S3_URL"

notifications:
  on_success: change
  on_failure: change
  webhooks:
    urls:
      - https://webhooks.gitter.im/e/51b9b53ca50a7bfca97d
    on_success: change
    on_failure: always
