Skip to content

Commit c44ddb8

Browse files
committed
Fix update_app_version_of_chart.sh
1 parent 2bc5740 commit c44ddb8

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

.circleci/update_app_version_of_chart.sh

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,35 @@ replace="version: $new_chart_version"
7878
sed -i "s/$search/$replace/" $thub_chart_path
7979

8080
echo "About to modify and print the updated $thub_chart_path file..."
81-
search="name: $application_name. version: $subchart_version"
82-
replace="name: $application_name\f version: $new_subchart_version"
83-
# Replace the current subchart version with the new subchart version
84-
# https://unix.stackexchange.com/a/152389
85-
cat $thub_chart_path | tr '\n' '\f' | sed -e "s/$search/$replace/" | tr '\f' '\n' | tee $thub_chart_path
81+
# Create a temporary file for safe editing
82+
temp_file=$(mktemp)
83+
# This searches for the specific subchart entry and updates its version
84+
awk -v app_name="$application_name" -v old_version="$subchart_version" -v new_version="$new_subchart_version" '
85+
BEGIN { in_dependencies = 0; found_chart = 0 }
86+
/^dependencies:/ { in_dependencies = 1 }
87+
/^[a-zA-Z]/ && !/^dependencies:/ && !/^ / { in_dependencies = 0 }
88+
in_dependencies && /^ - name:/ {
89+
if ($3 == app_name) {
90+
found_chart = 1
91+
print $0
92+
next
93+
}
94+
found_chart = 0
95+
}
96+
in_dependencies && found_chart && /^ version:/ {
97+
if ($2 == old_version) {
98+
print " version: " new_version
99+
found_chart = 0
100+
next
101+
}
102+
}
103+
{ print }
104+
' "$thub_chart_path" > "$temp_file"
105+
106+
# Replace the original file with the modified version
107+
mv "$temp_file" "$thub_chart_path"
108+
109+
echo "Updated $thub_chart_path file contents:"
110+
cat "$thub_chart_path"
86111

87112
commit_changes

0 commit comments

Comments
 (0)