Skip to content

Commit

Permalink
NO-JIRA: feat(ci/check-json.sh): ask yq to output each result into a …
Browse files Browse the repository at this point in the history
…separate file, in case json strings are multiline
  • Loading branch information
jiridanek committed Oct 29, 2024
1 parent 001104d commit 01f4e64
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions ci/check-json.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@ function check_json() {
echo "Checking: '${f}' - for '${string}':"

if grep --quiet --extended-regexp "${string}" "${f}"; then
#if $(grep -e "${string}" "${f}"); then
jsons=$(yq -r ".spec.tags[].annotations.\"${string}\"" "${f}")

while IFS= read -r json; do
echo " ${json}"
echo -n " > "; echo "${json}" | json_verify || ret_code="${?}"
done <<< "${jsons}"
tmp_dir=$(mktemp --directory -t=check-jsons-in-file-)
local tmp_dir
tmp_dir=$(mktemp --directory -t check-jsons-in-file-XXXXXXXXXX-)
if ! (cd "${tmp_dir}"; yq --split-exp "\$index" --unwrapScalar ".spec.tags[].annotations.\"${string}\"" "${f}"); then
echo "yq failed to run"
return 1
fi

for json in "${tmp_dir}"/*.yml; do
echo " "; cat "${json}"
echo -n " > "; json_verify < "${json}" || ret_code="${?}"
done
else
echo " Ignoring as this file doesn't contain necessary key field '${string}' for check"
fi
Expand Down

0 comments on commit 01f4e64

Please sign in to comment.