Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
gitlab_shared_files
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Eclipse Projects
aidge
gitlab_shared_files
Commits
a932a83c
Commit
a932a83c
authored
1 year ago
by
Grégoire Kubler
Browse files
Options
Downloads
Patches
Plain Diff
feature : rework of the dowload dependencies script, now supports handling of forks
parent
e4f652aa
No related branches found
No related tags found
1 merge request
!2
Fix/ci fork exec
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
.gitlab/ci/shared_script.gitlab-ci.yml
+45
-18
45 additions, 18 deletions
.gitlab/ci/shared_script.gitlab-ci.yml
with
45 additions
and
18 deletions
.gitlab/ci/shared_script.gitlab-ci.yml
+
45
−
18
View file @
a932a83c
...
@@ -4,10 +4,11 @@
...
@@ -4,10 +4,11 @@
# - DEPENDENCY_NAME: Name of the dependency project
# - DEPENDENCY_NAME: Name of the dependency project
# - DEPENDENCY_JOB: Name of the dependency job from which you want to pull artifacts
# - DEPENDENCY_JOB: Name of the dependency job from which you want to pull artifacts
script
:
script
:
-
apt-get -qq install -y jq
# Check if a branch with the same name exist on the dependency repository
-
BRANCH_TO_PULL="dev"
# default branch
-
BRANCH_TO_PULL="dev"
# default branch
# Check if a branch with the same name exist on the dependance repository
-
>
-
>
if [ "$CI_MERGE_REQUEST_ID" ]; then
if [ "$CI_MERGE_REQUEST_ID" ]; then
# CASE MERGE REQUEST
echo "Merge request pipeline detected"
echo "Merge request pipeline detected"
if [ $(curl -s -o /dev/null -w "%{http_code}" "https://gitlab.eclipse.org/eclipse/aidge/$DEPENDENCY_NAME/-/tree/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME") -eq 404 ]; then
if [ $(curl -s -o /dev/null -w "%{http_code}" "https://gitlab.eclipse.org/eclipse/aidge/$DEPENDENCY_NAME/-/tree/$CI_MERGE_REQUEST_TARGET_BRANCH_NAME") -eq 404 ]; then
echo "Pull from default"
echo "Pull from default"
...
@@ -16,29 +17,55 @@
...
@@ -16,29 +17,55 @@
echo "Pull from ${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}"
echo "Pull from ${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}"
BRANCH_TO_PULL=${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}
BRANCH_TO_PULL=${CI_MERGE_REQUEST_TARGET_BRANCH_NAME}
fi
fi
elif [ $(curl -s -o /dev/null -w "%{http_code}" "https://gitlab.eclipse.org/eclipse/aidge/$DEPENDENCY_NAME/-/tree/$CI_COMMIT_REF_NAME") -eq 404 ]; then
else # CASE CASUAL COMMIT
echo "Pull from default"
# checking if given branch exist on official repo or on fork
else
if [[ $(curl -s -o /dev/null -w "%{http_code}" "https://gitlab.eclipse.org/eclipse/aidge/$DEPENDENCY_NAME/-/tree/$CI_COMMIT_REF_NAME") -ne 302 ]]; then
# Pulling from branch with same name
PULL_FROM_FORK=FALSE
echo "Pull from branch name"
BRANCH_TO_PULL=$CI_COMMIT_REF_NAME
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 302 ]]; then
PULL_FROM_FORK=TRUE
BRANCH_TO_PULL=$CI_COMMIT_REF_NAME
else
PULL_FROM_FORK=FALSE
echo "No branch \"$CI_COMMIT_REF_NAME\" found for \"$DEPENDENCY_NAME\" in official or forked repos."
fi
fi
fi
-
apt-get install -y jq
-
echo "Pulling from branch:\"$BRANCH_TO_PULL\""
# Check group namespace is valid, if not DEPENDENCY_ID=6437 (aidge group ID)
-
>
-
>
if [ $(curl -s -o /dev/null -w "%{http_code}" "https://gitlab.eclipse.org/api/v4/groups/${CI_PROJECT_NAMESPACE_ID}") -eq 404 ]; then
if [[ ! $PULL_FROM_FORK ]]; then # nominal case : we are in the official project
echo "Using aidge group id by default"
DEPENDENCY_ID=$(curl "https://gitlab.eclipse.org/api/v4/groups/6437/projects?search=${DEPENDENCY_NAME}" | jq -r '.[0].id')
else
DEPENDENCY_ID=$(curl "https://gitlab.eclipse.org/api/v4/groups/${CI_PROJECT_NAMESPACE_ID}/projects?search=${DEPENDENCY_NAME}" | jq -r '.[0].id')
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."
USER_ID=17216
DEPENDENCY_ID=$(curl --header "PRIVATE_TOKEN: $CI_JOB_TOKEN" "https://gitlab.eclipse.org/api/v4/users/${USER_ID}/projects?search=${DEPENDENCY_NAME}" | jq -r '.[0].id')
fi
fi
-
echo "Project ID for ${DEPENDENCY_NAME} is ${DEPENDENCY_ID}"
-
echo "curling from https://gitlab.eclipse.org/api/v4/projects/$DEPENDENCY_ID/jobs/artifacts/$BRANCH_TO_PULL/download?job=$DEPENDENCY_JOB"
# Retrieve latest successful $DEPENDENCY_JOB $BRANCH_TO_PULL
-
curl -f --location --output build_artifacts.zip "https://gitlab.eclipse.org/api/v4/projects/$DEPENDENCY_ID/jobs/artifacts/$BRANCH_TO_PULL/download?job=$DEPENDENCY_JOB"
-
PIPELINES=$(curl -s --header "PRIVATE_TOKEN:$CI_JOB_TOKEN" "https://gitlab.eclipse.org/api/v4/projects/$DEPENDENCY_ID/pipelines?ref=${BRANCH_TO_PULL}&order_by=updated_at&sort=desc")
-
JOB_ID=-1
# handle case where there is no branch with the same name
-
>
for i in $(seq 0 $(jq length <<< "$PIPELINES")); do
PIPELINE_ID=$(jq --argjson idx $i '.[$idx].id' <<< $PIPELINES)
JOBS=$(curl -s --header "PRIVATE_TOKEN: $CI_JOB_TOKEN" "https://gitlab.eclipse.org/api/v4/projects/$DEPENDENCY_ID/pipelines/$PIPELINE_ID/jobs" | jq --arg job_name "$DEPENDENCY_JOB" 'map(select((.name == $job_name) and (.status == "success")))')
if [[ $(jq '. | length' <<< $JOBS) > 0 ]]; then
JOB_ID=$(jq '.[0].id' <<< $JOBS)
break
fi
done
-
>
if( $JOB_ID == -1 ) ; then
echo "ERROR : no successful job \"$DEPENDENCY_JOB\" found in branch \"$BRANCH_TO_PULL\" for project \"$DEPENDENCY_NAME\""
else
echo "Successful job \"$DEPENDENCY_JOB\" found in branch \"$BRANCH_TO_PULL\" for project \"$DEPENDENCY_NAME\""
fi
-
echo "curling from \"https://gitlab.eclipse.org/api/v4/projects/$DEPENDENCY_ID/jobs/$JOB_ID/artifacts\""
-
curl --location --output build_artifacts.zip --header "PRIVATE_TOKEN:$CI_JOB_TOKEN" "https://gitlab.eclipse.org/api/v4/projects/$DEPENDENCY_ID/jobs/$JOB_ID/artifacts"
-
unzip -q -o build_artifacts.zip -d .
-
unzip -q -o build_artifacts.zip -d .
-
rm -rf build_cpp
-
rm -rf build_cpp
.download_dependency_windows
:
.download_dependency_windows
:
# Note:
# Note:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment