Skip to content

Commit 4691dfc

Browse files
committed
Update update_dep.sh
Based on the experience of performing dependency bumps, some minor improvements are made to the script to make it conform to our current dependency bump procedure, listed as follows: - print out the dependency's version before and after the bump - introduce a new argument: should force upgrade when the dependency is purely indirect (see use case: #18596 (comment)) - check if the dependency is fully indirect - check if all dependencies across all go mod files have the same pinned version respectively after bumping a dependency Signed-off-by: Chun-Hung Tseng <[email protected]>
1 parent 2f9532b commit 4691dfc

File tree

1 file changed

+45
-11
lines changed

1 file changed

+45
-11
lines changed

scripts/update_dep.sh

+45-11
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,67 @@
11
#!/bin/bash
22

33
# Usage:
4-
# ./scripts/update_dep.sh module version
5-
# or ./scripts/update_dep.sh module
4+
# ./scripts/update_dep.sh should_force_upgrade module version
5+
# or ./scripts/update_dep.sh should_force_upgrade module
66
# e.g.
7-
# ./scripts/update_dep.sh github.com/golang/groupcache
8-
# ./scripts/update_dep.sh github.com/soheilhy/cmux v0.1.5
7+
# ./scripts/update_dep.sh false github.com/golang/groupcache
8+
# ./scripts/update_dep.sh false github.com/soheilhy/cmux v0.1.5
99
#
1010
# Updates version of given dependency in all the modules that depend on the mod.
1111

1212
set -euo pipefail
1313

1414
source ./scripts/test_lib.sh
1515

16-
mod="$1"
17-
ver="$2"
16+
if [ "$#" -ne 3 ]; then
17+
echo "Illegal number of parameters"
18+
exit 1
19+
fi
1820

19-
function maybe_update_module {
21+
should_force_upgrade="$1"
22+
mod="$2"
23+
ver="$3"
24+
25+
function print_current_dep_version {
26+
echo "${mod} version in all go mod files"
27+
grep --exclude-dir=.git --include=\*.mod -Ri "${mod}" | grep -v sum
28+
printf "\n\n"
29+
}
30+
31+
function is_fully_indirect {
32+
print_current_dep_version
33+
34+
# check if all lines end with "// indirect"
35+
# if grep found nothing, the error code will be non-zero
36+
if grep --exclude-dir=.git --include=\*.mod -Ri -q "^.*${mod} v.*// indirect$"; then
37+
echo "Fully indirect, we will terminate the script"
38+
exit 1
39+
else
40+
echo "Not fully indirect, we will perform dependency bump"
41+
fi
42+
}
43+
44+
function update_module {
2045
run go mod tidy
2146

22-
deps=$(go list -f '{{if not .Indirect}}{{if .Version}}{{.Path}},{{.Version}}{{end}}{{end}}' -m all)
47+
deps=$(go list -f '{{if .Version}}{{.Path}},{{.Version}}{{end}}' -m all)
2348
if [[ "$deps" == *"${mod}"* ]]; then
2449
if [ -z "${ver}" ]; then
2550
run go get "${mod}"
2651
else
2752
run go get "${mod}@${ver}"
2853
fi
2954
fi
30-
}
55+
}
56+
57+
print_current_dep_version
58+
if [ "$should_force_upgrade" = false ] ; then
59+
is_fully_indirect
60+
fi
61+
run_for_modules update_module
62+
print_current_dep_version
63+
64+
# check all dependencies across all go mod files have the same pinned version respectively
65+
PASSES="dep" ./scripts/test.sh
3166

32-
go mod tidy
33-
run_for_modules maybe_update_module
67+
./scripts/fix.sh

0 commit comments

Comments
 (0)