CI CHANGE integrate Test build and Coverity build into a single config
diff --git a/.travis.yml b/.travis.yml
index 45b2768..6684f71 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,41 +1,82 @@
 language: c
+sudo: required
+dist: trusty
 
-matrix:
+env:
+  global:
+   # The next declaration is the encrypted COVERITY_SCAN_TOKEN, created
+   #   via the "travis encrypt" command using the project repo's public key
+   - secure: "jkN1i+W2V5/ULAmpqEOyl6J6hsa9rS8JcBKsjB/Md6sJJprWKepUfQ0UdhrjBYbFJbo1mnjL0sHboTrowBXH59IQquPtw64oF9HzyMcmwr+Dm93hhm/vaI06oXwkxmnQxC0OW7Cttrmo+858lsegZYxrh2p4tgEd6WOtDpJIaQ4="
+
+stages:
+  - name: Test
+    if: type != cron
+    before_install:
+      - wget https://cmocka.org/files/1.1/cmocka-1.1.2.tar.xz
+      - tar -xf cmocka-1.1.2.tar.xz
+      - cd cmocka-1.1.2; mkdir build; cd build
+      - cmake .. && make -j2 && sudo make install
+      - cd ../..
+      - if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew update; fi
+      - if [ "$TRAVIS_OS_NAME" = "linux" ]; then sudo apt-get update -qq; sudo apt-get install -y valgrind; fi
+      - if [ "$TRAVIS_OS_NAME" = "linux" -a "$CC" = "gcc" ]; then pip install --user codecov; export CFLAGS="-coverage"; fi
+    script:
+      - mkdir build && cd build
+      - if [ "$TRAVIS_OS_NAME" = "osx" ]; then cmake -DENABLE_VALGRIND_TESTS=OFF ..; fi
+      - if [ "$TRAVIS_OS_NAME" = "linux" ]; then cmake ..; fi
+      - make -j2 && ctest --output-on-failure
+      - cd -
+    after_success:
+      - if [ "$TRAVIS_OS_NAME" = "linux" -a "$CC" = "gcc" ]; then codecov; fi
+  - name: Coverity
+    if: type = cron
+    env:
+      # The next declaration is the encrypted COVERITY_SCAN_TOKEN, created
+      #   via the "travis encrypt" command using the project repo's public key
+      - secure: "jkN1i+W2V5/ULAmpqEOyl6J6hsa9rS8JcBKsjB/Md6sJJprWKepUfQ0UdhrjBYbFJbo1mnjL0sHboTrowBXH59IQquPtw64oF9HzyMcmwr+Dm93hhm/vaI06oXwkxmnQxC0OW7Cttrmo+858lsegZYxrh2p4tgEd6WOtDpJIaQ4="
+    before_install:
+      - echo -n | openssl s_client -connect scan.coverity.com:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sudo tee -a /etc/ssl/certs/ca-certificates.crt
+      - sudo apt-get update -qq
+    script:
+      # do nothing, everything here is done in coverity addon
+      - true
+
+jobs:
   include:
-    - os: linux
-      dist: trusty
-      sudo: required
+    - stage: Coverity
+      name: Coverity night check
+      os: linux
       compiler: clang
-    - os: linux
-      dist: trusty
-      sudo: required
+      addons:
+        coverity_scan:
+          project:
+            name: "CESNET/libyang"
+          notification_email: rkrejci@cesnet.cz
+          build_command_prepend: "mkdir build; cd build; cmake ..; make clean"
+          build_command: "make"
+      branches:
+        only:
+          - libyang2
+    - stage: Test
+      name: Linux with CLang
+      os: linux
+      compiler: clang
+      branches:
+        only:
+          - libyang2
+    - stage: Test
+      name: Linux with GCC
+      os: linux
+      compiled: gcc
+      branches:
+        only:
+          - libyang2
+    - stage: Test
+      name: OS X with GCC
+      os: osx
       compiler: gcc
-    - os: osx
-      compiler: gcc
-  allow_failures:
-    - os: osx
-
-branches:
-  only:
-    - libyang2
-
-before_install:
-  - eval "${MATRIX_EVAL}"
-  - wget https://cmocka.org/files/1.1/cmocka-1.1.2.tar.xz
-  - tar -xf cmocka-1.1.2.tar.xz
-  - cd cmocka-1.1.2; mkdir build; cd build
-  - cmake .. && make -j2 && sudo make install
-  - cd ../..
-  - if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew update; fi
-  - if [ "$TRAVIS_OS_NAME" = "linux" ]; then sudo apt-get update -qq; sudo apt-get install -y valgrind; fi
-  - if [ "$TRAVIS_OS_NAME" = "linux" -a "$CC" = "gcc" ]; then pip install --user codecov; export CFLAGS="-coverage"; fi
-
-script:
-  - mkdir build && cd build
-  - if [ "$TRAVIS_OS_NAME" = "osx" ]; then cmake -DENABLE_VALGRIND_TESTS=OFF ..; fi
-  - if [ "$TRAVIS_OS_NAME" = "linux" ]; then cmake ..; fi
-  - make -j2 && ctest --output-on-failure
-  - cd -
-
-after_success:
-  - if [ "$TRAVIS_OS_NAME" = "linux" -a "$CC" = "gcc" ]; then codecov; fi
+      allow_failures:
+        - os: osx
+      branches:
+        only:
+          - libyang2