From 2c698a692e124b7917fea1f25dced81ac33c3e45 Mon Sep 17 00:00:00 2001
From: Timo Koch <timo.koch@iws.uni-stuttgart.de>
Date: Mon, 26 Jul 2021 18:38:33 +0200
Subject: [PATCH] [ci][python] Test Python bindings

---
 .gitlab-ci.yml                     |  7 ++---
 .gitlab-ci/default.yml             | 41 ++++++++++++++++++++++++++++--
 bin/testing/ci-setup-python-env.sh |  8 ++++++
 bin/testing/runselectedtests.py    |  2 +-
 4 files changed, 52 insertions(+), 6 deletions(-)
 create mode 100755 bin/testing/ci-setup-python-env.sh

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index dc75cc79b4..02855a45fa 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -106,13 +106,14 @@ full-dune-2.7-clang:
   variables:
     IMAGE: $IMAGE_REGISTRY_URL/full:dune-2.7-clang-ubuntu-20.04
 
-##################################
-# additional scheduled pipelines #
 full-dune-master-gcc:
-  extends: .non-mr-trigger
+  extends: .base-trigger
   variables:
     IMAGE: $IMAGE_REGISTRY_URL/full:dune-master-gcc-ubuntu-20.04
 
+
+##################################
+# additional scheduled pipelines #
 full-dune-master-clang:
   extends: .non-mr-trigger
   variables:
diff --git a/.gitlab-ci/default.yml b/.gitlab-ci/default.yml
index 15a7192fb4..012847136f 100644
--- a/.gitlab-ci/default.yml
+++ b/.gitlab-ci/default.yml
@@ -1,24 +1,39 @@
 default:
   image: $IMAGE
 
+
 stages:
   - configure
+  - select
   - build
   - test
 
+
 workflow:
   rules:
     - if: $CI_PIPELINE_SOURCE=="parent_pipeline"
 
+
 # variables that should be overwritten by the trigger
 variables:
   MR_TARGET_BRANCH_NAME: ""
   REFERENCE_SHA: ""
 
-select tests:
+
+configure:
   stage: configure
   script:
     - dunecontrol --opts=$DUNE_OPTS_FILE --current all
+    - source bin/testing/ci-setup-python-env.sh
+  artifacts:
+    paths:
+      - build-cmake
+    expire_in: 3 hours
+
+
+select tests:
+  stage: select
+  script:
     - |
       if [[ -n "$MR_TARGET_BRANCH_NAME" ]]; then
           echo "Detecting changes w.r.t to target branch '$MR_TARGET_BRANCH_NAME'"
@@ -44,9 +59,12 @@ select tests:
       fi
   artifacts:
     paths:
-      - build-cmake
       - affectedtests.json
     expire_in: 3 hours
+  needs:
+    - job: configure
+      artifacts: true
+
 
 build dumux:
   stage: build
@@ -66,9 +84,12 @@ build dumux:
       - affectedtests.json
     expire_in: 3 hours
   needs:
+    - job: configure
+      artifacts: true
     - job: select tests
       artifacts: true
 
+
 test dumux:
   stage: test
   variables:
@@ -89,3 +110,19 @@ test dumux:
   artifacts:
     reports:
       junit: junit/dumux-cmake.xml
+
+
+test dumux python:
+  stage: test
+  variables:
+    OMPI_ALLOW_RUN_AS_ROOT: 1
+    OMPI_ALLOW_RUN_AS_ROOT_CONFIRM: 1
+  script:
+    - source bin/testing/ci-setup-python-env.sh
+    - |
+      pushd build-cmake
+        ctest --output-on-failure -L python
+      popd
+  needs:
+    - job: configure
+      artifacts: true
diff --git a/bin/testing/ci-setup-python-env.sh b/bin/testing/ci-setup-python-env.sh
new file mode 100755
index 0000000000..dd20b89d61
--- /dev/null
+++ b/bin/testing/ci-setup-python-env.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+if [ -L /dune/bin/setup-python ] && [ -e /dune/bin/setup-python ] ; then
+    dunecontrol bexec "echo -n :\$(pwd)/python >> $(pwd)/pythonpath.txt"
+    export PYTHONPATH=$PYTHONPATH$(cat pythonpath.txt)
+    rm pythonpath.txt
+    setup-python --opts=$DUNE_OPTS_FILE install
+fi
diff --git a/bin/testing/runselectedtests.py b/bin/testing/runselectedtests.py
index 7fa8076ed5..a1570c898f 100755
--- a/bin/testing/runselectedtests.py
+++ b/bin/testing/runselectedtests.py
@@ -81,7 +81,7 @@ if __name__ == '__main__':
                         help='set the flags passed to make')
     parser.add_argument('-tf', '--testflags',
                         required=False,
-                        default='-j4 --output-on-failure',
+                        default='-j4 --output-on-failure -LE python',
                         help='set the flags passed to ctest')
     args = vars(parser.parse_args())
 
-- 
GitLab