Skip to content

Commit 0d681e5

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 0d681e5

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

hack/check-capi-version.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
# Bash Strict Mode: https://github.com/guettli/bash-strict-mode
3+
trap 'echo -e "\n🤷 🚨 🔥 Warning: A command has failed. Exiting the script. Line was ($0:$LINENO): $(sed -n "${LINENO}p" "$0" 2>/dev/null || true) 🔥 🚨 🤷 "; exit 3' ERR
4+
set -Eeuo pipefail
5+
6+
# Get the directory of the script
7+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8+
REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
9+
10+
cd "${REPO_ROOT}"
11+
12+
# Extract the desired CAPI version from go.mod
13+
DESIRED_VERSION=$(grep -E 'sigs.k8s.io/cluster-api v' go.mod | grep -v '/test' | awk '{print $2}')
14+
15+
if [[ -z "${DESIRED_VERSION}" ]]; then
16+
echo "❌ Could not find cluster-api version in go.mod"
17+
exit 1
18+
fi
19+
20+
echo "✓ Desired CAPI version from go.mod: ${DESIRED_VERSION}"
21+
echo ""
22+
23+
# Find all non-documentation files with cluster-api/clusterctl version mismatches
24+
# Docs are excluded as they can contain example output that doesn't need to be in sync
25+
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
26+
echo ""
27+
echo "❌ Version mismatches found! Expected: ${DESIRED_VERSION}"
28+
echo "Please update the mismatched files to use the version from go.mod"
29+
exit 1
30+
fi
31+
32+
echo "✅ All CAPI versions are in sync with go.mod (${DESIRED_VERSION})"

0 commit comments

Comments
 (0)