From d4ec2c105fe1df863a45d119fbc112148f6a9f33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20KUBLER?= <gregoire.kubler@proton.me> Date: Thu, 21 Mar 2024 17:01:12 +0100 Subject: [PATCH] feat : refactor branch to pull --- .gitlab/ci/build.gitlab-ci.yml | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/.gitlab/ci/build.gitlab-ci.yml b/.gitlab/ci/build.gitlab-ci.yml index dee38e74..e93b9df5 100644 --- a/.gitlab/ci/build.gitlab-ci.yml +++ b/.gitlab/ci/build.gitlab-ci.yml @@ -15,6 +15,7 @@ build:ubuntu_cpp: - apt-get -qq install -y jq # Check if a branch with the same name exist on the dependance repository - BRANCH_TO_PULL="dev" # default branch + - set -x - > if [ "$CI_MERGE_REQUEST_ID" ]; then echo "Merge request pipeline detected" @@ -26,16 +27,20 @@ build:ubuntu_cpp: BRANCH_TO_PULL=${CI_MERGE_REQUEST_TARGET_BRANCH_NAME} fi # checking if given branch exist on official repo or on fork - elif [[ $(curl -s -o /dev/null -w "%{http_code}" "https://gitlab.eclipse.org/eclipse/aidge/$DEPENDENCY_NAME/-/tree/$CI_COMMIT_REF_NAME") -ne 404 || $(curl -s -o /dev/null -w "%{http_code}" "https://gitlab.eclipse.org/hrouis/$DEPENDENCY_NAME/-/tree/$CI_COMMIT_REF_NAME") -ne 404 ]]; then + elif [[ $(curl -s -o /dev/null -w "%{http_code}" "https://gitlab.eclipse.org/eclipse/aidge/$DEPENDENCY_NAME/-/tree/$CI_COMMIT_REF_NAME") -ne 404 ]] + PULL_FROM_FORK=FALSE + BRANCH_TO_PULL=$CI_COMMIT_REF_NAME + elif [[$(curl -s -o /dev/null -w "%{http_code}" "https://gitlab.eclipse.org/hrouis/$DEPENDENCY_NAME/-/tree/$CI_COMMIT_REF_NAME") -ne 404 ]]; then + PULL_FROM_FORK=TRUE BRANCH_TO_PULL=$CI_COMMIT_REF_NAME else - echo "No branch \"$CI_COMMIT_REF_NAME\" found for repository \"$DEPENDENCY_NAME\"" + PULL_FROM_FORK=FALSE + echo "No branch \"$CI_COMMIT_REF_NAME\" found for \"$DEPENDENCY_NAME\" in official or forked repos." fi - echo "Pulling from branch:\"$BRANCH_TO_PULL\"" - # Check group namespace is valid, if it is then we are in the official project(aidge group id=6437), otherwise we pull from the fork - # nominal case : we are in the official project + - set +x - > - if [ "$(curl -s -o /dev/null -w "%{http_code}" "https://gitlab.eclipse.org/api/v4/groups/${CI_PROJECT_NAMESPACE_ID}")" != "404" ]; then + if [[ ! $PULL_FROM_FORK ]]; then # nominal case : we are in the official project DEPENDENCY_ID=$(curl "https://gitlab.eclipse.org/api/v4/groups/${CI_PROJECT_NAMESPACE_ID}/projects?search=${DEPENDENCY_NAME}" | jq -r '.[0].id') else # case for fork echo "Retrieving build_artifacts from hrouis' forked project." -- GitLab