language: scala

# Only build non-pushes (so PRs, API requests & cron jobs) OR tags OR forks OR main branch builds
# https://docs.travis-ci.com/user/conditional-builds-stages-jobs/
if: type != push OR tag IS present OR repo != playframework/playframework OR branch IN (master, 2.7.x, 2.6.x)

addons:
  apt:
    packages:
      # Install xmllint used to get Akka HTTP version
      - libxml2-utils

env:
  global:
    - secure: "NS2hMbBcmi6EF4QxtcNs4A2ZuNmIdLYQRJUWWejgnD4YtcsmoVjxrHRedqrnDdui4DyvaxWhg/3Uds23jEKTSbbh3ZphLO77BVgM2nUGUvVoa4i6qGF2eZFlIhq2G1gM700GPV7X4KmyjYi2HtH8CWBTkqP3g0An63mCZw/Gnlk="
  matrix:
    - TRAVIS_JDK=8

before_install:
  - curl --version # for debug purpose
  - if [ ! -f ~/.jabba/jabba.sh ]; then curl -L -v --retry 5 -o jabba-install.sh https://git.io/jabba && bash jabba-install.sh; fi
  - . ~/.jabba/jabba.sh 
install: jabba install $(jabba ls-remote "adopt@~1.$TRAVIS_JDK.0-0" --latest=patch) && jabba use "$_" && java -Xmx32m -version

stages:
  - validations
  - test
  - test-sbt
  - java11

jobs:
  include:
    - stage: validations
      script: scripts/validate-code
      name: "Code validations (format, binary compatibilty, whitesource, etc.)"
    - script: scripts/validate-docs
      name: "Validate docs (links, sample code, etc.)"
    - script: scripts/validate-microbenchmarks
      name: "Validate that microbenchmarks are runnable"
    - script: scripts/publish-local
      name: "Run a publishLocal for the default scala version"

    - stage: test
      script: scripts/test-scala-211
      name: "Run tests for Scala 2.11"
    - script: scripts/test-scala-212
      name: "Run tests for Scala 2.12"
    - script: scripts/test-scala-213
      name: "Run tests for Scala 2.13"
    - script: scripts/test-docs
      name: "Run documentation tests"
    - script: scripts/it-test-scala-212
      name: "Run it tests for Scala 2.12"
    - script: scripts/it-test-scala-213
      name: "Run it tests for Scala 2.13"

    - stage: test-sbt
      script: scripts/test-sbt-plugins-0_13
      name: "Scripted tests for sbt 0.13"
    - script: scripts/test-sbt-plugins-1_0
      name: "Scripted tests for sbt 1"

    # Test against Java 11, but only for Scala 2.12
    - stage: java11
      script: scripts/test-scala-212
      env: TRAVIS_JDK=11
      name: "Run tests for Scala 2.12 and Java 11"
    - script: scripts/it-test-scala-212
      env: TRAVIS_JDK=11
      name: "Run it tests for Scala 2.12 and Java 11"
    - script: scripts/test-sbt-plugins-1_0
      env: TRAVIS_JDK=11
      name: "Scripted tests for sbt 1 and Java 11"

cache:
  directories:
    - "$HOME/.coursier/cache"
    - "$HOME/.ivy2/cache"
    - "$HOME/.jabba"
    - "$HOME/.sbt"

before_cache:
  - rm -rf $HOME/.ivy2/local
  - rm -rf $HOME/.ivy2/cache/com.typesafe.play/*
  - rm -rf $HOME/.ivy2/cache/scala_*/sbt_*/com.typesafe.play/*
  - find $HOME/.ivy2 -name "ivydata-*.properties" -delete
  - find $HOME/.sbt  -name "*.lock"               -delete

notifications:
  email:
    recipients:
      secure: gxDYtOlihOtFCVxfwjoqRfOJly7EjvUB9KyP4Vz/QyaLVFOKEBQj2z64CaWwsog9g4cb7cWzjofftDhDY/8r16OnG9k3K5OTO4jzD+6N6a2bAFvTjCOrFX/GIPU0hle2Jr0Y7+t1NtkCPlcSDCQ2RyQX4izhyJoL1kOgrUQlutM=
    on_failure: always  
    on_success: never
  webhooks:
    urls:
    - https://webhooks.gitter.im/e/d2c8a242a2615f659595
    on_success: always
    on_failure: always
  slack:
    secure: bMaBU2Az2YK0rVx95luyOikXqB/C5khfvuVI03muOGFfdiEEBEZYoqiCtB7OisveBU/orQCrjZJRL9+vCsEwVvIFF1eIa66ZE8wOTOGNMdv8hetdfR6dg2+RLrnE0zltVhlG2XMFK7X743utmE8e3koMWYH8uQSTQCXdOoUJwpQ=
    on_success: never
    on_failure: always
