#!/usr/bin/env bash set -o nounset set -o errexit #set -o xtrace fail() { echo $1 >&2 exit 1 } # yq eval yaml_files=($(find . -name '*.yml' -print)) if [ ${#yaml_files[@]} -gt 0 ]; then # yq eval --exit-status evaluates files returns a non-zero exit status: # override that exit status so this entire script doesn't exit prematurely broken_files=() for f in ${yaml_files[@]}; do yq --exit-status 'tag == "!!map" or tag== "!!seq"' >/dev/null 2>&1 $f || broken_files+=($f) done #echo "${broken_files[@]}" #output=$(printf '%s\n' ${broken_files[@]}) #echo "$output" if [ ${#broken_files[@]} -gt 0 ]; then echo 'The following files appear to contain invalid yaml:' >&2 printf '%s\n' ${broken_files[@]} >&2 exit 1 fi fi