language: generic
dist: bionic

matrix:
  include:
    - os: linux
      env: COMPILER_NAME=gcc CXX=g++-5 CC=gcc-5 COMMON_OS_NAME=${TRAVIS_OS_NAME}
      addons:
        apt:
          packages:
            - g++-5
          sources: &sources
            - llvm-toolchain-bionic-11
            - sourceline: 'deb https://apt.llvm.org/bionic/ llvm-toolchain-bionic-11 main'
              key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key'
            - ubuntu-toolchain-r-test    
    - os: linux
      env: COMPILER_NAME=clang CXX=clang++-11 CC=clang-11 COMMON_OS_NAME=${TRAVIS_OS_NAME}
      addons:
        apt:
          packages:
            - clang-11
          sources: *sources
    - os: osx
      osx_image: xcode11.3
      env: CC=gcc-9 && CXX=g++-9 COMMON_OS_NAME=darwin
    - os: osx
      osx_image: xcode11.3
      env: CC=clang && CXX=clang++ COMMON_OS_NAME=darwin

before_install:
  - echo $LANG
  - echo $LC_ALL
  - $CXX --version

script:
  #    - rvm get head  # Workaround 'shell_session_update: command not found'
  - set -e
  - make test
  - python setup.py build
  - python setup.py test
  # Test CMake build scripts.
  - cmake . -Bbuild && cmake --build build --target run_tests
  # make a tarfile for the binaries and rename for os and tag
  - make dist
  - mv jsonnet-bin.tar.gz jsonnet-bin-${TRAVIS_TAG}-${COMMON_OS_NAME}.tar.gz

deploy:
  provider: releases
  api_key: $JSONNET_GITHUB_TOKEN
  file: jsonnet-bin-${TRAVIS_TAG}-${TRAVIS_OS_NAME}.tar.gz
  skip_cleanup: true
  on:
    tags: true
    # no point deploying the images built with both compilers
    condition: $CC =~ gcc

branches:
  only:
    - master
    # the branch name is the tag name, so having only master means you can't
    # trigger a build by just push a tag - so add in a regex to match tags that
    # should trigger. 
    - /^v.*$/

notifications:
  recipients:
    - sparkprime@gmail.com
  email:
    on_success: change
    on_failure: always
  irc:
    channels:
      - "chat.freenode.net#jsonnet"
    template:
      - "%{repository}/%{branch} (%{commit} - %{author}): %{message}"
