@@ -45,50 +45,51 @@ update_obi_image_tag() {
4545 local normalized_ver=" ${LATEST_VER# v} " # Strip leading 'v' if present
4646 local target_tag=" v$normalized_ver "
4747 local current_tag
48- local updated_file=" "
4948
5049 current_tag=$( yq eval ' .obi.image.tag' " $values_file " )
5150 echo " Current OBI image tag in values.yaml is $current_tag "
5251
5352 if [ " $current_tag " != " $target_tag " ]; then
5453 echo " Updating OBI image tag to $target_tag in values.yaml"
55- updated_file=$( mktemp " ${values_file} .XXXXXX" )
56- cleanup_updated_file () {
57- if [ -n " $updated_file " ] && [ -f " $updated_file " ]; then
58- rm -f " $updated_file "
59- fi
60- }
61- trap cleanup_updated_file RETURN
62-
63- if awk -v target_tag=" $target_tag " '
64- BEGIN {
65- in_obi=0
66- in_image=0
67- updated=0
68- image_indent=""
69- }
70- /^obi:/ { in_obi=1 }
71- in_obi && /^[^[:space:]][^:]*:/ && !/^obi:/ { in_obi=0; in_image=0 }
72- in_obi && match($0, /^[[:space:]]+image:/) {
73- in_image=1
74- image_indent=substr($0, RSTART, RLENGTH - length("image:"))
75- }
76- in_image && $0 ~ ("^" image_indent "[^[:space:]][^:]*:") && $0 !~ ("^" image_indent "image:") { in_image=0 }
77- in_image && $0 ~ ("^" image_indent "[[:space:]]+tag: ") {
78- print image_indent " tag: \"" target_tag "\""
79- updated=1
80- in_image=0
81- next
82- }
83- { print }
84- END {
85- if (!updated) {
86- exit 1
54+ if (
55+ updated_file=$( mktemp " ${values_file} .XXXXXX" )
56+ trap ' if [ -n "$updated_file" ] && [ -f "$updated_file" ]; then rm -f "$updated_file"; fi' EXIT
57+
58+ if awk -v target_tag=" $target_tag " '
59+ BEGIN {
60+ in_obi=0
61+ in_image=0
62+ updated=0
63+ image_indent=""
64+ }
65+ /^obi:/ { in_obi=1 }
66+ in_obi && /^[^[:space:]][^:]*:/ && !/^obi:/ { in_obi=0; in_image=0 }
67+ in_obi && match($0, /^[[:space:]]+image:/) {
68+ in_image=1
69+ image_indent=substr($0, RSTART, RLENGTH - length("image:"))
70+ }
71+ in_image && $0 ~ ("^" image_indent "[^[:space:]][^:]*:") && $0 !~ ("^" image_indent "image:") { in_image=0 }
72+ in_image && $0 ~ ("^" image_indent "[[:space:]]+tag: ") {
73+ print image_indent " tag: \"" target_tag "\""
74+ updated=1
75+ in_image=0
76+ next
8777 }
88- }
89- ' " $values_file " > " $updated_file " ; then
90- mv " $updated_file " " $values_file "
91- updated_file=" "
78+ { print }
79+ END {
80+ if (!updated) {
81+ exit 1
82+ }
83+ }
84+ ' " $values_file " > " $updated_file " ; then
85+ mv " $updated_file " " $values_file "
86+ updated_file=" "
87+ else
88+ echo " Error: Failed to update obi.image.tag in $values_file ; expected to find obi.image.tag and rewrite it to $target_tag ." >&2
89+ exit 1
90+ fi
91+ ); then
92+ :
9293 else
9394 return 1
9495 fi
0 commit comments