fix: 优化 kubectl 版本检测以支持新旧版本格式

This commit is contained in:
Lyda
2025-10-11 18:38:07 +08:00
parent 425b35a08a
commit 4473ed9c52

View File

@@ -28,10 +28,21 @@ validate_binary() {
local required="$2"
local version_cmd="$3"
local output_var="$4"
local version_output=""
if command -v "$name" >/dev/null 2>&1; then
log_success "检测到 $name: $($version_cmd)"
printf '%s=%s\n' "$output_var" "$($version_cmd)" >> "$GITHUB_OUTPUT"
if [[ "$name" == "kubectl" ]]; then
if version_output=$(kubectl version --client --short 2>/dev/null | head -n 1); then
:
else
version_output=$(kubectl version --client 2>/dev/null | head -n 1)
fi
else
version_output=$(bash -c "$version_cmd")
fi
log_success "检测到 $name: $version_output"
printf '%s=%s\n' "$output_var" "$version_output" >> "$GITHUB_OUTPUT"
return 0
fi