From bfbf39639beb60cd4691dbb64eab72436c0da2c3 Mon Sep 17 00:00:00 2001
From: Lars Bilke <lars.bilke@ufz.de>
Date: Wed, 17 Mar 2021 14:25:41 +0100
Subject: [PATCH] [ci] Fix warnings check.

Do the check right in the compiler job.
---
 .gitlab-ci.yml                              |  1 -
 scripts/ci/extends/template-build-linux.yml |  4 ++++
 scripts/ci/extends/template-build-win.yml   |  7 +++++++
 scripts/ci/jobs/build-linux.yml             |  1 +
 scripts/ci/jobs/build-mac.yml               |  1 +
 scripts/ci/jobs/build-win.yml               |  1 +
 scripts/ci/jobs/checks.yml                  | 16 ----------------
 7 files changed, 14 insertions(+), 17 deletions(-)
 delete mode 100644 scripts/ci/jobs/checks.yml

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 25fe61a5aa2..ffb042b08ce 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -51,7 +51,6 @@ include:
   - local: '/scripts/ci/jobs/build-docs.yml'
   - local: '/scripts/ci/jobs/build-win.yml'
   - local: '/scripts/ci/jobs/build-mac.yml'
-  - 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'
diff --git a/scripts/ci/extends/template-build-linux.yml b/scripts/ci/extends/template-build-linux.yml
index 0654504d551..e39b5e74b1a 100644
--- a/scripts/ci/extends/template-build-linux.yml
+++ b/scripts/ci/extends/template-build-linux.yml
@@ -29,3 +29,7 @@
       else
           $BUILD_CMD_PREFIX cmake --build . --target ${TARGETS} > >(tee make.output)
       fi
+    - |
+      if [[ "$CHECK_WARNINGS" = true ]] ; then
+          if [[ $(cat make.output | grep warning -i) ]]; then printf 'There were compiler warnings:\n\n'; cat make.output | grep warning -i; exit 1; fi
+      fi
diff --git a/scripts/ci/extends/template-build-win.yml b/scripts/ci/extends/template-build-win.yml
index cba0eb9f2bf..fb18920ddf2 100644
--- a/scripts/ci/extends/template-build-win.yml
+++ b/scripts/ci/extends/template-build-win.yml
@@ -25,3 +25,10 @@
     - if($env:BUILD_TESTS -eq "true") { cmake --build . --target tests }
     - if($env:BUILD_CTEST -eq "true") { cmake --build . --target ctest }
     - if($env:BUILD_CTEST -eq "true") { cp Testing/**/Test.xml Tests/ctest.xml }
+    - |
+      if($env:CHECK_WARNINGS -eq "true" -and (cat make.output | Select-String -Pattern ': warning') )
+      {
+          Write-Output 'There were compiler warnings:\n'
+          cat make.output | Select-String -Pattern ': warning'
+          exit 1
+      }
diff --git a/scripts/ci/jobs/build-linux.yml b/scripts/ci/jobs/build-linux.yml
index ef375adff31..3dd53aa4bba 100644
--- a/scripts/ci/jobs/build-linux.yml
+++ b/scripts/ci/jobs/build-linux.yml
@@ -50,6 +50,7 @@ build linux (no unity):
     BUILD_DIR: "no-unity"
     BUILD_TESTS: "false"
     BUILD_CTEST: "false"
+    CHECK_WARNINGS: "true"
     CMAKE_PRESET: release
     CMAKE_ARGS: >-
       -DOGS_USE_PYTHON=OFF
diff --git a/scripts/ci/jobs/build-mac.yml b/scripts/ci/jobs/build-mac.yml
index 2c85a2a1af1..04eb3319bbb 100644
--- a/scripts/ci/jobs/build-mac.yml
+++ b/scripts/ci/jobs/build-mac.yml
@@ -7,6 +7,7 @@ build mac:
   needs: [meta]
   variables:
     BUILD_DIR: "mac-release"
+    CHECK_WARNINGS: "true"
     CMAKE_PRESET: release
     CMAKE_ARGS: >-
       -DOGS_INSTALL_DEPENDENCIES=ON
diff --git a/scripts/ci/jobs/build-win.yml b/scripts/ci/jobs/build-win.yml
index bf991fb6bc6..9c2ed063ede 100644
--- a/scripts/ci/jobs/build-win.yml
+++ b/scripts/ci/jobs/build-win.yml
@@ -8,6 +8,7 @@ build win:
       allow_failure: true
   variables:
     BUILD_DIR: win-release
+    CHECK_WARNINGS: "true"
     CMAKE_PRESET: release
     CMAKE_ARGS: >-
       -DOGS_CI_TESTRUNNER_REPEAT=1
diff --git a/scripts/ci/jobs/checks.yml b/scripts/ci/jobs/checks.yml
deleted file mode 100644
index c3a993ce5ef..00000000000
--- a/scripts/ci/jobs/checks.yml
+++ /dev/null
@@ -1,16 +0,0 @@
-compiler warnings:
-  stage: check
-  image: ubuntu:20.04
-  variables:
-    GIT_STRATEGY: none
-  allow_failure: true
-  needs:
-    - job: "build linux (no unity)"
-    - job: "build win: [USE_PYTHON=ON]"
-    - job: build mac
-  script:
-    - exit_code=0
-    - "if [[ $(cat build/no-unity/make.output | grep warning -i) ]]; then printf 'There were GCC compiler warnings:\n\n'; cat make.output | grep warning -i; exit_code=1; fi"
-    - "if [[ $(cat build/win-release/make.output | grep ': warning' -i) ]]; then printf 'There were MSVC compiler warnings:\n\n'; cat make.output | grep ': warning' -i; exit_code=1; fi"
-    - "if [[ $(cat build/mac-release/make.output | grep warning -i) ]]; then printf 'There were Clang (macOS) compiler warnings:\n\n'; cat make.output | grep warning -i; exit_code=1; fi"
-    - exit $exit_code
-- 
GitLab