Skip to content

Commit 2cd8724

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 2cd8724

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

hack/check-capi-version.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2025 The Kubernetes Authors.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
# Bash Strict Mode: https://github.com/guettli/bash-strict-mode
17+
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
18+
set -Eeuo pipefail
19+
20+
# Get the directory of the script
21+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
22+
REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
23+
24+
cd "${REPO_ROOT}"
25+
26+
# Extract the desired CAPI version from go.mod
27+
DESIRED_VERSION=$(grep -E 'sigs.k8s.io/cluster-api v' go.mod | grep -v '/test' | awk '{print $2}')
28+
29+
if [[ -z "${DESIRED_VERSION}" ]]; then
30+
echo "❌ Could not find cluster-api version in go.mod"
31+
exit 1
32+
fi
33+
34+
echo "✓ Desired CAPI version from go.mod: ${DESIRED_VERSION}"
35+
echo ""
36+
37+
# Find all non-documentation files with cluster-api/clusterctl version mismatches
38+
# Docs are excluded as they can contain example output that doesn't need to be in sync
39+
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
40+
echo ""
41+
echo "❌ Version mismatches found! Expected: ${DESIRED_VERSION}"
42+
echo "Please update the mismatched files to use the version from go.mod"
43+
exit 1
44+
fi
45+
46+
echo "✅ All CAPI versions are in sync with go.mod (${DESIRED_VERSION})"

0 commit comments

Comments
 (0)