# Build and autotest script for PX4 Firmware
# http://travis-ci.org

language: cpp

git:
  depth: 2000
  submodules: false

env:
  global:
    # COVERITY KEY
    - secure: "NyaJoCGjU0Xc90Y6bxVYWLgjrJX5HlZsm/SPxruZ6I7xkGo19fJIFzGegOHQFR32D4AiKjllfjTUNy+ncckWplind0QwxtF4/kxXrz9XBfiby6X8jLYXIekrB6Ay0mBLGbniDdh+lpWtcyop6Dmkt5bdJCJuKY2nv9ENnhhs07M="
    # AWS KEY: $PX4_AWS_KEY
    - secure: "XknnZHWBbpHbN4f3fuAVwUztdLIu8ej4keC3aQSDofo3uw8AFEzojfsQsN9u77ShWSIV4iYJWh9C9ALkCx7TocJ+xYjiboo10YhM9lH/8u+EXjYWG6GHS8ua0wkir+cViSxoLNaMtmcb/rPTicJecAGANxLsIHyBAgTL3fkbLSA="
    # AWS SECRET: $PX4_AWS_SECRET
    - secure: "h6oajlW68dWIr+wZhO58Dv6e68dZHrBLVA6lPXZmheFQBW6Xam1HuLGA0LOW6cL9TnrAsOZ8g4goB58eMQnMEijFZKi3mhRwZhd/Xjq/ZGJOWBUrLoQHZUw2dQk5ja5vmUlKEoQnFZjDuMjx8KfX5ZMNy8A3yssWZtJYHD8c+bk="

matrix:
  fast_finish: true
  include:
    - os: linux
      sudo: required
      services:
        - docker
      env: BUILD_TARGET=check_format
    - os: linux
      sudo: required
      services:
        - docker
      env: BUILD_TARGET=tests
    - os: linux
      sudo: required
      services:
        - docker
      env: BUILD_TARGET=tests_asan
    - os: linux
      sudo: required
      services:
        - docker
      env: BUILD_TARGET=tests_coverage
    - os: linux
      sudo: required
      services:
        - docker
      env: BUILD_TARGET=clang-tidy
    - os: linux
      sudo: required
      services:
        - docker
      env: BUILD_TARGET=scan-build
    - os: linux
      sudo: required
      services:
        - docker
      env: BUILD_TARGET=cppcheck
    - os: linux
      sudo: required
      services:
        - docker
      env: BUILD_TARGET=px4_metadata
    - os: linux
      dist: trusty
      sudo: required
      env: BUILD_TARGET=coverity_scan
  allow_failures:
    - env: BUILD_TARGET=tests_asan
    - env: BUILD_TARGET=tests_coverage

cache:
  ccache: true

before_install:
  # install dependencies for the coverity build (target and branch), otherwise exit early
  - if [[ "${TRAVIS_BRANCH}" = "coverity" ]]; then
      if [[ "${BUILD_TARGET}" = "coverity_scan" ]]; then sudo apt-get install genromfs && pip install empy jinja2; else exit 0; fi;
    fi
  # use git:// to fetch instead of https://
  - git config --global url."git://".insteadOf https://

script:
  - if [[ "${BUILD_TARGET}" = "coverity_scan" ]]; then
      echo "no script for coverity build";

    elif [[ "${TRAVIS_BRANCH}" = "coverity" ]]; then
      echo "exit early for coverity build" && exit 0;

    elif [[ "${BUILD_TARGET}" = "check_format" ]]; then
      ./Tools/docker_run.sh 'make check_format';

    elif [[ "${BUILD_TARGET}" = "tests" ]]; then
      ./Tools/docker_run.sh 'make tests';

    elif [[ "${BUILD_TARGET}" = "tests_coverage" ]]; then
      ./Tools/docker_run.sh 'make tests_coverage' && bash <(curl -s https://codecov.io/bash) -F unittests;

    elif [[ "${BUILD_TARGET}" = "tests_asan" ]]; then
      ./Tools/docker_run.sh 'PX4_ASAN=1 make tests';

    elif [[ "${BUILD_TARGET}" = "px4_metadata" ]]; then
      ./Tools/docker_run.sh 'make px4_metadata';

    elif [[ "${BUILD_TARGET}" = "clang-tidy" ]]; then
      ./Tools/docker_run.sh 'make clang-tidy-quiet';

    fi

after_success:
  # s3 upload airframe and parameter metadata
  - if [[ "${BUILD_TARGET}" = "px4_metadata" && "${TRAVIS_PULL_REQUEST}" = "false" ]]; then
         ./Tools/docker_run.sh 'make s3put_metadata AWS_S3_BUCKET="px4-travis/Firmware/${TRAVIS_BRANCH}"';
    fi
  # s3 upload clang scan-build output for master branch
  - if [[ "${BUILD_TARGET}" = "scan-build" && "${TRAVIS_PULL_REQUEST}" = "false" ]]; then
         ./Tools/docker_run.sh 'make s3put_scan-build AWS_S3_BUCKET="px4-travis/Firmware/${TRAVIS_BRANCH}/scan-build"';
    fi
  # s3 upload cppcheck output for master branch
  - if [[ "${BUILD_TARGET}" = "cppcheck" && "${TRAVIS_PULL_REQUEST}" = "false" ]]; then
         ./Tools/docker_run.sh 'make s3put_cppcheck AWS_S3_BUCKET="px4-travis/Firmware/${TRAVIS_BRANCH}/cppcheck"';
    fi

addons:
  coverity_scan:
    project:
      name: PX4/Firmware
    notification_email: ci@px4.io
    build_command: make posix_sitl_default
    branch_pattern: coverity

notifications:
  webhooks:
    urls:
      - https://webhooks.gitter.im/e/2b9c4a4cb2211f8befba
    on_success: always  # options: [always|never|change] default: always
    on_failure: always  # options: [always|never|change] default: always
  slack:
    rooms:
      - secure: "QKw73Zel/s3JAbe/7XyO9tPnJwiiGFpYzSjdR8lG3tYFjRdXZnhxG4c+G7bkgkaPTS4Hult33VXE3kcEqOI7+C+eRwRlZhDfL0knQbXVCxjcLjzmUFdoPOwurlgZDw66PFWCi5tZcLKSRo3u4U8ibT4WKi3jm9sDSyOcfBAucMU="
    on_pull_requests: false
    on_success: never  # options: [always|never|change] default: always
    on_failure: never  # options: [always|never|change] default: always
