From e408af25f8e45cbb5feb0d75fdd3ddbe716788a3 Mon Sep 17 00:00:00 2001
From: cmoineau <cyril.moineau@cea.fr>
Date: Wed, 31 Jan 2024 10:39:51 +0000
Subject: [PATCH] add dependency download.

---
 .gitlab/ci/shared_test.gitlab-ci.yml | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/.gitlab/ci/shared_test.gitlab-ci.yml b/.gitlab/ci/shared_test.gitlab-ci.yml
index efa1c6c..8a37330 100644
--- a/.gitlab/ci/shared_test.gitlab-ci.yml
+++ b/.gitlab/ci/shared_test.gitlab-ci.yml
@@ -8,10 +8,19 @@ shared_job:
 .download_dependency:
   script:
     - GROUP_ID=$(curl "https://gitlab.eclipse.org/api/v4/groups?search=aidge" | grep -m1 -oP '"id":\s*\K\d+')
-    - echo "GROUP_ID $GROUP_ID "
     - PROJECT_ID=$(curl "https://gitlab.eclipse.org/api/v4/groups/$GROUP_ID/projects?search=$DEPENDENCY_NAME" | grep -m1 -oP '"id":\s*\K\d+')
-    - echo "project $DEPENDENCY_NAME id = $PROJECT_ID"
 
+
+    # Check if a branch with the same name exist on the dependance repository
+    - RESPONSE_CODE=$(curl -s -o /dev/null -w "%{http_code}" "https://gitlab.eclipse.org/eclipse/aidge/${DEPENDENCY}/-/tree/${CI_COMMIT_BRANCH}")
+    - >
+      if [ "$RESPONSE_CODE" -eq 404 ] || [ "$CI_MERGE_REQUEST_ID" ]; then
+        echo "default to main branch"
+        curl --location --output build_artifacts.zip "https://gitlab.eclipse.org/api/v4/groups/$GROUP_ID/projects/${PROJECT_ID}/jobs/artifacts/main/download?job=build:ubuntu_cpp"
+      else
+        echo "pull from ${CI_COMMIT_BRANCH}"
+        curl --location --output build_artifacts.zip "https://gitlab.eclipse.org/api/v4/groups/$GROUP_ID/projects/${PROJECT_ID}/jobs/artifacts/${CI_COMMIT_BRANCH}/download?job=${JOB}"
+      fi
 # variables:
 #   MY_CUSTOM_FUNCTION: >
 #     function my_custom_function() {
-- 
GitLab