From d8dfd008cef4483d6623bd5a79cb8a193a17a38a Mon Sep 17 00:00:00 2001
From: Thomas Jahns <jahns@dkrz.de>
Date: Tue, 5 Nov 2024 14:31:14 +0100
Subject: [PATCH] gitlab-ci: expand and simplify setup.

---
 .gitlab-ci.yml | 214 +++++++++++++++++++++++--------------------------
 1 file changed, 99 insertions(+), 115 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 4481f8a3..b7de3fe5 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -56,24 +56,105 @@ include:
   before_script:
     - *load_basic_modules
     - module load gcc/11.2.0-gcc-11.2.0 openmpi/4.1.2-gcc-11.2.0
+    - export OMPI_MCA_btl_sm_use_knem=0
+    - export OMPI_MCA_btl_vader_single_copy_mechanism=none
+    - ci_FC=mpifort
+    - ci_FCFLAGS='-pipe -O2 -g -march=native'
+    - ci_BUILD_FCFLAGS='-Wall -Wextra -Werror'
+    - ci_CC=mpicc
+    - ci_CFLAGS='-pipe -O2 -g -march=native'
+    - ci_BUILD_CFLAGS='-Wall -Wextra -Werror'
 
 .init_build_intel_2021_5_0:
   extends: .init_build
   before_script:
     - *load_basic_modules
     - module load intel-oneapi-compilers/2022.0.1-gcc-11.2.0 openmpi/4.1.2-intel-2021.5.0
+    - ci_FC=mpifort
+    - ci_CC=mpicc
+    - ci_CFLAGS='-O2 -march=core-avx2 -g'
+    - ci_FCFLAGS='-O2 -march=core-avx2 -g'
+    - ci_BUILD_FCFLAGS='-diag-enable=all'
+    - ci_BUILD_CFLAGS='-diag-enable=all'
+    - export OMPI_MCA_btl_sm_use_knem=0
+    - export OMPI_MCA_btl_vader_single_copy_mechanism=none
 
 .init_build_oneapi_2023_2_1:
   extends: .init_build
   before_script:
     - *load_basic_modules
     - module load intel-oneapi-compilers/2023.2.1-gcc-11.2.0 intel-oneapi-mpi/2021.5.0-intel-2021.5.0
+    - export I_MPI_F90=ifx I_MPI_CC=icx
+    - ci_FC=mpiifort
+    - ci_FCFLAGS='-O2 -march=core-avx2 -g'
+    - ci_BUILD_FCFLAGS='-diag-enable=all'
+    - ci_CC=mpiicc
+    - ci_CFLAGS='-O2 -march=core-avx2 -g -fno-math-errno'
+    - ci_BUILD_CFLAGS='-diag-enable=all'
+    - ci_LDFLAGS="-g -shared-intel"
+    - ci_MPI_LAUNCH=$(command -v mpirun)
 
 .init_build_nag_7_1:
   extends: .init_build
   before_script:
     - *load_basic_modules
     - module load nag/7.1-gcc-11.2.0 openmpi/4.1.2-nag-7.1
+    - export OMPI_MCA_btl_sm_use_knem=0
+    - export OMPI_MCA_btl_vader_single_copy_mechanism=none
+    - ci_FCFLAGS='-C=alias -C=array -C=bits -C=dangling -C=do -C=intovf -C=present -C=pointer -C=recursion -gline -nan -g -fpp -colour=warn:yellow -wmismatch=mpi_pack,mpi_unpack,mpi_bcast,mpi_send,mpi_recv,mpi_allreduce,mpi_isend,mpi_irecv,mpi_allgather,mpi_allgatherv,mpi_gather,mpi_gatherv,mpi_sendrecv,mpi_type_get_extent,xt_slice_c_loc -w=uda -w=alloctr -w=uep -w=x77 -f2008 -Wc,-pipe'
+    - ci_CFLAGS="-O0 -g -pipe"
+    - ci_BUILD_CFLAGS='-Wall -Werror'
+    - ci_CC=mpicc
+    - ci_FC=mpif90
+
+.init_build_nag_7_2:
+  extends: .init_build
+  before_script:
+    - *load_basic_modules
+    - module load nag/7.2-gcc-11.2.0 openmpi/4.1.6-nag-7.2
+    - export OMPI_MCA_btl_sm_use_knem=0
+    - export OMPI_MCA_btl_vader_single_copy_mechanism=none
+    - ci_FCFLAGS="-C=alias -C=array -C=bits -C=dangling -C=do -C=intovf -C=present -C=pointer -C=recursion -gline -nan -g -fpp -colour=warn:yellow -wmismatch=mpi_pack,mpi_unpack,mpi_bcast,mpi_send,mpi_recv,mpi_allreduce,mpi_isend,mpi_irecv,mpi_allgather,mpi_allgatherv,mpi_gather,mpi_gatherv,mpi_sendrecv,mpi_type_get_extent,xt_slice_c_loc -w=uda -w=alloctr -w=uep -w=x77 -f2008 -Wc,-pipe"
+    - ci_CFLAGS="-O0 -g -pipe"
+    - ci_BUILD_CFLAGS='-Wall -Werror'
+    - ci_CC=mpicc
+    - ci_FC=mpif90
+
+.basic_build:
+  script:
+    - scripts/reconfigure
+    - >
+      ./configure
+      ${ci_CC+CC="${ci_CC}"}
+      ${ci_FC+FC="${ci_FC}"}
+      ${ci_FCFLAGS+FCFLAGS="${ci_FCFLAGS}"}
+      ${BUILD_FCFLAGS+BUILD_FCFLAGS="${ci_BUILD_FCFLAGS}"}
+      ${ci_CFLAGS+CFLAGS="${ci_CFLAGS}"}
+      ${ci_BUILD_CFLAGS+BUILD_CFLAGS="${ci_BUILD_CFLAGS}"}
+      --disable-silent-rules
+      MPI_LAUNCH="${ci_MPI_LAUNCH-$(command -v mpirun) --oversubscribe}"
+      ${ci_LDFLAGS+LDFLAGS="$ci_LDFLAGS"}
+      || { status=$? ; gzip config.log ; exit $status ; }
+    - gzip config.log
+# build yaxt and unit tests without running tests
+    - make 2> >(tee make.err)
+# run tests
+    - make -j4 check
+# check git untracked files(any git untracked files would cause failure in ICON buildbot test)
+    - mapfile -t untracked_files < <( $(git ls-files --other --exclude-standard --exclude=config.log.gz --exclude=make.err) )
+    - |
+      [[ ${#untracked_files[@]} -eq 0 ]] || {
+        printf "%s\n" "Failure: Untracked files found" "${untracked_files[@]}"
+        exit 1
+      }
+  artifacts:
+    paths:
+      - make.err
+      - config.log.gz
+      - tests/test-suite.log
+    when: always
+    expire_in: 5min
+
 
 .install_gcovr: &install_gcovr
   - mkdir $CI_PROJECT_DIR/install_dir
@@ -124,130 +205,33 @@ gen_cov_data:
 
 run_test_gcc_11_2_0:
   stage: tests
-  extends: .init_build_gcc_11_2_0
-  script:
-    - export OMPI_MCA_btl_sm_use_knem=0
-    - export OMPI_MCA_btl_vader_single_copy_mechanism=none
-    - scripts/reconfigure
-    - >
-      ./configure
-      CC=mpicc FC=mpifort
-      FCFLAGS="-pipe -O2 -g -march=native"
-      BUILD_FCFLAGS="-Wall -Wextra -Werror"
-      CFLAGS="-pipe -O2 -g -march=native"
-      BUILD_CFLAGS="-Wall -Wextra -Werror"
-      --disable-silent-rules
-      MPI_LAUNCH="$(command -v mpirun) --oversubscribe"
-      || { status=$? ; gzip config.log ; exit $status ; }
-    - gzip config.log
-# build yaxt and unit tests without running tests
-    - make 2> >(tee make.err)
-# run tests
-    - make -j4 check
-# check git untracked files(any git untracked files would cause failure in ICON buildbot test)
-    - mapfile -t untracked_files < <( $(git ls-files --other --exclude-standard --exclude=config.log.gz --exclude=make.err) )
-    - |
-      [[ ${#untracked_files[@]} -eq 0 ]] || {
-        printf "%s\n" "Failure: Untracked files found" "${untracked_files[@]}"
-        exit 1
-      }
-  artifacts:
-    paths:
-      - make.err
-      - config.log.gz
-      - tests/test-suite.log
-    when: always
-    expire_in: 5min
+  extends:
+    - .init_build_gcc_11_2_0
+    - .basic_build
 
 run_test_intel_2021_5_0:
   stage: tests
-  extends: .init_build_intel_2021_5_0
-  script:
-    - export OMPI_MCA_btl_sm_use_knem=0
-    - export OMPI_MCA_btl_vader_single_copy_mechanism=none
-    - scripts/reconfigure
-    - >
-      ./configure
-      CC=mpicc FC=mpifort
-      FCFLAGS="-O2 -march=core-avx2 -g"
-      CFLAGS="-O2 -march=core-avx2 -g"
-      BUILD_FCFLAGS="-diag-enable=all"
-      BUILD_CFLAGS="-diag-enable=all"
-      --disable-silent-rules
-      MPI_LAUNCH="$(command -v mpirun) --oversubscribe"
-      || { status=$? ; gzip config.log ; exit $status ; }
-    - gzip config.log
-# build yaxt and unit tests without running tests
-    - make 2> >(tee make.err)
-# run tests
-    - make -j4 check
-  artifacts:
-    paths:
-      - make.err
-      - config.log.gz
-      - tests/test-suite.log
-    when: always
-    expire_in: 5min
+  extends:
+    - .init_build_intel_2021_5_0
+    - .basic_build
 
 run_test_oneapi_2023_2_1:
   stage: tests
-  extends: .init_build_oneapi_2023_2_1
-  script:
-    - export I_MPI_F90=ifx I_MPI_CC=icx
-    - scripts/reconfigure
-    - >
-      ./configure
-      CC=mpiicc FC=mpiifort
-      FCFLAGS="-O2 -march=core-avx2 -g"
-      CFLAGS="-O2 -march=core-avx2 -g -fno-math-errno"
-      BUILD_FCFLAGS="-diag-enable=all"
-      BUILD_CFLAGS="-diag-enable=all"
-      LDFLAGS="-g -shared-intel"
-      --disable-silent-rules
-      --disable-static
-      MPI_LAUNCH="$(command -v mpirun)"
-      || { status=$? ; gzip config.log ; exit $status ; }
-    - gzip config.log
-# build yaxt and unit tests without running tests
-    - make 2> >(tee make.err)
-# run tests
-    - make -j4 check
-  artifacts:
-    paths:
-      - make.err
-      - config.log.gz
-      - tests/test-suite.log
-    when: always
-    expire_in: 5min
+  extends:
+    - .init_build_oneapi_2023_2_1
+    - .basic_build
 
 run_test_nag_7_1:
   stage: tests
-  extends: .init_build_nag_7_1
-  script:
-    - export OMPI_MCA_btl_sm_use_knem=0
-    - export OMPI_MCA_btl_vader_single_copy_mechanism=none
-    - scripts/reconfigure
-    - >
-      ./configure
-      FCFLAGS="-C=alias -C=array -C=bits -C=dangling -C=do -C=intovf -C=present -C=pointer -C=recursion -gline -nan -g -fpp -colour=warn:yellow -wmismatch=mpi_pack,mpi_unpack,mpi_bcast,mpi_send,mpi_recv,mpi_allreduce,mpi_isend,mpi_irecv,mpi_allgather,mpi_allgatherv,mpi_gather,mpi_gatherv,mpi_sendrecv,mpi_type_get_extent,xt_slice_c_loc -w=uda -w=alloctr -w=uep -w=x77 -f2008 -Wc,-pipe"
-      CFLAGS="-O0 -g -pipe"
-      BUILD_CFLAGS="-Wall -Werror"
-      CC=mpicc FC=mpif90
-      MPI_LAUNCH="$(command -v mpirun) --oversubscribe"
-      --disable-silent-rules
-      || { status=$? ; gzip config.log ; exit $status ; }
-    - gzip config.log
-# build yaxt and unit tests without running tests
-    - make 2> >(tee make.err)
-# run tests
-    - make check
-  artifacts:
-    paths:
-      - make.err
-      - config.log.gz
-      - tests/test-suite.log
-    when: always
-    expire_in: 5min
+  extends:
+    - .init_build_nag_7_1
+    - .basic_build    
+
+run_test_nag_7_2:
+  stage: tests
+  extends:
+    - .init_build_nag_7_2
+    - .basic_build
 
 gen_doxy_html:
   stage: documentation
-- 
GitLab