126 lines
4.0 KiB
Bash
126 lines
4.0 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
wl_area_index() {
|
|
case "$1" in
|
|
frontend) printf '0' ;;
|
|
backend) printf '1' ;;
|
|
specs) printf '2' ;;
|
|
docs) printf '3' ;;
|
|
*) return 1 ;;
|
|
esac
|
|
}
|
|
|
|
wl_trim() {
|
|
local value=$1
|
|
value=${value#"${value%%[![:space:]]*}"}
|
|
value=${value%"${value##*[![:space:]]}"}
|
|
printf '%s' "$value"
|
|
}
|
|
|
|
wl_parse_delivery_map() {
|
|
local metadata_file=$1
|
|
local design_file=$2
|
|
local raw_area raw_status raw_reason area status reason gate index
|
|
|
|
wl_areas=(frontend backend specs docs)
|
|
wl_affected_flags=(0 0 0 0)
|
|
wl_map_statuses=('' '' '' '')
|
|
wl_map_reasons=('' '' '' '')
|
|
wl_contract_status=''
|
|
wl_contract_reason=''
|
|
|
|
while IFS= read -r area; do
|
|
[[ -n "$area" ]] || continue
|
|
if ! index=$(wl_area_index "$area"); then
|
|
printf 'Unknown affected area in metadata: %s\n' "$area" >&2
|
|
return 1
|
|
fi
|
|
if [[ "${wl_affected_flags[$index]}" -eq 1 ]]; then
|
|
printf 'Duplicate affected area in metadata: %s\n' "$area" >&2
|
|
return 1
|
|
fi
|
|
wl_affected_flags[$index]=1
|
|
done < <(
|
|
awk '
|
|
$0 == "affected_areas:" { in_areas = 1; next }
|
|
in_areas && /^ - / { sub(/^ - /, ""); print; next }
|
|
in_areas { exit }
|
|
' "$metadata_file"
|
|
)
|
|
|
|
if [[ "${wl_affected_flags[2]}" -ne 1 ]]; then
|
|
printf 'Delivery Map violation: specs must be affected for every versioned change.\n' >&2
|
|
return 1
|
|
fi
|
|
|
|
while IFS='|' read -r _ raw_area raw_status raw_reason _; do
|
|
area=$(wl_trim "$raw_area")
|
|
case "$area" in
|
|
frontend|backend|specs|docs) ;;
|
|
*) continue ;;
|
|
esac
|
|
index=$(wl_area_index "$area")
|
|
if [[ -n "${wl_map_statuses[$index]}" ]]; then
|
|
printf 'Delivery Map contains duplicate row for %s.\n' "$area" >&2
|
|
return 1
|
|
fi
|
|
status=$(wl_trim "$raw_status")
|
|
status=${status//\`/}
|
|
reason=$(wl_trim "$raw_reason")
|
|
wl_map_statuses[$index]=$status
|
|
wl_map_reasons[$index]=$reason
|
|
done < "$design_file"
|
|
|
|
while IFS='|' read -r _ raw_area raw_status raw_reason _; do
|
|
gate=$(wl_trim "$raw_area")
|
|
[[ "$gate" == 'runtime-openapi' ]] || continue
|
|
if [[ -n "$wl_contract_status" ]]; then
|
|
printf 'Contract Gate Decision contains duplicate runtime-openapi row.\n' >&2
|
|
return 1
|
|
fi
|
|
wl_contract_status=$(wl_trim "$raw_status")
|
|
wl_contract_status=${wl_contract_status//\`/}
|
|
wl_contract_reason=$(wl_trim "$raw_reason")
|
|
done < "$design_file"
|
|
|
|
for index in 0 1 2 3; do
|
|
area=${wl_areas[$index]}
|
|
status=${wl_map_statuses[$index]}
|
|
reason=${wl_map_reasons[$index]}
|
|
if [[ -z "$status" ]]; then
|
|
printf 'Delivery Map is missing area: %s\n' "$area" >&2
|
|
return 1
|
|
fi
|
|
if [[ "${wl_affected_flags[$index]}" -eq 1 ]]; then
|
|
if [[ "$status" != 'affected' ]]; then
|
|
printf 'Delivery Map mismatch: %s is listed as affected in metadata but has status %s.\n' "$area" "$status" >&2
|
|
return 1
|
|
fi
|
|
elif [[ "$status" != 'N/A' ]]; then
|
|
printf 'Delivery Map mismatch: %s is absent from affected_areas but has status %s.\n' "$area" "$status" >&2
|
|
return 1
|
|
fi
|
|
if [[ -z "$reason" || "$reason" == '-' || "$reason" == '—' || "$reason" == *'<!--'* ]]; then
|
|
printf 'Delivery Map requires a concrete outcome or N/A reason for %s.\n' "$area" >&2
|
|
return 1
|
|
fi
|
|
done
|
|
|
|
if [[ -z "$wl_contract_status" ]]; then
|
|
printf 'Contract Gate Decision is missing runtime-openapi.\n' >&2
|
|
return 1
|
|
fi
|
|
if [[ "$wl_contract_status" != 'required' && "$wl_contract_status" != 'N/A' ]]; then
|
|
printf 'Invalid runtime-openapi decision: %s. Expected required or N/A.\n' "$wl_contract_status" >&2
|
|
return 1
|
|
fi
|
|
if [[ -z "$wl_contract_reason" || "$wl_contract_reason" == '-' || "$wl_contract_reason" == '—' || "$wl_contract_reason" == *'<!--'* ]]; then
|
|
printf 'Contract Gate Decision requires a concrete runtime-openapi reason.\n' >&2
|
|
return 1
|
|
fi
|
|
if [[ "$wl_contract_status" == 'required' && ( "${wl_affected_flags[0]}" -ne 1 || "${wl_affected_flags[1]}" -ne 1 ) ]]; then
|
|
printf 'runtime-openapi cannot be required unless frontend and backend are affected.\n' >&2
|
|
return 1
|
|
fi
|
|
}
|