Skip to content

Commit 796adb8

Browse files
committed
chore: add script to easily update go deps
Signed-off-by: Michael Gasch <[email protected]>
1 parent 6de37de commit 796adb8

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

hack/update-deps.sh

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/bin/bash
2+
# Copyright 2022 The CloudEvents Authors
3+
# SPDX-License-Identifier: Apache-2.0
4+
# update-deps.sh - Updates Go dependencies in all directories with go.mod files
5+
#
6+
# This script:
7+
# 1. Finds all directories containing go.mod files
8+
# 2. Goes into each directory and runs go get -u to update dependencies
9+
# 3. Runs go mod tidy to clean up the go.mod and go.sum files
10+
11+
set -euo pipefail
12+
13+
# Print script banner
14+
echo "====================================="
15+
echo "Go Dependencies Update Script"
16+
echo "====================================="
17+
18+
# Find all directories with go.mod files
19+
# TODO (@embano1): currently ignores samples/http due to broken deps
20+
echo "Finding all directories with go.mod files..."
21+
DIRS=$(find . -name "go.mod" -not -path "./samples/http/*" -exec dirname {} \;)
22+
if [ -z "$DIRS" ]; then
23+
echo "No go.mod files found!"
24+
exit 0
25+
fi
26+
27+
# Count the number of directories
28+
DIR_COUNT=$(echo "$DIRS" | wc -l | tr -d ' ')
29+
echo "Found $DIR_COUNT directories with go.mod files"
30+
echo
31+
32+
# Process each directory
33+
COUNTER=1
34+
for DIR in $DIRS; do
35+
echo "[$COUNTER/$DIR_COUNT] Processing $DIR"
36+
37+
# Change to the directory
38+
pushd "$DIR" >/dev/null
39+
40+
# disable go toolchain switching
41+
export GOTOOLCHAIN=local
42+
43+
echo " - Updating dependencies..."
44+
go get -u ./...
45+
46+
echo " - Running go mod tidy..."
47+
go mod tidy
48+
49+
# Return to the original directory
50+
popd >/dev/null
51+
52+
echo " - Done"
53+
echo
54+
55+
COUNTER=$((COUNTER + 1))
56+
done
57+
58+
echo "All dependencies updated successfully!"

0 commit comments

Comments
 (0)