Skip to content

Commit

Permalink
chore: parallel k8sio go.mod replace update script
Browse files Browse the repository at this point in the history
  • Loading branch information
czeslavo committed Oct 25, 2024
1 parent c27f6e0 commit 05f0bd2
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions hack/update-k8sio-gomod-replace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"

0 comments on commit 05f0bd2

Please sign in to comment.