Created
November 8, 2016 16:20
-
-
Save ssh60/fcbea851aa5e7b621066654da01b6372 to your computer and use it in GitHub Desktop.
Check YAML syntax with shell and python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set +e | |
declare -i RESULT=0 | |
if [ -z $1 ] ; then | |
echo "Usage $0 <directory to check>" | |
exit 1 | |
fi | |
YAML_PATH_LIST=$(find $1 -type f -name "*.yaml") | |
if [ -z "$YAML_PATH_LIST" ] ; then | |
echo 'Nothing to check' | |
exit 0 | |
else | |
echo -e "YAML files to check syntax:\n$YAML_PATH_LIST" | |
fi | |
for YAML_PATH in $YAML_PATH_LIST ; do | |
python -c "import yaml; stream = open(\"${YAML_PATH}\", 'r'); yaml.load(stream)" | |
RESULT+=$? | |
done | |
exit $RESULT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment