
# Global environment
language: cpp
os: linux
dist: bionic

# Avoid double build because of the tagging in the build.
branches:
  except:
  - latest-passing-build

# Build stages and the conditionals for the stages
stages:
  - name: extensive daily tests
    if: type = cron
  - name: basic build & test
    if: type != cron
  - name: extended build & test
    if: type != cron
  - name: deploy latest
    if: "(NOT type IN (pull_request)) AND (branch = master) AND (type != cron)"

jobs:
  include:

# Basic builds

# Mac OSX
    - stage: basic build & test
      compiler: gcc
      os: osx
      env: BUILD=autotools
    - compiler: clang
      env: BUILD=autotools
      os: osx

# Windows
    - compiler: msbuild
      os: windows
      env: BUILD=vc_windows CPP_STD=17
        - MSBUILD_PATH="c:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin"
        - VCTargetsPath="C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\IDE\VC\VCTargets"

# Linux
    - compiler: gcc
      env: BUILD=cmake CPP_STD=17
    - compiler: gcc
      env: BUILD=autotools
    - compiler: clang
      env: BUILD=autotools

# Extended builds, different C++ version and build tools
    - stage: extended build & test

# Mac OSX
      compiler: clang
      os: osx
      env: BUILD=cmake CPP_STD=17
    - compiler: gcc
      os: osx
      env: BUILD=cmake CPP_STD=14

# Linux
#   CMake different C++ versions with clang
    - compiler: clang
      env: BUILD=cmake CPP_STD=98
    - compiler: clang
      env: BUILD=cmake CPP_STD=11
    - compiler: clang
      env: BUILD=cmake CPP_STD=14
    - compiler: clang
      env: BUILD=cmake CPP_STD=17

#   CMake different C++ versions with gcc
    - compiler: gcc
      env: BUILD=cmake CPP_STD=98
    - compiler: gcc
      env: BUILD=cmake CPP_STD=11
    - compiler: gcc
      env: BUILD=cmake CPP_STD=14
    - compiler: gcc
      env: BUILD=cmake CPP_STD=17

#   New compilers can be added here. Need to be cleared when compiler becomes standard
    - compiler: gcc
      env: BUILD=cmake CPP_STD=17
        - CC=gcc-10
        - CXX=g++-10
      addons:
        apt:
          packages: ['g++-10']
          sources:
            - sourceline: 'ppa:ubuntu-toolchain-r/test'
    - compiler: clang
      env: BUILD=cmake CPP_STD=17
        - CC=clang-11
        - CXX=clang++-11
      addons:
        apt:
          sources:
            - sourceline: 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-11 main'
              key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key'
          packages: ['clang-11', 'libc++-11-dev', 'libc++abi-11-dev']

#   Specific other tests
    - compiler: gcc
      env: BUILD=test_report
      addons:
        apt:
          packages:
          - ant-optional
    - compiler: gcc
      env: BUILD=cmake_coverage
    - compiler: gcc
      env: BUILD=cmake_gtest
    - compiler: clang
      env: BUILD=autotools_gtest
    - compiler: gcc
      env: BUILD=autotools_cmake_install_test

#   MS DOS Build
    - env: BUILD=make_dos
      addons:
        apt:
          packages:
          - dosbox

#   Docker images. Need to be cleared at times
    - env: BUILD=docker_ubuntu_autotools
    - env: BUILD=docker_ubuntu_dos
    - env: BUILD=autotools_dist

    - stage: extensive daily tests
      compiler: gcc
      env: BUILD=extensive_check
    - compiler: clang
      env: BUILD=extensive_check
    - arch: ppc64le
      compiler: gcc
      env: BUILD=autotools
    - arch: s390x
      compiler: gcc
      env: BUILD=autotools
    - arch: arm64
      compiler: gcc
      env: BUILD=autotools
    - compiler: gcc
      env: BUILD=makefileworker
    - compiler: clang
      env: BUILD=autotools_install_and_test_examples

#   Deploy to github releases
    - stage: deploy latest
      env: BUILD=autotools_dist
      script:
      - export DATE=`date`
      - git tag -f latest-passing-build -a -m "Generated tag from TravisCI for build $TRAVIS_BUILD_NUMBER at $DATE"
      - git push -f https://cpputest-travis:$GH_TOKEN@github.com/cpputest/cpputest.git --tags
      - ../scripts/travis_ci_build.sh
      - pwd
      - ls
      deploy:
        provider: releases
        #:
        edge: true
        token: $GH_TOKEN
        tag_name: latest-passing-build
        name: Latest passing build
        release_notes: "This is the automatic release from Travis CI.\n\nWhenever a build passes, it gets released as Latest Passing Build.\n\nBuild number: $TRAVIS_BUILD_NUMBER\nDate: $DATE\nLog: $TRAVIS_BUILD_WEB_URL"
        file:
          - cpputest-latest.tar.gz
          - cpputest-latest.zip
        overwrite: true
        on:
          tags: false

before_script:
- export CPPUTEST_BUILD_DIR=$TRAVIS_BUILD_DIR/cpputest_build
- mkdir -p $CPPUTEST_BUILD_DIR && cd $CPPUTEST_BUILD_DIR

script:
- "../scripts/travis_ci_build.sh"

after_failure:
- "../scripts/travis_ci_after.sh"

after_success:
- "../scripts/travis_ci_after.sh"

notifications:
  slack:
    secure: oOx4AGIiJB+j1pkIxlLeQh5qp7TF89Sj+3RzJRQuo6z0HocTz9yJgXPlDh1H9rLj5SxK/UKsk+WFafVuPdWakQ40LeYO49C/+e+mCDcS0ujLka6dvIE8v0SEb1PuaAGjJWdhiviAhSqu9YOKPYZs37lD3oqepuEpxeiXwsur9QU=

env:
  global:
    secure: H6djbn5YP1P62n//ergaRZ4lIkneCzWp1Ok4F71kvvNiwlRzYDGll4kJT6MhVq6bBHeR81W/lwUd+RdjyqsJpVhj7DHXC/0k0h0xpAAm7LUhOl+6mIII1uhcMFqbeHvilwvDCzTQ6qv8Mzd1g0QfUECrmti9/U+/TTFJG0r0Zuc=
