Skip to content

Commit 612ca28

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 - check if the dependency is fully indirect - change the behavior of bumping dependency (doesn't ignore bumping indirect dependency in the go mod files anymore) - 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 18eb5c6 commit 612ca28

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

scripts/update_dep.sh

+36-6
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,51 @@ set -euo pipefail
1313

1414
source ./scripts/test_lib.sh
1515

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

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

22-
deps=$(go list -f '{{if not .Indirect}}{{if .Version}}{{.Path}},{{.Version}}{{end}}{{end}}' -m all)
46+
deps=$(go list -f '{{if .Version}}{{.Path}},{{.Version}}{{end}}' -m all)
2347
if [[ "$deps" == *"${mod}"* ]]; then
2448
if [ -z "${ver}" ]; then
25-
run go get "${mod}"
49+
run go get -u "${mod}"
2650
else
2751
run go get "${mod}@${ver}"
2852
fi
2953
fi
30-
}
54+
}
55+
56+
print_current_dep_version
57+
is_fully_indirect
58+
run_for_modules update_module
59+
60+
./scripts/fix.sh
61+
PASSES="dep" ./scripts/test.sh
3162

32-
go mod tidy
33-
run_for_modules maybe_update_module
63+
print_current_dep_version

0 commit comments

Comments
 (0)