From 05f0bd2d45e2b6d9a3490f057cbf63a928d636f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20Burzy=C5=84ski?= Date: Fri, 25 Oct 2024 09:22:20 +0200 Subject: [PATCH] chore: parallel k8sio go.mod replace update script --- hack/update-k8sio-gomod-replace.sh | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/hack/update-k8sio-gomod-replace.sh b/hack/update-k8sio-gomod-replace.sh index 03536bbcc..ca81b1b9c 100755 --- a/hack/update-k8sio-gomod-replace.sh +++ b/hack/update-k8sio-gomod-replace.sh @@ -10,12 +10,27 @@ MODS=($( curl -sS https://raw.githubusercontent.com/kubernetes/kubernetes/v${VERSION}/go.mod | sed -n 's|.*k8s.io/\(.*\) => ./staging/src/k8s.io/.*|k8s.io/\1|p' )) -for MOD in "${MODS[@]}"; do - V=$( + +# Export variables for access in subshells run by xargs +export VERSION + +# Function to update go.mod replace directive for a module +update_mod() { + local MOD=$1 + local V=$( go mod download -json "${MOD}@kubernetes-${VERSION}" | sed -n 's|.*"Version": "\(.*\)".*|\1|p' ) echo "Updating go.mod replace directive for ${MOD}" go mod edit "-replace=${MOD}=${MOD}@${V}" -done +} + +# Export function for access in subshells run by xargs +export -f update_mod + +# Run the updates concurrently +CONCURRENCY=$(nproc) +echo "[DEBUG] Updating modules concurrently with N=${CONCURRENCY}" +printf "%s\n" "${MODS[@]}" | xargs -P 4 -n 1 -I {} bash -c 'update_mod "$@"' _ {} + go get "k8s.io/kubernetes@v${VERSION}"