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 a044f28 commit 74cb438
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 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}"
local tmp_dir
tmp_dir=$(mktemp --directory -t=check-jsons-in-file-)
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 74cb438

Please sign in to comment.