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

Generation config version stage

parent 04f07d2e
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -35,6 +35,21 @@ Validate OpenAPI:
    paths:
      - ${LOGFILE_OPENAPI}
    
Generate config:
  stage: generation
  when: always
  before_script:
    - |
     curl "${CI_API_V4_URL}/projects/57/repository/files/all%2Fgenerate-config%2Esh/raw?ref=master" >> generate-config.sh
    - chmod +x generate-config.sh
  script:
    - echo 'Generate config'
    - ./generate-config.sh $(pwd)
  artifacts:
    name: "$CI_JOB_NAME"
    paths:
      - api-versions.txt
      
CR contribution:
  stage: generation
  when: on_success

all/generate-config.sh

0 → 100644
+55 −0
Original line number Diff line number Diff line
#!/bin/bash
# Copyright ETSI 2021
# See: https://forge.etsi.org/etsi-forge-copyright-statement.txt
echo "------ Content of the folder ------"
ls

# 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

echo "------ Installing necessary node modules -----"

npm install js-yaml
npm install json

pwd
echo "------ Removing old CONFIG file ------"
#rm -f api-versions.txt

echo "------ Generating CONFIG file from all YAML files ------"

echo "------ Switching to $1 folder --------"
#cd $1
#pwd 
fres=0

for i in $1/*.yaml ;  do
	echo "[$i]"
	echo "[$i]" | grep -Po "TS[\w-]+\.yaml" | xargs -I % sh -c 'echo [%]' >> api-versions.txt ;
    node ./node_modules/js-yaml/bin/js-yaml $i > "$i.json" ;
    cat "$i.json" | node ./node_modules/json/lib/json info.version >> api-versions.txt

    input=$(cat "$i.json" | node ./node_modules/json/lib/json externalDocs.description)
    pattern="[0-9]+[.][0-9]+[.][0-9]+"
    if echo $input | grep -qPo $pattern
    then
      echo $input | grep -Po $pattern >> api-versions.txt
    else
      echo "-" >> api-versions.txt
    fi

    # cat "$i.json" | node ./scripts/node_modules/json/lib/json externalDocs.description | grep -Po "[0-9]+[.][0-9]+[.][0-9]+" >> api-versions.txt

    cat "$i.json" | node ./node_modules/json/lib/json info.description | grep -Po "[0-9]{4}" >> api-versions.txt
    res=$?
    fres=$(($fres||$res))
done

# Exit code needed for jenkins to know the verdict of the build
echo "-- Final validator returns $fres."
exit $fres
+1 −1
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@ function validate {
    echo -e "----  Validating $i:  "    
    if [ $RUN_IN_DOCKER == 0 ] ; then
	   bname=$(basename "$1")
       docker run --rm -v $(pwd):"/specs" $DOCKER_IMAGE swagger-cli validate "/specs/$bname"
       docker run --rm -v $(dirname $(realpath $1)):"/specs" $DOCKER_IMAGE swagger-cli validate "/specs/$bname"
    else
        swagger-cli validate "$1"
    fi