mirror of
https://github.com/actions/actions-runner-controller.git
synced 2026-03-09 20:51:06 +08:00
helper wip
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user