From 259221162536d4c4164fdfd631723a2184790b07 Mon Sep 17 00:00:00 2001
From: cmoineau <cyril.moineau@cea.fr>
Date: Fri, 18 Apr 2025 14:30:32 +0000
Subject: [PATCH] Separate before script in ubuntu jobs

---
 .gitlab/ci/ubuntu_python.gitlab-ci.yml | 68 ++++++++++++++++----------
 1 file changed, 42 insertions(+), 26 deletions(-)

diff --git a/.gitlab/ci/ubuntu_python.gitlab-ci.yml b/.gitlab/ci/ubuntu_python.gitlab-ci.yml
index 0d7ad96..f1572a4 100644
--- a/.gitlab/ci/ubuntu_python.gitlab-ci.yml
+++ b/.gitlab/ci/ubuntu_python.gitlab-ci.yml
@@ -5,16 +5,20 @@ include:
 ####################################################################################################
 #                                               BUILD
 ####################################################################################################
+
+.setup:build:ubuntu_python:
+  before_script:
+    - !reference [.retrieve_deps:apt, script]
+    - DEPENDENCY_JOB="build:ubuntu_python"
+    - !reference [.ubuntu:download:artifacts, before_script]
+    - python3 -m pip install virtualenv
+
 build:ubuntu_python:
   stage: build
   needs: []
   tags:
     - docker
-  before_script: &setup_ubuntu_build
-    - !reference [.retrieve_deps:apt, script]
-    - DEPENDENCY_JOB="build:ubuntu_python"
-    - !reference [.ubuntu:download:artifacts, before_script]
-    - python3 -m pip install virtualenv
+  extends: .setup:build:ubuntu_python
 
   script:
     - virtualenv venv
@@ -33,6 +37,15 @@ build:ubuntu_python:
 ####################################################################################################
 #                                               TEST
 ####################################################################################################
+
+.setup:test:ubuntu_python:
+  before_script:
+    - !reference [.retrieve_deps:apt, script]
+    - source venv/bin/activate
+    - python -m pip install pytest
+    - which python
+    - python -m pip list
+
 test:ubuntu_python:
   stage: test
   needs: ["build:ubuntu_python"]
@@ -41,16 +54,12 @@ test:ubuntu_python:
     - allow_failure: false
   tags:
     - docker
-  before_script: &setup_ubuntu_test
-    - !reference [.retrieve_deps:apt, script]
-    - source venv/bin/activate
-    - python -m pip install pytest
-    - which python
-    - python -m pip list
-    - >
-      if [[ "$CI_PROJECT_NAME" == "aidge_onnx" ]]; then
-        python -m pip install requests onnxruntime>=1.18.0
-      fi
+  extends: .setup:test:ubuntu_python
+  # before_script: &setup_ubuntu_test
+  #   - >
+  #     if [[ "$CI_PROJECT_NAME" == "aidge_onnx" ]]; then
+  #       python -m pip install requests onnxruntime>=1.18.0
+  #     fi
   script:
     - cd ${CI_PROJECT_NAME}
     # Run on discovery all tests located in project/unit_tests/python and discard the stdout
@@ -65,23 +74,30 @@ test:ubuntu_python:
 ####################################################################################################
 #                                               COVERAGE
 ####################################################################################################
+
+.setup:coverage:ubuntu_python:
+  before_script:
+    - !reference [.retrieve_deps:apt, script]
+    - source venv/bin/activate
+    - which python
+    - python -m pip list
+    - python -m pip install numpy coverage requests
+
 coverage:ubuntu_python:
   stage: coverage
   needs: ["build:ubuntu_python"]
-  extends: .rules:static_analysis_coverage
+  extends:
+    - .rules:static_analysis_coverage
+    - .setup:coverage:ubuntu_python
   tags:
     - docker
 
-  before_script: &setup_ubuntu_cov
-    - !reference [.retrieve_deps:apt, script]
-    - source venv/bin/activate
-    - which python
-    - python -m pip list
-    - python -m pip install numpy coverage requests unittest-xml-reporting
-    - >
-      if [[ "$CI_PROJECT_NAME" == "aidge_onnx" ]]; then
-        python -m pip install pytest onnxruntime>=1.18.0
-      fi
+  # before_script: &setup_ubuntu_cov
+
+  #   - >
+  #     if [[ "$CI_PROJECT_NAME" == "aidge_onnx" ]]; then
+  #       python -m pip install pytest onnxruntime>=1.18.0
+  #     fi
   script:
     - cd ${CI_PROJECT_NAME}
     # Retrieve the installation path of the module, since it is installed with pip.
-- 
GitLab