Skip to content

Commit b47f8e8

Browse files
committed
Add script to check CAPI version alignment
This script validates that Cluster API versions are consistent across the codebase by reading the desired version from go.mod and checking for mismatches in Makefile, Tiltfile, and test configurations. Documentation files (*.md) are excluded as they may contain example output that doesn't need to be kept in sync. Fixes #1705
1 parent ba8c768 commit b47f8e8

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

hack/check-capi-version.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
set -o errexit
2+
set -o nounset
3+
set -o pipefail
4+
5+
# Get the directory of the script
6+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7+
REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
8+
9+
cd "${REPO_ROOT}"
10+
11+
# Extract the desired CAPI version from go.mod
12+
DESIRED_VERSION=$(grep -E 'sigs.k8s.io/cluster-api v' go.mod | grep -v '/test' | awk '{print $2}')
13+
14+
if [[ -z "${DESIRED_VERSION}" ]]; then
15+
echo "❌ Could not find cluster-api version in go.mod"
16+
exit 1
17+
fi
18+
19+
echo "✓ Desired CAPI version from go.mod: ${DESIRED_VERSION}"
20+
echo ""
21+
22+
# Find all non-documentation files with cluster-api/clusterctl version mismatches
23+
# Docs are excluded as they can contain example output that doesn't need to be in sync
24+
if git ls-files | grep -v vendor | grep -v '\.md$' | xargs grep -nH -E '(cluster-api|clusterctl|capi_version)' 2>/dev/null | grep -E 'v1\.[0-9]+\.[0-9]+' | grep -v "${DESIRED_VERSION}"; then
25+
echo ""
26+
echo "❌ Version mismatches found! Expected: ${DESIRED_VERSION}"
27+
echo "Please update the mismatched files to use the version from go.mod"
28+
exit 1
29+
fi
30+
31+
echo "✅ All CAPI versions are in sync with go.mod (${DESIRED_VERSION})"

0 commit comments

Comments
 (0)