From 01f4e64e475e0be4b2008a1ad13e356aaacbcc41 Mon Sep 17 00:00:00 2001 From: Jiri Danek Date: Tue, 29 Oct 2024 13:51:57 +0100 Subject: [PATCH] NO-JIRA: feat(ci/check-json.sh): ask yq to output each result into a separate file, in case json strings are multiline --- ci/check-json.sh | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/ci/check-json.sh b/ci/check-json.sh index 175af19f6..c81d9c9b2 100755 --- a/ci/check-json.sh +++ b/ci/check-json.sh @@ -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