From d5e64c6e5552bda64e0b8a0123ab1177b3aef6ed Mon Sep 17 00:00:00 2001
From: "Patrick L.S. Connor" <connorpa@mail.desy.de>
Date: Thu, 11 Jul 2024 00:17:01 +0200
Subject: [PATCH] fix CI for EL9 (either LCG or micromamba)

---
 .gitlab-ci.yml    | 40 ++++++++++++++++++++++++++++++----------
 CMakeLists.txt    |  1 -
 README.md         |  2 +-
 install.sh        |  2 +-
 prerequisites.yml | 16 ++++++++++++++++
 setup             |  5 +++++
 6 files changed, 53 insertions(+), 13 deletions(-)
 create mode 100644 prerequisites.yml

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 374f3c7..e765a93 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,17 +1,37 @@
-image: gitlab-registry.cern.ch/ci-tools/ci-worker:cc7
-
-compilation:
+LCG:
     stage: build
     tags:
         - cvmfs
     variables:
         TERM: xterm
     script:
-        - yum install -y cmake3 openssl-devel python3 zsh
-        - source ./setup
+        - yum install -y cmake python3 zsh which libtirpc libicu libglvnd-glx pcre2-utf16 libXrender libSM
+        - source /cvmfs/sft.cern.ch/lcg/views/LCG_104/x86_64-el9-gcc13-opt/setup.sh
+        - ./install.sh
+        - source tools/setup.sh
+        - (cd Darwin.build; ctest --output-junit ../test_report.xml)
+        - (cd Core.build; ctest --output-junit ../test_report.xml)
+    artifacts:
+      when: always
+      paths:
+        - test_report.xml
+      reports:
+        junit: test_report.xml
+
+micromamba:
+    stage: build
+    script:
+        - sh <(curl -L micro.mamba.pm/install.sh)
+        - source ~/.bashrc
+        - micromamba create -f prerequisites.yml -n DAS -y
+        - micromamba activate DAS
         - ./install.sh
-        - cd CMSSW*/
-        - shopt -s expand_aliases  # allows aliases like cmsenv to be used
-        - cmsenv
-        - python -c "import CRABAPI"
-        - scram b -j$(nproc)
+        - source tools/setup.sh
+        - (cd Darwin.build; ctest --output-junit ../test_report.xml)
+        - (cd Core.build; ctest --output-junit ../test_report.xml)
+    artifacts:
+      when: always
+      paths:
+        - test_report.xml
+      reports:
+        junit: test_report.xml
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b84c00f..f4ce72c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -69,7 +69,6 @@ ExternalProject_Add(Darwin
     CMAKE_ARGS          -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR> -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
     BINARY_DIR          "${CMAKE_SOURCE_DIR}/Darwin.build"
     INSTALL_DIR         "${CMAKE_INSTALL_PREFIX}"
-    TEST_AFTER_INSTALL  ON
 )
 configure_file(darwin.xml.in darwin.xml)
 install(FILES "${CMAKE_BINARY_DIR}/darwin.xml" TYPE SYSCONF)
diff --git a/README.md b/README.md
index 34acc8f..beeb8f3 100644
--- a/README.md
+++ b/README.md
@@ -137,7 +137,7 @@ cmake --build Core.build --target install
 It is good practice to check that your changes do not harm the rest of the code. For this, tests can be run as follows:
 ```
 cd $DAS_BASE/Core.build
-ctest .
+ctest
 ```
 (analog to `cd $CMSSW_BASE; scram b runtests`.)
 
diff --git a/install.sh b/install.sh
index 0e0570e..71a5090 100755
--- a/install.sh
+++ b/install.sh
@@ -31,7 +31,7 @@ fi
 set -x
 
 # Download and build supporting tools
-cmake -B build
+cmake -B build $(correction config --cmake)
 cmake --build build --target install -j$(nproc)
 
 ## Get a CMSSW if we don't have one
diff --git a/prerequisites.yml b/prerequisites.yml
new file mode 100644
index 0000000..7688d81
--- /dev/null
+++ b/prerequisites.yml
@@ -0,0 +1,16 @@
+channels:
+  - conda-forge
+dependencies:
+  - zsh
+  - python >= 3.9
+  - cmake >= 3.26
+  - boost >= 1.78
+  - libgit2
+  - root
+  - gxx
+  - correctionlib
+  - eigen
+  - git-lfs
+  - doxygen
+  - pip:
+      - git+https://gitlab.cern.ch/RooUnfold/RooUnfold@master
diff --git a/setup b/setup
index 60acbf1..da20ab3 100644
--- a/setup
+++ b/setup
@@ -25,6 +25,11 @@ case "$(hostname)" in
         ;;
 esac
 
+if [ "$CI" = "true" ]
+then
+    return
+fi
+
 source /cvmfs/cms.cern.ch/rucio/setup-py3.sh
 source /cvmfs/cms.cern.ch/crab3/crab.sh
 
-- 
GitLab