Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 7e1b59dc authored by Mathieu Faverge's avatar Mathieu Faverge
Browse files

ci: Add precheck to merge_request builds

parent 5ee23704
No related branches found
No related tags found
1 merge request!293CI: Add precheck to merge_request builds
#!/usr/bin/env bash
success=1
check_rebase()
{
hash_master=$(git show-ref -s origin/master)
hash_common=$(git merge-base origin/master ${CI_COMMIT_SHA})
if [ "${hash_master}" = "${hash_common}" ]
then
echo "check_rebase: OK"
return 0
else
echo "check_rebase: Rebase is required"
success=0
return 1
fi
}
check_draft()
{
if [ "${CI_PIPELINE_SOURCE}" = "merge_request_event" ]
then
draft=$( echo ${CI_MERGE_REQUEST_TITLE} | sed "s/^Draft.*$/Draft/" )
wip=$( echo ${CI_MERGE_REQUEST_TITLE} | sed "s/^WIP.*$/WIP/" )
if [ "$draft" = "Draft" ]
then
echo "check_draft: Merge request is in draft mode"
success=0
return 1
fi
if [ "$wip" = "WIP" ]
then
echo "check_draft: Merge request is in WIP"
success=0
return 1
fi
# if [ "${CI_MERGE_REQUEST_APPROVED}" != "true" ]
# then
# echo "check_approval: Merge request not yet approved"
# success=0
# return 1
# fi
echo "check_draft: Merge request is ok"
fi
return 0
}
echo "----------------------------------------------------"
check_rebase
echo ""
echo "----------------------------------------------------"
check_draft
echo ""
echo "----------------------------------------------------"
echo " Checking file headers: "
TOOLSDIR=$(dirname $0)/../tools
$TOOLSDIR/check_header.sh
rc=$?
if [ $rc -eq 0 ]
then
echo "Check header: SUCCESS"
else
echo "Check header: FAILED"
success=0
fi
if [ $success -eq 0 ]
then
exit 1
# We could cancel the job, but then the log is not pushed in time to the web interface
#curl --request POST --header "PRIVATE-TOKEN: ${PIPELINE_TOKEN}" "https://gitlab.inria.fr/api/v4/projects/$CI_PROJECT_ID/pipelines/$CI_PIPELINE_ID/cancel"
fi
...@@ -21,6 +21,14 @@ ...@@ -21,6 +21,14 @@
except: except:
- schedules - schedules
preliminary_checks:
image: registry.gitlab.inria.fr/solverstack/docker/distrib
stage: .pre
script:
- .gitlab/check_ci.sh
only:
- merge_requests
.build_script_template: .build_script_template:
extends: .only-branches extends: .only-branches
stage: build stage: build
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
# #
#!/usr/bin/env sh #!/usr/bin/env sh
header=1 header=1
nberr=0
print_header() print_header()
{ {
...@@ -45,6 +46,7 @@ check_header_file() ...@@ -45,6 +46,7 @@ check_header_file()
then then
print_header $filename print_header $filename
echo -n "@file line missing or incorrect:"; grep "@file" $filename; echo "" echo -n "@file line missing or incorrect:"; grep "@file" $filename; echo ""
nberr=$(( nberr + 1 ))
fi fi
fi fi
} }
...@@ -74,6 +76,7 @@ check_header_version() ...@@ -74,6 +76,7 @@ check_header_version()
then then
print_header $filename print_header $filename
echo -n "@version line missing or incorrect:"; grep "@version" $filename; echo ""; echo -n "@version line missing or incorrect:"; grep "@version" $filename; echo "";
nberr=$(( nberr + 1 ))
fi fi
} }
...@@ -87,6 +90,7 @@ check_header_author() ...@@ -87,6 +90,7 @@ check_header_author()
then then
print_header $filename print_header $filename
echo "@author line missing"; echo "@author line missing";
nberr=$(( nberr + 1 ))
fi fi
} }
...@@ -100,6 +104,7 @@ check_header_date() ...@@ -100,6 +104,7 @@ check_header_date()
then then
print_header $filename print_header $filename
echo -n "@date line missing or incorrect"; grep "@date" $filename; echo ""; echo -n "@date line missing or incorrect"; grep "@date" $filename; echo "";
nberr=$(( nberr + 1 ))
fi fi
} }
...@@ -137,6 +142,7 @@ check_header_define() ...@@ -137,6 +142,7 @@ check_header_define()
grep "#ifndef" $filename grep "#ifndef" $filename
grep "#define" $filename grep "#define" $filename
grep "#endif" $filename grep "#endif" $filename
nberr=$(( nberr + 1 ))
fi fi
;; ;;
*) *)
...@@ -197,3 +203,11 @@ do ...@@ -197,3 +203,11 @@ do
check_header $f check_header $f
done done
if [ $nberr -gt 0 ]
then
echo "${nberr} mistakes have been found in the header files."
exit 1
else
exit 0
fi
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment