Skip to content

Instantly share code, notes, and snippets.

@ssh60
Created November 8, 2016 16:20
Show Gist options
  • Save ssh60/fcbea851aa5e7b621066654da01b6372 to your computer and use it in GitHub Desktop.
Save ssh60/fcbea851aa5e7b621066654da01b6372 to your computer and use it in GitHub Desktop.
Check YAML syntax with shell and python
#!/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