Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile.core.mk
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ $(CRD_SCHEMA_CHECKER): $(LOCALBIN)

.PHONY: lint-crds
lint-crds: crd-schema-checker ## Lint CRDs for backwards compatibility on release branches.
@PREVIOUS_VERSION=$(PREVIOUS_VERSION) ./tools/crd-schema-checker.sh
@./tools/crd-schema-checker.sh

.PHONY: lint-helm
lint-helm:
Expand Down
20 changes: 16 additions & 4 deletions tools/crd-schema-checker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
# Compares CRDs between the current release branch and the previous one to catch breaking changes.
# Uses OpenShift's crd-schema-checker to detect issues like removed fields or stricter validation.
# Run 'make crd-schema-checker' first to install the dependency, then 'make lint-crds' to check.
#
# Environment variables:
# PREVIOUS_BRANCH Optional. Explicitly set the release branch to compare against.
# If not set, the script auto-detects the appropriate branch:
# - On a release branch: uses the previous release branch (via sort -V).
# - On any other branch: uses the latest available release branch (via sort -V).

set -euo pipefail

Expand Down Expand Up @@ -93,11 +99,17 @@ if [[ "$current_branch" =~ ^release-[0-9]+\.[0-9]+$ ]]; then
previous_branch=$(git branch -r | grep -E 'origin/release-[0-9]+\.[0-9]+$' |
sed 's|.*origin/||' | sort -V |
awk -v target="$current_branch" '$0 == target { print prev; exit } { prev = $0 }')
elif [[ -n "${PREVIOUS_VERSION:-}" ]]; then
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As PREVIOUS_VERSION is not used anymore anywhere in this script it probably does not make sense to pass this variable to this script in the Makefile.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

previous_branch="release-$(echo "${PREVIOUS_VERSION}" | cut -f1,2 -d'.')"
elif [[ -n "${PREVIOUS_BRANCH:-}" ]]; then
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PREVIOUS_BRANCH is not described anywhere, maybe a short help would be good for this script.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a note about PREVIOUS_BRANCH use

# Explicit override — allows callers to specify the exact branch to compare against.
previous_branch="${PREVIOUS_BRANCH}"
else
echo "Not on a release branch and PREVIOUS_VERSION not set. Skipping."
exit 0
# Not on a release branch: compare against the latest available release branch.
previous_branch=$(git branch -r | grep -E 'origin/release-[0-9]+(\.[0-9]+)*$' | \
sed 's|.*origin/||' | sort -V | tail -1)
if [[ -z "$previous_branch" ]]; then
echo "No release branches found. Please check branch naming or specify PREVIOUS_BRANCH explicitly."
exit 1
fi
fi

if [[ -z "$previous_branch" ]]; then
Expand Down
Loading