mirror of
https://git.bjxgj.com/xgj/xgj-actions.git
synced 2025-10-14 04:13:37 +08:00
fix: 优化 kubectl 版本检测以支持新旧版本格式
This commit is contained in:
@@ -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
|
||||
|
||||
|
Reference in New Issue
Block a user