# vim:sw=2:et:

os: linux
dist: xenial
language: elixir
notifications:
  email:
    recipients:
      - alerts@rabbitmq.com
    on_success: never
    on_failure: always
addons:
  apt:
    packages:
      - awscli
cache:
  apt: true
env:
  global:
    - secure: nibXH/qEVpheE1+M5U1cY/rKuv820TxpV/97pstEUDb5Fk5p8s3WZn4kG1BP5jtFozWtsAUNIjGlbJTTaDn4YnIFjxDBoPPO8IbgFWRnukuUd/v6phCunDrBx4u5oDyaNN0VJv5/c2jpl92kYaVs5cEbKTOag67DOy2D7rPWl+E=
    - secure: OhWqYiQ/+X4pQxFDiuh5QRHUhhR9+btzXDc5jjh5LQw9t7KHDiR3k5SrN1/x5Z/sGp1cUKz7tQkz5dkjTRo4wJCEgg3iFaTSGi/5t2n2KlJVJ3sxEs+Q/dCc2VNCx50bjYs64q4BH/sKDEthDp1LXRG7/DcRVfz28t4HJe7/P9I=

    # $base_rmq_ref is used by rabbitmq-components.mk to select the
    # appropriate branch for dependencies.
    - base_rmq_ref=master

elixir:
  - '1.9'
otp_release:
  - '21.3'
  - '22.2'

install:
  # This project being an Erlang one (we just set language to Elixir
  # to ensure it is installed), we don't want Travis to run mix(1)
  # automatically as it will break.
  skip

script:
  # $current_rmq_ref is also used by rabbitmq-components.mk to select
  # the appropriate branch for dependencies.
  - make check-rabbitmq-components.mk
    current_rmq_ref="${TRAVIS_PULL_REQUEST_BRANCH:-${TRAVIS_BRANCH}}"
  - make xref
    current_rmq_ref="${TRAVIS_PULL_REQUEST_BRANCH:-${TRAVIS_BRANCH}}"
  - make tests
    current_rmq_ref="${TRAVIS_PULL_REQUEST_BRANCH:-${TRAVIS_BRANCH}}"

after_failure:
  - |
    cd "$TRAVIS_BUILD_DIR"
    if test -d logs && test "$AWS_ACCESS_KEY_ID" && test "$AWS_SECRET_ACCESS_KEY"; then
      archive_name="$(basename "$TRAVIS_REPO_SLUG")-$TRAVIS_JOB_NUMBER"

      tar -c --transform "s/^logs/${archive_name}/" -f - logs | \
        xz > "${archive_name}.tar.xz"

      aws s3 cp "${archive_name}.tar.xz" s3://server-release-pipeline/travis-ci-logs/ \
        --region eu-west-1 \
        --acl public-read
    fi
