helper wip

This commit is contained in:
Nikola Jokic
2026-02-02 01:15:33 +01:00
parent 0824407642
commit ff29c45902

View File

@@ -10,6 +10,26 @@ export TARGET_ORG="${TARGET_ORG:-actions-runner-controller}"
export TARGET_REPO="${TARGET_REPO:-arc_e2e_test_dummy}"
export IMAGE_NAME="${IMAGE_NAME:-arc-test-image}"
# Trims a single pair of matching surrounding quotes from the provided string.
# Examples:
# trim_quotes '"1.2.3"' -> 1.2.3
# trim_quotes "'v1'" -> v1
function trim_quotes() {
local s
s="$*"
if [[ ${#s} -ge 2 ]]; then
local first last
first="${s:0:1}"
last="${s: -1}"
if [[ ( "${first}" == '"' && "${last}" == '"' ) || ( "${first}" == "'" && "${last}" == "'" ) ]]; then
s="${s:1:${#s}-2}"
fi
fi
printf '%s\n' "${s}"
}
# Tests decide which chart version to use. Helper provides extraction utilities.
function chart_version() {
local chart_yaml="$1"
@@ -19,38 +39,21 @@ function chart_version() {
fi
local version
if command -v yq >/dev/null 2>&1; then
# Support both common yq variants:
# - mikefarah/yq: yq -r '.version' file
# - kislyuk/yq: yq '.version' < file
if version="$(yq -r '.version' "${chart_yaml}" 2>/dev/null)"; then
:
else
version="$(yq '.version' <"${chart_yaml}" 2>/dev/null)" || return 1
fi
version="$(printf '%s' "${version}" | tr -d "\"'[:space:]")"
if [[ -z "${version}" ]]; then
echo "Failed to extract version from ${chart_yaml} via yq" >&2
return 1
fi
printf '%s\n' "${version}"
return 0
if version="$(yq -r '.version' "${chart_yaml}" 2>/dev/null)"; then
:
else
version="$(yq '.version' <"${chart_yaml}" 2>/dev/null)" || return 1
fi
version="$(awk -F: '$1 ~ /^version$/ { v=$2; gsub(/[[:space:]\"\x27]/, "", v); print v; exit }' "${chart_yaml}")"
version="$(printf '%s' "${version}" | tr -d "\"'[:space:]")"
if [[ -z "${version}" ]]; then
echo "Failed to extract version from ${chart_yaml}" >&2
echo "Failed to extract version from ${chart_yaml} via yq" >&2
return 1
fi
printf '%s\n' "${version}"
return 0
}
# Backwards-compatible alias (kept so older local branches still work).
function extract_chart_version() { chart_version "$@"; }
function ensure_version_set() {
if [[ -z "${VERSION:-}" ]]; then
echo "VERSION is not set. Set it in the test, e.g. export VERSION=\"$(chart_version path/to/Chart.yaml)\"." >&2