From 9354b0f8c7a0cb8ff7cea8a5f80a8149e83cdae9 Mon Sep 17 00:00:00 2001 From: Leandro Mendes Date: Thu, 27 Jul 2023 11:20:35 +0200 Subject: [PATCH] more fixes and improvementes --- .../file-updates-process-file-updates-task.yaml | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/internal-services/catalog/file-updates-process-file-updates-task.yaml b/internal-services/catalog/file-updates-process-file-updates-task.yaml index 9499734..882080e 100644 --- a/internal-services/catalog/file-updates-process-file-updates-task.yaml +++ b/internal-services/catalog/file-updates-process-file-updates-task.yaml @@ -73,24 +73,29 @@ spec: git_clone_and_checkout --repository $REPO --revision $REVISION for file in ${FILES}; do + # in case the file has comments, empty newlines and other special chages in the + # start of the file we need to know where the actual yaml data starts + blankLines=`awk '/[[:alpha:]]+/{ if(! match($0, "^#")) { print NR-1; exit } }' $file` + jq -cr ".paths[] | select(.path==\"${file}\") | .replacements[] | [.key, .replacement] | join(\"\t\")" $TEMP| \ while read replacement; do IFS=$'\t' read KEY REPLACE <<< $replacement - # the key position + # getting the key's position echo -en "Searching for key \`${KEY}\`: " - LN=`yq "${KEY} | line" $file` - if [ "${LN}" == 0 ]; then + foundAt=`yq "${KEY} | line" $file` + if [ "${foundAt}" -eq 0 ]; then echo "NOT FOUND" continue fi echo "FOUND" - # yq always gives the pos -1 line, so we add it - LINES=$(expr `yq "${KEY}" $file |wc -l` + 1) + # getting the value size (in number of lines) + valueSize=$(expr `yq "${KEY}" $file |wc -l`) + startBlock=`expr $foundAt + $blankLines` # run the replace - sed -i "${LN},+${LINES}s${REPLACE}" $file + sed -i "${startBlock},+${valueSize}s${REPLACE}" $file done done