diff --git a/.gitlab/validate.sh b/.gitlab/validate.sh index daf827c2c82b2705dfca38e94b15e2a7ac6b3dc6..201fc52c94f173c55d7f6fbe1c6ea7cbf63c91a8 100755 --- a/.gitlab/validate.sh +++ b/.gitlab/validate.sh @@ -5,7 +5,7 @@ # @copyright 2023-2023 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria, # Univ. Bordeaux. All rights reserved. # -# @version 1.0.0 +# @version 1.2.0 # @author Mathieu Faverge # @author Florent Pruvost # @date 2023-09-22 @@ -34,8 +34,9 @@ if [[ -z $SONARQUBE_LOGIN ]]; then fi if [[ $METRIC == "BUG" ]]; then - BUG=`curl -u $TOKEN: -X GET "https://sonarqube.inria.fr/sonarqube/api/measures/component?component=${CI_PROJECT_NAMESPACE}%3A${CI_PROJECT_NAME}&pullRequest=${CI_MERGE_REQUEST_IID}&metricKeys=new_bugs" |jq '.component.measures[0].period.value' | sed -e "s#\"##g"` - if [[ $BUG > 0 ]]; then + BUG=`curl -u $SONARQUBE_LOGIN: -X GET "https://sonarqube.inria.fr/sonarqube/api/measures/component?component=${CI_PROJECT_NAMESPACE}%3A${CI_PROJECT_NAME}&pullRequest=${CI_MERGE_REQUEST_IID}&metricKeys=new_bugs" |jq '.component.measures[0].period.value' | sed -e "s#\"##g"` + echo "BUG=$BUG" + if [[ $BUG -gt 0 ]]; then echo "%{BUG} new bugs detected by Sonarqube -> Failure." exit 1 else @@ -43,11 +44,12 @@ if [[ $METRIC == "BUG" ]]; then exit 0 fi elif [[ $METRIC == "COVERAGE" ]]; then - COV=`curl -u $TOKEN: -X GET "https://sonarqube.inria.fr/sonarqube/api/measures/component?component=${CI_PROJECT_NAMESPACE}%3A${CI_PROJECT_NAME}&pullRequest=${CI_MERGE_REQUEST_IID}&metricKeys=new_coverage" |jq '.component.measures[0].period.value' | sed -e "s#\"##g"` + COV=`curl -u $SONARQUBE_LOGIN: -X GET "https://sonarqube.inria.fr/sonarqube/api/measures/component?component=${CI_PROJECT_NAMESPACE}%3A${CI_PROJECT_NAME}&pullRequest=${CI_MERGE_REQUEST_IID}&metricKeys=new_coverage" |jq '.component.measures[0].period.value' | sed -e "s#\"##g" | cut -d "." -f 1` + echo "COV=$COV" if [[ $COV == "null" || -z $COV ]]; then echo "Coverage is empty, certainly that there are no lines of new code (considered during the analysis) to compare -> Success." else - if [[ $COV < 80 ]]; then + if [[ $COV -lt 80 ]]; then echo "Coverage on new lines is ${COV}%, which is < 80% -> Failure." exit 1 else