42 lines
1.6 KiB
Bash
42 lines
1.6 KiB
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)"
|
|
api_base_ref="${API_BASE_REF:-}"
|
|
redocly="${REDOCLY:-}"
|
|
codegen_python="${CODEGEN_PYTHON:-python3}"
|
|
|
|
if [[ -z "$api_base_ref" ]]; then
|
|
echo "check-api-compat: set API_BASE_REF to a Git ref containing the previous API sources" >&2
|
|
exit 2
|
|
fi
|
|
if [[ -z "$redocly" || ! -x "$redocly" ]]; then
|
|
echo "check-api-compat: install the API tools with make -C api install first" >&2
|
|
exit 2
|
|
fi
|
|
if ! git -C "$repo_root" rev-parse --verify "${api_base_ref}^{commit}" >/dev/null 2>&1; then
|
|
echo "check-api-compat: API_BASE_REF does not resolve to a Git commit" >&2
|
|
exit 2
|
|
fi
|
|
if ! git -C "$repo_root" ls-tree -r --name-only "$api_base_ref" -- api | grep -Eq '^api/(core/)?openapi\.yml$'; then
|
|
echo "check-api-compat: API_BASE_REF has no prior public contract; compatibility comparison skipped"
|
|
exit 0
|
|
fi
|
|
|
|
temporary_dir="$(mktemp -d "${TMPDIR:-/tmp}/lincodex-api-compat.XXXXXX")"
|
|
trap 'rm -rf "$temporary_dir"' EXIT
|
|
|
|
git -C "$repo_root" archive --format=tar "$api_base_ref" api | tar -xf - -C "$temporary_dir"
|
|
if [[ -f "$temporary_dir/api/core/openapi.yml" ]]; then
|
|
previous_contract="$temporary_dir/api/core"
|
|
else
|
|
previous_contract="$temporary_dir/api"
|
|
fi
|
|
"$codegen_python" "$repo_root/scripts/merge-schemas.py" "$previous_contract"
|
|
"$redocly" bundle "$previous_contract/openapi.yml" --output "$previous_contract/openapi.bundle.yml"
|
|
"$redocly" lint --config "$repo_root/api/redocly.yaml" "$previous_contract/openapi.bundle.yml"
|
|
go -C "$repo_root/backend" tool oasdiff breaking \
|
|
"$previous_contract/openapi.bundle.yml" \
|
|
"$repo_root/api/core/openapi.bundle.yml" \
|
|
--fail-on ERR
|