From 1b7e9c017cb36f1e3ddf65d0332623bd8849b2a3 Mon Sep 17 00:00:00 2001
From: Giovanni La Mura <giovanni.lamura@inaf.it>
Date: Wed, 20 Dec 2023 15:39:24 +0100
Subject: [PATCH] Implement pipeline configuration and execution rules

---
 .gitlab-ci.yml | 37 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 3322dd02..96e825ab 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,4 +1,19 @@
 # CI pipeline configuration
+
+# Switch from branch pipelines to merge request pipelines when a merge request is created
+workflow:
+  rules:
+    # Ensures next rules do not block triggered pipelines
+    - if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS && $CI_PIPELINE_SOURCE == "push"
+      when: never
+    # always run for merge requests
+    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
+    # never run a branch pipeline if there is an open merge request for that branch
+    - if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
+      when: never
+    # the only allowed branch pipeline is that on the default branch
+    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
+
 stages:
    - build
    - run
@@ -66,4 +81,24 @@ testing_stage:
    allow_failure: true
    needs:
       - job: running_stage
-      
\ No newline at end of file
+   artifacts:
+      - paths:
+         - build/cluster/pycompare.html
+	 - build/sphere/pycompare.html
+      exclude:
+         - ".git*"
+	 - ".git/**/*"
+      expire_in: 2 hours
+   script:
+      # bash commands to be executed
+      - pwd
+      - hostname
+      - echo $CI_COMMIT_SHA
+      - echo $CI_COMMIT_BRANCH
+      - cd build/sphere
+      - echo "Comparing output of SPHERE"
+      - python3 ../../src/scripts/pycompare.py --ffile=OSPH --cfile=c_OSPH --html
+      - cd ../cluster
+      - echo "Comparing output of CLUSTER"
+      - python3 ../../src/scripts/pycompare.py --ffile=OCLU --cfile=c_OCLU --html
+      
-- 
GitLab