Skip to content

Commit 0a7a573

Browse files
Copilotaslafy-z
andcommitted
Simplify helm_supports_credentials() function as suggested
Co-authored-by: aslafy-z <[email protected]>
1 parent 1de1dc5 commit 0a7a573

File tree

1 file changed

+6
-30
lines changed

1 file changed

+6
-30
lines changed

tests/test-helper.bash

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -57,34 +57,10 @@ set_chart_cache_strategy() {
5757

5858
# Check if Helm version supports credential passing (>= 3.14.0)
5959
helm_supports_credentials() {
60-
local helm_version
61-
helm_version=$($HELM_BIN version --short 2>/dev/null | head -1 | sed 's/v//' | cut -d'+' -f1 | cut -d'-' -f1)
62-
63-
# If we can't get version, assume it doesn't support credentials
64-
[ -n "$helm_version" ] || return 1
65-
66-
# Extract major.minor.patch using parameter expansion
67-
local major="${helm_version%%.*}"
68-
local rest="${helm_version#*.}"
69-
local minor="${rest%%.*}"
70-
local patch="${rest#*.}"
71-
72-
# If patch is the same as rest, there was no second dot, so patch is 0
73-
[ "$patch" = "$rest" ] && patch=0
74-
75-
# Ensure we have numeric values (basic check)
76-
case "$major" in ''|*[!0-9]*) return 1 ;; esac
77-
case "$minor" in ''|*[!0-9]*) return 1 ;; esac
78-
case "$patch" in ''|*[!0-9]*) patch=0 ;; esac
79-
80-
# Check if version >= 3.14.0
81-
if [ "$major" -gt 3 ]; then
82-
return 0
83-
elif [ "$major" -eq 3 ] && [ "$minor" -gt 14 ]; then
84-
return 0
85-
elif [ "$major" -eq 3 ] && [ "$minor" -eq 14 ] && [ "$patch" -ge 0 ]; then
86-
return 0
87-
else
88-
return 1
89-
fi
60+
v=$($HELM_BIN version --short 2>/dev/null | sed 's/^v//' | cut -d+ -f1 | cut -d- -f1)
61+
[ -n "$v" ] || return 1
62+
set -- $(echo "$v" | awk -F. '{print $1,$2,($3?$3:0)}')
63+
[ "$1" -gt 3 ] ||
64+
[ "$1" -eq 3 -a "$2" -gt 14 ] ||
65+
[ "$1" -eq 3 -a "$2" -eq 14 -a "$3" -ge 0 ]
9066
}

0 commit comments

Comments
 (0)