diff --git a/all/.gitlab-ci.yml b/all/.gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..b8c6c571cf285f0f5406abb4ec1cba9e67e06136 --- /dev/null +++ b/all/.gitlab-ci.yml @@ -0,0 +1,76 @@ +# CI/CD: +# +# VALIDATION triggered by: +# - any (branch commit) +# +# GENERATION triggered by: +# - any (branch commit) for Generate config +# - merge request for CR contribution +# + +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_OPENAPI: "openapi-validation.log" + GIT_CLEAN_FLAGS: -ffdxq + +stages: + - validation + - generation + +Validate OpenAPI: + stage: validation + before_script: + - | + 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' + - docker run --rm -v $(pwd):"/specs" etsiforge/swagger-cli:4.0.3 /bin/sh -c "sh specs/validate-all-in-docker.sh" + artifacts: + name: "$CI_JOB_NAME" + 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 $ + artifacts: + name: "$CI_JOB_NAME" + paths: + - api-versions.txt + +CR contribution: + stage: generation + when: on_success + only: + - merge_requests + before_script: + - | + curl "${CI_API_V4_URL}/projects/57/repository/files/all%2Fgenerate_changemarks%2Esh/raw?ref=master" >> generate_changemarks.sh + - chmod +x generate_changemarks.sh + # - | + # curl "${CI_API_V4_URL}/projects/57/repository/files/all%2Fall_delimiter_start%2Edocx/raw?ref=master" >> all_delimiter_start.docx + # - | + # curl "${CI_API_V4_URL}/projects/57/repository/files/all%2Fall_delimiter_end%2Edocx/raw?ref=master" >> all_delimiter_end.docx + script: + - echo 'CR contribution' + - mkdir docs + - ./generate_changemarks.sh ${CI_PROJECT_URL} ${CI_MERGE_REQUEST_PROJECT_ID} ${CI_MERGE_REQUEST_IID} + #- ./generate_changemarks.sh ${CI_PROJECT_URL} ${CI_MERGE_REQUEST_PROJECT_ID} ${CI_MERGE_REQUEST_IID} all_delimiter_start.docx all_delimiter_end.docx + artifacts: + paths: + - docs/ + expose_as: 'Word document contribution' \ No newline at end of file diff --git a/all/generate-config.sh b/all/generate-config.sh new file mode 100644 index 0000000000000000000000000000000000000000..93d01618a0eed165a7b24abd17a911b1d787b170 --- /dev/null +++ b/all/generate-config.sh @@ -0,0 +1,58 @@ +#!/bin/bash +# Copyright ETSI 2021 +# See: https://forge.etsi.org/etsi-forge-copyright-statement.txt +# 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 + +echo "------ Generating CONFIG file from all YAML files ------" +fres=0 + +for i in *.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 + + #node ./node_modules/js-yaml/bin/js-yaml $i|node ./node_modules/json/lib/json info.version externalDocs.description info.description |grep -Po "[0-9]+[.][0-9]+[.][0-9]+|[0-9]{4}" >>api-versions.txt + FILE="${i}" + INFO_VERSION=`sed -n '/^info:/,/^[^[:space:]]/{/^ version:/p;/^[^([:space:]|info:)]/q}' ${FILE} | grep -Po '([0-9]+\.){2}[0-9]+'` #>> api-versions.txt #Info version + if [ "$INFO_VERSION" == "" ]; then + echo "-" >>api-versions.txt + else + echo $INFO_VERSION >> api-versions.txt + fi + EXT_DOC_VERSION=`sed -n '/^externalDocs:/,/^[^[:space:]]/{/^ description:/,/^[^[:space:]]/p;/^[^([:space:]|externalDocs:)]/q}' ${FILE} | grep -Po '([0-9]+\.){2}[0-9]+'` # >> api-versions.txt # EXT_DOC_VERSION + if [ "$EXT_DOC_VERSION" == "" ]; then + echo "-" >>api-versions.txt + else + echo $EXT_DOC_VERSION >> api-versions.txt + fi + sed -n '/^info:/,/^[^[:space:]]/{/^ description:/,/^[^[:space:]]/p;/^[^([:space:]|info:)]/q}' ${FILE} | grep -Po '[0-9]{4}' >> api-versions.txt + + res=$? + fres=$(($fres||$res)) +done +exit $fres diff --git a/all/generate_changemarks.sh b/all/generate_changemarks.sh new file mode 100644 index 0000000000000000000000000000000000000000..86c44ba84122e04eea726f27f4eada1b0fc085e0 --- /dev/null +++ b/all/generate_changemarks.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +DOCKER_IMAGE=forge.3gpp.org:5050/tools/3gpp-scripts/forgelib:v2.0.0 + +echo "\n------ Checking for docker image --------" +docker pull "$DOCKER_IMAGE" + +echo "------ Removing previous outputs --------" +rm **/*.docx + +echo "------ Parsing repo URL --------" + +HOST_URL=$(echo $1 | cut -d'/' -f 1-3) +PROJECT_NAME=$(echo $1 | cut -d'/' -f 5- | cut -d'.' -f 1) +echo "HOST URL:" $HOST_URL +echo "PROJECT NAME:" $PROJECT_NAME +echo "PROJECT ID:" $2 +echo "MERGE IID:" $3 + +echo "\n------ Generating change marks --------" +docker container run --rm -v $(pwd):/tmp/ "$DOCKER_IMAGE" forgelib-changedocs -vv --outPath=/tmp/docs "$HOST_URL" "$2" "$PROJECT_NAME" "$3" +#docker container run --rm -v $(pwd):/tmp/ "$DOCKER_IMAGE" forgelib-changedocs -vv --combine --outPath=/tmp/docs --startdelimiter "/tmp/$4" --enddelimiter "/tmp/$5" "$HOST_URL" "$2" "$PROJECT_NAME" "$3" + +exit 0 + diff --git a/all/validate-all-in-docker.sh b/all/validate-all-in-docker.sh new file mode 100644 index 0000000000000000000000000000000000000000..eec5d0d9379c861950ba5511adc46caae25c5180 --- /dev/null +++ b/all/validate-all-in-docker.sh @@ -0,0 +1,52 @@ +#!/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 ... " + MSG=$(swagger-cli validate "$i" 2>&1) + #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 ----" >> $LOGFILE +echo -e $LOG >> $LOGFILE + +# 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 +mv $LOGFILE specs/ +# Exit code needed for jenkins to know the verdict of the build +exit $fres \ No newline at end of file diff --git a/all/validate-all.sh b/all/validate-all.sh new file mode 100644 index 0000000000000000000000000000000000000000..038fc4aa2537f03dcf371096908f91915054fa0b --- /dev/null +++ b/all/validate-all.sh @@ -0,0 +1,85 @@ +#!/bin/bash +# Copyright ETSI 2019-2021 +# See: https://forge.etsi.org/etsi-forge-copyright-statement.txt + +LOGFILE=openapi-validation.log +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 { + 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 + echo -e "---- Validating $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 diff --git a/sa5/.gitlab-ci.yml b/sa5/.gitlab-ci.yml new file mode 100644 index 0000000000000000000000000000000000000000..424b09bbd326ebce777f2b99100a71718ef3597b --- /dev/null +++ b/sa5/.gitlab-ci.yml @@ -0,0 +1,92 @@ +# CI/CD: +# +# RESOLVE triggered by: +# - any (branch commit) +# 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.log" + LOGFILE_LINT: "yang-linting.log" + LOGFILE_OPENAPI: "openapi-validation.log" + +stages: + - validation + - generation + +YANG Strict: + stage: validation + before_script: + - | + curl "${CI_API_V4_URL}/projects/57/repository/files/sa5%2Fvalidate-data-models%2Esh/raw?ref=master" >> validate-data-models.sh + - chmod +x validate-data-models.sh + script: + - echo 'YANG Strict' + - ./validate-data-models.sh . + after_script: + - ls + artifacts: + name: "YANG strict validation result" + paths: + - ${LOGFILE_YANG} + +YANG 3GPP Checks: + stage: validation + before_script: + - | + curl "${CI_API_V4_URL}/projects/57/repository/files/sa5%2Flint-data-models%2Esh/raw?ref=master" >> lint-data-models.sh + - chmod +x lint-data-models.sh + script: + - echo 'YANG 3GPP Checks' + - ./lint-data-models.sh . + artifacts: + name: "YANG 3gpp style check result" + paths: + - ${LOGFILE_LINT} + +Validate OpenAPI: + stage: validation + before_script: + - | + curl "${CI_API_V4_URL}/projects/57/repository/files/sa5%2Fvalidate-all%2Esh/raw?ref=master" >> validate-all.sh + - chmod +x validate-all.sh + script: + - echo 'Validate OpenAPI' + - ./validate-all.sh ./OpenAPI + artifacts: + name: "OpenAPI validation result" + paths: + - ./OpenAPI/${LOGFILE_OPENAPI} + +Word CR text: + stage: generation + when: on_success + only: + - merge_requests + before_script: + - | + curl "${CI_API_V4_URL}/projects/57/repository/files/sa5%2Fgenerate_changemarks%2Esh/raw?ref=master" >> generate_changemarks.sh + - chmod +x generate_changemarks.sh + - | + curl "${CI_API_V4_URL}/projects/57/repository/files/sa5%2Fsa5_delimiter_start%2Edocx/raw?ref=master" >> sa5_delimiter_start.docx + - | + curl "${CI_API_V4_URL}/projects/57/repository/files/sa5%2Fsa5_delimiter_end%2Edocx/raw?ref=master" >> sa5_delimiter_end.docx + script: + - echo 'CR contribution' + - mkdir docs + - ./generate_changemarks.sh ${CI_PROJECT_URL} ${CI_MERGE_REQUEST_PROJECT_ID} ${CI_MERGE_REQUEST_IID} sa5_delimiter_start.docx sa5_delimiter_end.docx + artifacts: + paths: + - docs/ + expose_as: 'Word CR text' \ No newline at end of file diff --git a/sa5/generate_changemarks.sh b/sa5/generate_changemarks.sh new file mode 100755 index 0000000000000000000000000000000000000000..1658fad08066bf95647a1d6a840ab0a0227897e6 --- /dev/null +++ b/sa5/generate_changemarks.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +DOCKER_IMAGE=forge.3gpp.org:5050/tools/3gpp-scripts/forgelib:v2.0.0 + +echo "\n------ Checking for docker image --------" +docker pull "$DOCKER_IMAGE" + +echo "------ Removing previous outputs --------" +rm **/*.docx + +echo "------ Parsing repo URL --------" + +HOST_URL=$(echo $1 | cut -d'/' -f 1-3) +PROJECT_NAME=$(echo $1 | cut -d'/' -f 5- | cut -d'.' -f 1) +echo "HOST URL:" $HOST_URL +echo "PROJECT NAME:" $PROJECT_NAME +echo "PROJECT ID:" $2 +echo "MERGE IID:" $3 + +echo "\n------ Generating change marks --------" +docker container run --rm -v $(pwd):/tmp/ "$DOCKER_IMAGE" forgelib-changedocs -vv --combine --outPath=/tmp/docs --startdelimiter "/tmp/$4" --enddelimiter "/tmp/$5" "$HOST_URL" "$2" "$PROJECT_NAME" "$3" + +exit 0 + diff --git a/sa5/lint-data-models.sh b/sa5/lint-data-models.sh new file mode 100755 index 0000000000000000000000000000000000000000..b9d8b4ff79f8135ebc31bd7c796ded5989aff36f --- /dev/null +++ b/sa5/lint-data-models.sh @@ -0,0 +1,81 @@ +#!/bin/bash +# Copyright ETSI 2020 + +LOGFILE=yang-linting.log +DOCKER_IMG=etsiforge/pyang:2.4.0-3gpp-d410f57 + +echo "------ Switching to $1 folder --------" +cd $1 + +echo "------ Content of the folder ------" +ls + +echo "------ Checking for previous logs ------" +if [ -f "$LOGFILE" ] ; then + echo "Found previous log. Removing it" + rm "$LOGFILE" +fi + +echo "------ Linting modified YANG files ------" +# If there are no YANG, JSON or XML files, then simply exit +ls | grep -q 'yang' +found_data_models=$? +if [ ! $found_data_models ] ; then + echo "-- No YANG files." + exit 0 +fi + +echo "------ pyYANG Version ------" +docker run --rm -v $(pwd)/yang-models:/yang "${DOCKER_IMG}" pyang --version + +echo "------ Linting modified YANG files ------" +# Display all errors and warnings to the user. Errors are allowed. +docker pull -q "${DOCKER_IMG}" +# Linting only yang files that have changed in last commit +files_changed=`git log --raw -n 1 |grep "^:.*yang-models/.*yang"| cut -d '/' -f 2` +echo $files_changed +external_files_changed=`git log --raw -n 1 |grep "^:.*yang-models/external-yams/.*yang"| cut -d '/' -f 2` +echo $external_files_modified +if [ -d "changed-yang-models" ]; then + echo "Removing changed-yang-models dir" + rm -rf "changed-yang-models" +fi +mkdir changed-yang-models +mkdir changed-yang-models/external-yams +if [ ! -z "$files_changed" ] ; then + cd yang-models + cp $files_changed ../changed-yang-models/ + cd .. +fi + +if [ ! -z "$external_files_changed" ] ; then + cd yang-models/external-yams + cp $external_files_changed ../changed-yang-models/external-yams + cd ../.. +fi + +if [ ! -z "$files_changed" ] || [ ! -z "$external_files_changed" ] ; then + docker run --rm -v $(pwd):/yang "${DOCKER_IMG}" "/bin/sh" -c 'pyang --3gpp -p yang-models -p yang-models/external-yams changed-yang-models/*.yang' 2>>$LOGFILE >>$LOGFILE + ret=$? +else + echo "-- No YANG files modified." + exit 0 +fi + +#Validate all yang files +#docker run --rm -v $(pwd)/yang-models:/yang "${DOCKER_IMG}" "/bin/sh" -c 'pyang --3gpp -p external-yams _3gpp-*.yang' 2>>$LOGFILE >>$LOGFILE +#ret=$? + +echo "Output of Linting commad saved to $LOGFILE." + +echo "------ Linting result ------" +echo $ret + +if [ $ret == 1 ] ; then + echo "Some issues were collected by the linter, but they are treated as warnings and are not failing the validation." + echo "To see the full output of the linter, download the archived artifact named '$LOGFILE'." +fi + +# exit $ret +exit 0 + diff --git a/sa5/sa5_delimiter_end.docx b/sa5/sa5_delimiter_end.docx new file mode 100644 index 0000000000000000000000000000000000000000..1e8210e0b75e4314214a21abc77bc44fea8c4d3b Binary files /dev/null and b/sa5/sa5_delimiter_end.docx differ diff --git a/sa5/sa5_delimiter_start.docx b/sa5/sa5_delimiter_start.docx new file mode 100644 index 0000000000000000000000000000000000000000..d1a6ca2ed299f4bebefdf91f448edffe0a57bcc8 Binary files /dev/null and b/sa5/sa5_delimiter_start.docx differ diff --git a/sa5/validate-all.sh b/sa5/validate-all.sh new file mode 100755 index 0000000000000000000000000000000000000000..4c35f43d90dada91cdbffb995a7ea020d12050be --- /dev/null +++ b/sa5/validate-all.sh @@ -0,0 +1,85 @@ +#!/bin/bash +# Copyright ETSI 2019-2021 +# See: https://forge.etsi.org/etsi-forge-copyright-statement.txt + +LOGFILE=openapi-validation.log +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. 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 diff --git a/sa5/validate-data-models.sh b/sa5/validate-data-models.sh new file mode 100755 index 0000000000000000000000000000000000000000..eca92e3c28e5fe6b99c6d53f2c7784e74ea2ffbd --- /dev/null +++ b/sa5/validate-data-models.sh @@ -0,0 +1,41 @@ +#!/bin/bash +# Copyright ETSI 2020 + +LOGFILE=yang-validation.log +DOCKER_IMG=etsiforge/pyang:2.4.0-3gpp-d410f57 + +echo "------ Switching to $1 folder --------" +cd $1 + +echo "------ Content of the folder ------" +ls + +echo "------ Checking for previous logs ------" +if [ -f "$LOGFILE" ] ; then + echo "Found previous log. Removing it" + rm "$LOGFILE" +fi + +echo "------ Validating modified YANG files ------" +# If there are no YANG, JSON or XML files, then simply exit +ls | grep -q 'yang' +found_data_models=$? +if [ ! $found_data_models ] ; then + echo "-- No YANG files." + exit 0 +fi + +# This must run error-free and must display all warnings to the user +docker pull -q "${DOCKER_IMG}" +#Validate all yang files +docker run --rm -v $(pwd)/yang-models:/yang "${DOCKER_IMG}" "/bin/sh" -c 'pyang --strict -p external-yams *.yang' 2>>$LOGFILE >>$LOGFILE +ret=$? + +cat $LOGFILE + +if [ $ret == 0 ] ; then + echo "No errors found by pyang --strict validation." +fi + +exit $ret +