From e54ea37ca43230a2808912304c032c9590855443 Mon Sep 17 00:00:00 2001
From: Florian Uhlig <f.uhlig@gsi.de>
Date: Tue, 7 Jul 2020 09:03:02 +0200
Subject: [PATCH] Improve Continuous Integration

Pipeline now fails also in case of failing tests.
New CI option MergeRequest for Dart.sh wrapper which creates a special CDash label.
Use new CI option when GitLab CI runs for a merge request.
---
 .gitlab-ci.yml     |  2 +-
 CbmRoot_test.cmake | 16 +++++++++++++---
 Dart.sh            |  6 +++---
 3 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index da5164ff..9606f509 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -109,7 +109,7 @@ CbmRoot_Merge:
     - ls
     - pwd
     - cat Dart.cfg
-    - $PWD/Dart.sh Continuous Dart.cfg
+    - $PWD/Dart.sh MergeRequest Dart.cfg
 
 pages:
   stage: documentation
diff --git a/CbmRoot_test.cmake b/CbmRoot_test.cmake
index e357f65a..8d2960c5 100644
--- a/CbmRoot_test.cmake
+++ b/CbmRoot_test.cmake
@@ -85,7 +85,7 @@ Ctest_Read_Custom_Files("${CTEST_BINARY_DIRECTORY}")
 
 Ctest_Start($ENV{ctest_model})
 
-If($ENV{ctest_model} MATCHES Continuous)
+If($ENV{ctest_model} MATCHES Continuous OR $ENV{ctest_model} MATCHES MergeRequest)
   set(ENV{ctest_model} Nightly)
 EndIf()
 
@@ -102,7 +102,11 @@ If(NOT _RETVAL)
     CTest_Submit(PARTS Update Configure Build)
   EndIf()
 
-  Ctest_Test(BUILD "${CTEST_BINARY_DIRECTORY}" PARALLEL_LEVEL $ENV{number_of_processors})
+  Ctest_Test(BUILD "${CTEST_BINARY_DIRECTORY}" 
+             PARALLEL_LEVEL $ENV{number_of_processors}
+             RETURN_VALUE _ctest_test_ret_val
+            )
+
   If($ENV{ctest_model} MATCHES Continuous)
     CTest_Submit(PARTS Test)
   EndIf()
@@ -118,6 +122,12 @@ If(NOT _RETVAL)
   If(NOT $ENV{ctest_model} MATCHES Continuous)
     Ctest_Submit()
   EndIf()
+
+  # Pipeline should fail also in case of failed tests
+  if (_ctest_test_ret_val)
+    Message(FATAL_ERROR "Some tests failed.")
+  endif()
+
 Else()
   CTest_Submit()
-EndIf()
\ No newline at end of file
+EndIf()
diff --git a/Dart.sh b/Dart.sh
index 6064523f..84205a6c 100755
--- a/Dart.sh
+++ b/Dart.sh
@@ -43,11 +43,11 @@ if [ "$#" -lt "2" ]; then
 fi
 
 # test if a ctest model is either Experimental or Nightly
-if [ "$1" == "Experimental" -o "$1" == "Nightly" -o "$1" == "Continuous" -o "$1" == "Profile" -o "$1" == "Weekly" ]; then
+if [ "$1" == "Experimental" -o "$1" == "Nightly" -o "$1" == "Continuous" -o "$1" == "Profile" -o "$1" == "Weekly" -o "$1" == "MergeRequest" ]; then
   echo ""
 else
   echo "-- Error -- This ctest model is not supported."
-  echo "-- Error -- Possible arguments are Nightly, Experimental, Continuous or Profile."
+  echo "-- Error -- Possible arguments are Nightly, Experimental, Continuous, Profile or MergeRequest."
   exit 1
 fi 
 
@@ -80,7 +80,7 @@ fi
 
 if [ "${ctest_model}" == "Weekly" ]; then
   export LABEL1=${LINUX_FLAVOUR}-$SYSTEM-$COMPILER$GCC_VERSION-${ctest_model}-fairsoft_$FAIRSOFT_VERSION-fairroot_$FAIRROOT_VERSION
-elif [ "${ctest_model}" == "Continuous" ]; then
+elif [ "${ctest_model}" == "MergeRequest" ]; then
   export LABEL1=${LINUX_FLAVOUR}-$SYSTEM-$COMPILER$GCC_VERSION-fairsoft_$FAIRSOFT_VERSION-fairroot_${FAIRROOT_VERSION}_MR-$CI_MERGE_REQUEST_IID
 else
   export LABEL1=${LINUX_FLAVOUR}-$SYSTEM-$COMPILER$GCC_VERSION-fairsoft_$FAIRSOFT_VERSION-fairroot_$FAIRROOT_VERSION
-- 
GitLab