Skip to content

Commit 838ef83

Browse files
committed
Add bump-capa.sh and bump-capi.sh
1 parent e064c5f commit 838ef83

File tree

2 files changed

+123
-0
lines changed

2 files changed

+123
-0
lines changed

hack/bump-capa.sh

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail -o errtrace -x
3+
4+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5+
ROOT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
6+
7+
cd "$ROOT_DIR"
8+
9+
if [ -n "${CAPA_VERSION:-}" ]; then
10+
REF="$CAPA_VERSION"
11+
else
12+
echo "CAPA_VERSION not set, querying latest commit SHA from kubernetes-sigs/cluster-api-provider-aws main..."
13+
set +o pipefail
14+
REF=$(curl -sL "https://api.github.com/repos/kubernetes-sigs/cluster-api-provider-aws/commits/main" | awk -F '"' '/"sha"/ { print $4; exit }')
15+
set -o pipefail
16+
if [ -z "$REF" ]; then
17+
echo "Failed to determine latest CAPA commit. Set CAPA_VERSION to continue." >&2
18+
exit 1
19+
fi
20+
echo "Using discovered CAPA ref: $REF"
21+
fi
22+
23+
P_MODULE_DIR="$ROOT_DIR/cluster-api/providers/aws"
24+
pushd "$P_MODULE_DIR"
25+
26+
echo "Upgrading CAPA to commit ${REF} in providers/aws"
27+
GO111MODULE=on go get "sigs.k8s.io/cluster-api-provider-aws/v2@${REF}"
28+
echo "Running go mod tidy"
29+
GO111MODULE=on go mod tidy
30+
echo "Running go mod vendor"
31+
GO111MODULE=on go mod vendor
32+
33+
GO_VERSION=$(grep 'require sigs.k8s.io/cluster-api-provider-aws/v2' go.mod | awk '{print $NF}')
34+
echo "Go generated pseudo-version: $GO_VERSION"
35+
36+
echo "Reading existing replace directives from cluster-api/providers/aws/go.mod"
37+
EXISTING_REPLACES=$(grep -E '^replace ' go.mod | awk '{print $2}' || true)
38+
39+
if [ -n "$EXISTING_REPLACES" ]; then
40+
echo "Found existing replace directives for packages:"
41+
echo "$EXISTING_REPLACES"
42+
43+
CAPI_CORE_GOMOD="$ROOT_DIR/cluster-api/cluster-api/go.mod"
44+
if [ ! -f "$CAPI_CORE_GOMOD" ]; then
45+
echo "Warning: cluster-api/cluster-api/go.mod not found at $CAPI_CORE_GOMOD" >&2
46+
else
47+
echo "Looking up versions in cluster-api/cluster-api/go.mod"
48+
while IFS= read -r pkg; do
49+
if [ -n "$pkg" ]; then
50+
VERSION=$(grep -E "^\s*${pkg}\s+" "$CAPI_CORE_GOMOD" | awk '{print $2}' | head -1 || true)
51+
if [ -z "$VERSION" ]; then
52+
VERSION=$(grep -E "^replace.*=>\s*${pkg}\s+" "$CAPI_CORE_GOMOD" | awk '{print $NF}' || true)
53+
fi
54+
55+
if [ -n "$VERSION" ]; then
56+
echo "Applying replace: ${pkg} => ${pkg} ${VERSION}"
57+
go mod edit -replace="${pkg}=${pkg}@${VERSION}"
58+
else
59+
echo "Warning: Could not find version for ${pkg} in cluster-api/cluster-api/go.mod"
60+
fi
61+
fi
62+
done <<< "$EXISTING_REPLACES"
63+
fi
64+
fi
65+
66+
echo "Running go mod vendor in cluster-api/providers/aws"
67+
GO111MODULE=on go mod vendor
68+
popd
69+
70+
echo "Upgrading CAPA to ${GO_VERSION} in root directory"
71+
pushd "$ROOT_DIR"
72+
GO111MODULE=on go get "sigs.k8s.io/cluster-api-provider-aws/v2@${REF}"
73+
74+
echo "Running go mod tidy"
75+
GO111MODULE=on go mod tidy
76+
echo "Running go mod vendor"
77+
GO111MODULE=on go mod vendor
78+
popd
79+
80+
echo "Done."

hack/bump-capi.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
5+
ROOT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
6+
cd "$ROOT_DIR"
7+
8+
if [ -n "${CAPI_VERSION:-}" ]; then
9+
VERSION="$CAPI_VERSION"
10+
else
11+
echo "CAPI_VERSION not set, querying latest release from kubernetes-sigs/cluster-api..."
12+
if ! VERSION=$(curl -sL "https://api.github.com/repos/kubernetes-sigs/cluster-api/releases/latest" 2>/dev/null | awk -F '"' '/tag_name/ { print $4; exit }'); then
13+
echo "Failed to query GitHub API for latest release." >&2
14+
exit 1
15+
fi
16+
if [ -z "$VERSION" ]; then
17+
echo "Failed to discover latest cluster-api release. Set CAPI_VERSION environment variable to continue." >&2
18+
exit 1
19+
fi
20+
echo "Using discovered version: $VERSION"
21+
fi
22+
23+
24+
pushd ./cluster-api
25+
26+
echo "Updating CAPI to $VERSION in cluster-api"
27+
GO111MODULE=on go get "sigs.k8s.io/cluster-api@${VERSION}"
28+
echo "Running: go mod tidy"
29+
GO111MODULE=on go mod tidy
30+
echo "Running: go mod vendor"
31+
GO111MODULE=on go mod vendor
32+
popd
33+
34+
echo "Updating CAPI to $VERSION in root directory"
35+
pushd "$ROOT_DIR/cluster-api"
36+
GO111MODULE=on go get "sigs.k8s.io/cluster-api@${VERSION}"
37+
echo "Running: go mod tidy"
38+
GO111MODULE=on go mod tidy
39+
echo "Running: go mod vendor"
40+
GO111MODULE=on go mod vendor
41+
popd
42+
43+
echo "Done."

0 commit comments

Comments
 (0)