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

Initial commit

parents
Loading
Loading
Loading
Loading
+65 −0
Original line number Original line Diff line number Diff line
# CI/CD:
#
# VALIDATION triggered by:
#  - any (branch commit)
#  
# GENERATION triggered by:
#  - merge request
#   

workflow:
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
    - if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
      when: never
    - if: $CI_COMMIT_BRANCH
    
variables:
  LOGFILE_YANG: "yang-validation.txt"
  LOGFILE_LINT: "yang-linting.txt"
  LOGFILE_OPENAPI: "openapi-validation.txt"

stages:
  - build
  - validation
  - trigger
    
Build container:
  stage: build
  before_script:
    - |
     curl "${CI_API_V4_URL}/projects/$PIPELINES_SCRIPTS_PROJECT_ID/repository/files/api-tests%2Fbuild-container%2Esh/raw?ref=main" >> build-container.sh
    - chmod +x build-container.sh
  script:
    - echo 'Building container'
    - ./build-container.sh   
    
Validate API Robot Test Suite:
  stage: validation
  before_script:
    - |
     curl "${CI_API_V4_URL}/projects/$PIPELINES_SCRIPTS_PROJECT_ID/repository/files/api-tests%2Frun-container%2Esh/raw?ref=main" >> run-container.sh
    - chmod +x run-container.sh
  script:
    - echo 'Validate API Robot Test Suite'
    - ./run-container.sh $(pwd) $CI_COMMIT_BRANCH
  artifacts:
#    name: "OpenAPI validation result"
#    when: always
    paths:
      - build/*.docx
#    expose_as: 'OpenAPI validation result'
    
Run Hivetap Robot:
  stage: trigger
  when: on_success
  only:
    - /^.*fix-plu$/
  before_script:
    - apiTestsVersion=$(echo $CI_COMMIT_BRANCH | cut -d'/' -f 2 | cut -d'-' -f 1)
    - echo apiTestsVersion
  script:
    - echo 'Triggering Hivetap Robot project'
    - |
     curl -X POST -F token=${ROBOT_HIVE_TAP_TT_TOKEN} -F ref=master -F "variables[API_TESTS_VERSION]=$apiTestsVersion" -F "variables[TEST_SUITE]=NFV" "${CI_API_V4_URL}/projects/484/trigger/pipeline"
 No newline at end of file
+36 −0
Original line number Original line Diff line number Diff line
#!/bin/bash
# Copyright ETSI 2019
# See: https://forge.etsi.org/etsi-forge-copyright-statement.txt

#set -e
set -vx

DOCKER_FILE=./scripts/docker/Dockerfile
if [ -f ${DOCKER_FILE} ]
then
    #check and build stf583-rf-validation image
    DOCKER_ID=`docker ps -a | grep -e stf583-rf-validation | awk '{ print $1 }'`
#    if [ ! -z "${DOCKER_ID}" ]
#    then
#        docker rm --force stf583-rf-validation
#    fi
    docker build --tag stf583-rf-validation -f ${DOCKER_FILE} .
    if [ "$?" != "0" ]
    then
        echo "Docker build failed: $?"
        exit -1
    fi
#    docker image ls -a
#    docker inspect stf583-rf-validation:latest
#    if [ "$?" != "0" ]
#    then
#        echo "Docker inspect failed: $?"
#        exit -2
#    fi
#else
#    exit -3
fi

# That's all Floks
exit 0
+18 −0
Original line number Original line Diff line number Diff line
#!/bin/bash
# Copyright ETSI 2019
# See: https://forge.etsi.org/etsi-forge-copyright-statement.txt

#set -e
#set -vx

mkdir -p build

echo "Using git branch $2"

docker run -v "$(pwd)/build:/home/etsi/dev/build" stf583-rf-validation:latest "bash" \
	-c  "/home/etsi/dev/robot/scripts/validate.sh $2"

ret=$? 

exit $ret
+91 −0
Original line number Original line Diff line number Diff line
#!/bin/bash
# Copyright ETSI 2019-2021
# See: https://forge.etsi.org/etsi-forge-copyright-statement.txt

LOGFILE=openapi-validation.txt
DOCKER_IMAGE=etsiforge/swagger-cli:4.0.3

echo -e "\n------ Switching to $1 folder --------"
cd $1

echo "------ Checking for previous logs ------"
if [ -f "$LOGFILE" ] ; then
    echo "Found previous log. Removing it"
    rm "$LOGFILE"
fi

if [ -x "$(command -v docker)" ] ; then
    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
else
    RUN_IN_DOCKER=1
    if [ ! -x "$(command -v swagger-cli)" ] ; then
        echo "Validator swagger-cli not found. Quitting."
        exit 1
    else
        echo "Using local validator ($(which swagger-cli))"
    fi
fi

function validate {
    echo -e "----  Validating $i:  "    
    if [ $RUN_IN_DOCKER == 0 ] ; then
	   bname=$(basename "$1")
       docker run --rm -v $(dirname $(realpath $1)):"/specs" $DOCKER_IMAGE swagger-cli validate "/specs/$bname"
    else
        swagger-cli validate "$1"
    fi
}

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 ./*.yaml ;  do

    MSG=$(validate "$i" 2>&1)
    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" | tee -a $LOGFILE
else
   echo "Some errors found by the OpenAPI validation" | tee -a $LOGFILE
fi

if [ ! "$ERR" == "" ] ; then 
    echo -e "\n---- Errors detected ----" >> $LOGFILE
    echo -e $ERR >> $LOGFILE
fi

echo -e "\n---- Complete log of validation ----" >> $LOGFILE
echo -e $LOG >> $LOGFILE

echo -e "\n------ Content of the folder ------" >> $LOGFILE
ls >> $LOGFILE

if [ ! -s $LOGFILE ] ;then
	rm "$LOGFILE"
else
	echo "To see the full output of the OpenAPI validation, download the archived artifact named '$LOGFILE'."
fi

# Exit code needed for jenkins to know the verdict of the build

exit $fres