From cd05537f3d45fc42480978a4ec2be7fa78f94138 Mon Sep 17 00:00:00 2001
From: Lars Bilke <lars.bilke@ufz.de>
Date: Wed, 17 Feb 2021 08:52:32 +0100
Subject: [PATCH] [ci] Added job code coverage (testrunner only).

---
 .gitlab-ci.yml                              |  1 +
 scripts/ci/extends/template-build-linux.yml | 17 +++++++++++------
 scripts/ci/jobs/code-coverage.yml           | 17 +++++++++++++++++
 3 files changed, 29 insertions(+), 6 deletions(-)
 create mode 100644 scripts/ci/jobs/code-coverage.yml

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index fafc6d425f4..25fe61a5aa2 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -54,6 +54,7 @@ include:
   - local: '/scripts/ci/jobs/checks.yml'
   # - template: 'Code-Quality.gitlab-ci.yml' # see !3053
   - local: '/scripts/ci/jobs/code-quality.yml'
+  - local: '/scripts/ci/jobs/code-coverage.yml'
   - local: '/scripts/ci/jobs/build-gui-linux.yml'
   - local: '/scripts/ci/jobs/build-gui-win.yml'
   - local: '/scripts/ci/jobs/build-gui-mac.yml'
diff --git a/scripts/ci/extends/template-build-linux.yml b/scripts/ci/extends/template-build-linux.yml
index 346ff35eb45..089ca30ef94 100644
--- a/scripts/ci/extends/template-build-linux.yml
+++ b/scripts/ci/extends/template-build-linux.yml
@@ -15,9 +15,14 @@
     - cmake -S . --preset=$CMAKE_PRESET $CMAKE_ARGS -DOGS_BUILD_PROCESSES=$BUILD_PROCESSES
     - build_dir=${BUILD_DIR:-build/$CMAKE_PRESET}
     - cd $build_dir
-    - $BUILD_CMD_PREFIX cmake --build . --target package > >(tee make.output)
-    - if [ "$BUILD_TESTS" = true ] ; then $BUILD_CMD_PREFIX cmake --build . --target tests ; fi
-    - if [ "$BUILD_CTEST" = true ] ; then $BUILD_CMD_PREFIX cmake --build . --target ctest ; fi
-    - if [ "$BUILD_CTEST_LARGE" = true ] ; then $BUILD_CMD_PREFIX cmake --build . --target ctest-large ; fi
-    - if [ "$BUILD_CTEST" = true ] ; then cp Testing/**/Test.xml Tests/ctest.xml ; fi
-    - if [ "$BUILD_CTEST_LARGE" = true ] ; then cp Testing/**/Test.xml Tests/ctest-large.xml ; fi
+    - |
+      if [[ -z "$TARGETS" ]]; then
+          $BUILD_CMD_PREFIX cmake --build . --target package > >(tee make.output)
+          if [ "$BUILD_TESTS" = true ] ; then $BUILD_CMD_PREFIX cmake --build . --target tests ; fi
+          if [ "$BUILD_CTEST" = true ] ; then $BUILD_CMD_PREFIX cmake --build . --target ctest ; fi
+          if [ "$BUILD_CTEST_LARGE" = true ] ; then $BUILD_CMD_PREFIX cmake --build . --target ctest-large ; fi
+          if [ "$BUILD_CTEST" = true ] ; then cp Testing/**/Test.xml Tests/ctest.xml ; fi
+          if [ "$BUILD_CTEST_LARGE" = true ] ; then cp Testing/**/Test.xml Tests/ctest-large.xml ; fi
+      else
+          $BUILD_CMD_PREFIX cmake --build . --target ${TARGETS} > >(tee make.output)
+      fi
diff --git a/scripts/ci/jobs/code-coverage.yml b/scripts/ci/jobs/code-coverage.yml
new file mode 100644
index 00000000000..c253ab31754
--- /dev/null
+++ b/scripts/ci/jobs/code-coverage.yml
@@ -0,0 +1,17 @@
+code coverage:
+  stage: check
+  extends:
+    - .template-build-linux
+  tags: [shell, envinf]
+  variables:
+    CMAKE_PRESET: coverage
+    TARGETS: testrunner_coverage
+  before_script:
+    # HACK to easier linking to the generated pages
+    - echo '<meta http-equiv="REFRESH" content="0;URL=build/coverage/testrunner_coverage/index.html">' >> Coverage.html
+  artifacts:
+    expose_as: 'Coverage'
+    paths:
+      - Coverage.html
+      - build/coverage/testrunner_coverage
+    expire_in: 1 week
-- 
GitLab