Created
May 19, 2021 10:58
-
-
Save codebymikey/e4333692337819fa77bee10524b60795 to your computer and use it in GitHub Desktop.
Find invalid YAML files
This file contains 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
#!/usr/bin/env bash | |
# Script for finding invalid yaml files in the current directory. | |
# Requires the yq script. | |
for program in find yq; do | |
which "$program" > /dev/null || { echo "ERROR: '$program' program could not be found."; exit 1; } | |
done | |
if yq --version 2>/dev/null | grep -E "yq version [4-9]" > /dev/null; then | |
# Support yq 4+ https://mikefarah.gitbook.io/yq/v/v4.x/upgrading-from-v3#validate-documents | |
find . -name '*.yml' -exec sh -c 'yq e "true" "$0" > /dev/null || echo "$0 is invalid"' {} ';'; | |
else | |
find . -name '*.yml' -exec sh -c 'yq validate "$0" || echo "$0 is invalid"' {} ';'; | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment