Commit 54b4f8e9 authored by Miguel Angel Reina Ortega's avatar Miguel Angel Reina Ortega
Browse files

Moving validation loop into docker

parent 49269a88
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -25,11 +25,12 @@ Validate OpenAPI:
  stage: validation
  before_script:
    - |
     curl "${CI_API_V4_URL}/projects/57/repository/files/all%2Fvalidate-all%2Esh/raw?ref=master" >> validate-all.sh
    - chmod +x validate-all.sh
     curl "${CI_API_V4_URL}/projects/57/repository/files/all%2Fvalidate-all-in-docker%2Esh/raw?ref=master" >> validate-all-in-docker.sh
    - chmod +x validate-all-in-docker.sh
  script:
    - echo 'Validate OpenAPI'
    - ./validate-all.sh $(pwd)
    - docker run --rm -v $(pwd):"/specs" etsiforge/swagger-cli:4.0.3 /bin/sh -c "sh specs/validate-all-in-docker.sh"
    #- ./validate-all.sh $(pwd)
  artifacts:
    name: "$CI_JOB_NAME"
    paths:
+47 −0
Original line number Diff line number Diff line
#!/bin/sh
# Copyright ETSI 2019-2021
# See: https://forge.etsi.org/etsi-forge-copyright-statement.txt
LOGFILE=openapi-validation.log
echo -e "\n------ Validating all YAML files (may takes several minutes) ------"
# If there are no YAML file, simply exit
ls | grep -q yaml
found_yaml=$?
if [ ! $found_yaml ]
then
    echo "-- No YAML files."
    exit 0
fi
fres=0
LOG=""
ERR=""
for i in specs/*.yaml
do
    #echo -e "----  Validating $i ...  "
	swagger-cli validate "$i"
    #MSG=$(validate "$i" 2>&1)
	#echo "$MSG"
    res=$?
    # if [ ! $res == 0 ] ; then 
        # ERR="$ERR$MSG\n"
    # fi 
    # LOG="$LOG$MSG\n"
    fres=$(($fres||$res))
done
echo -e "\n-- Final validator returns $fres." | tee -a $LOGFILE
if [ $fres == 0 ]
then
   echo "No errors found, all files validate the OpenAPI definition. Below the complete log." | tee -a $LOGFILE
else
   echo "Some errors found, see below the details." | tee -a $LOGFILE
fi
if [ ! "$ERR" == "" ]
then
    echo -e "\n---- Errors detected ----" | tee -a $LOGFILE
    echo -e $ERR  | tee -a $LOGFILE
fi
echo -e "\n---- Complete log of validation ----" | tee -a $LOGFILE
echo -e $LOG | tee -a $LOGFILE
#echo -e "\n------ Content of the folder ------" | tee -a $LOGFILE
#ls | tee -a $LOGFILE
# Exit code needed for jenkins to know the verdict of the build
exit $fres
+1 −1
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@ if [ -f "$LOGFILE" ] ; then
fi

if [ -x "$(command -v docker)" ] ; then
    RUN_IN_DOCKER=1
    RUN_IN_DOCKER=0
    echo "Using dockerized validator ($DOCKER_IMAGE)"
    docker pull "$DOCKER_IMAGE"
	#docker pull -q "$DOCKER_IMAGE" --> Pull quietly only from Ubuntu 20.04