Use contemporary Bash helpers in hack/verify-generated-swagger-spec.sh
#!/bin/bash
source "$(dirname "${BASH_SOURCE}")/lib/init.sh"
-echo "===== Verifying API Swagger Spec ====="
+os::log::info "===== Verifying API Swagger Spec ====="
SPECROOT="${OS_ROOT}/api"
REL_TMP_PATH="_output/verify-generated-swagger-spec"
TMP_SPECROOT="${OS_ROOT}/${REL_TMP_PATH}/api"
-echo "Generating a fresh spec..."
-if ! output=`${OS_ROOT}/hack/update-generated-swagger-spec.sh ${REL_TMP_PATH} 2>&1`
-then
- echo "FAILURE: Generation of fresh spec failed:"
- echo "$output"
- exit 1
+function cleanup() {
+ local return_code="$?"
+ rm -rf "${TMP_SPECROOT}"
+
+ os::util::describe_return_code "${return_code}"
+ exit "${return_code}"
+}
+
+trap cleanup EXIT
+
+os::log::info "Generating a fresh spec..."
+if ! output=$("${OS_ROOT}/hack/update-generated-swagger-spec.sh" "${REL_TMP_PATH}" 2>&1); then
+ os::log::fatal "Generation of fresh spec failed:
+${output}"
fi
# TODO: more effective way to do this, or have readme be generated
cp "${SPECROOT}/README.md" "${TMP_SPECROOT}"
-echo "Diffing current spec against freshly generated spec..."
-ret=0
-diff -Naupr -I 'Auto generated by' "${SPECROOT}" "${TMP_SPECROOT}" || ret=$?
-rm -rf "${TMP_SPECROOT}"
-if [[ $ret -eq 0 ]]
-then
- echo "SUCCESS: Swagger spec up to date."
+os::log::info "Diffing current spec against freshly generated spec..."
+if ! output=$(diff -Naupr -I 'Auto generated by' "${SPECROOT}" "${TMP_SPECROOT}" 2>&1); then
+ os::log::fatal "Swagger spec is out of date. Please run hack/update-generated-swagger-spec.sh:
+${output}"
else
- echo "FAILURE: Swagger spec is out of date. Please run hack/update-generated-swagger-spec.sh"
- exit 1
+ os::log::info "Swagger spec up to date."
fi
\ No newline at end of file
