|
| 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." |
0 commit comments