-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 followed: - print out the dependency's version before and after the bump - 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]>
- Loading branch information
1 parent
9fc3b2a
commit 3976754
Showing
1 changed file
with
43 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,65 @@ | ||
#!/bin/bash | ||
|
||
# Usage: | ||
# ./scripts/update_dep.sh module version | ||
# or ./scripts/update_dep.sh module | ||
# ./scripts/update_dep.sh should_force_upgrade module version | ||
# or ./scripts/update_dep.sh should_force_upgrade module | ||
# e.g. | ||
# ./scripts/update_dep.sh github.com/golang/groupcache | ||
# ./scripts/update_dep.sh github.com/soheilhy/cmux v0.1.5 | ||
# ./scripts/update_dep.sh false github.com/golang/groupcache | ||
# ./scripts/update_dep.sh false github.com/soheilhy/cmux v0.1.5 | ||
# | ||
# Updates version of given dependency in all the modules that depend on the mod. | ||
|
||
set -euo pipefail | ||
|
||
source ./scripts/test_lib.sh | ||
|
||
mod="$1" | ||
ver="$2" | ||
if [ "$#" -ne 3 ]; then | ||
echo "Illegal number of parameters" | ||
exit 1 | ||
fi | ||
|
||
function maybe_update_module { | ||
should_force_upgrade="$1" | ||
mod="$2" | ||
ver="$3" | ||
|
||
function print_current_dep_version { | ||
echo "${mod} version in all go mod files" | ||
grep --exclude-dir=.git --include=\*.mod -Ri "${mod}" | grep -v sum | ||
printf "\n\n" | ||
} | ||
|
||
function is_fully_indirect { | ||
tmp=$(print_current_dep_version) | ||
# Check if all lines end with "// indirect" | ||
|
||
# if grep found nothing, the error code will be non-zero | ||
if grep --exclude-dir=.git --include=\*.mod -Ri -q "^.*${mod} v.*// indirect$"; then | ||
echo "Fully indirect, we will terminate the script" | ||
exit 1 | ||
else | ||
echo "Not fully indirect, we will perform dependency bump" | ||
fi | ||
} | ||
|
||
function update_module { | ||
run go mod tidy | ||
|
||
deps=$(go list -f '{{if not .Indirect}}{{if .Version}}{{.Path}},{{.Version}}{{end}}{{end}}' -m all) | ||
deps=$(go list -f '{{if .Version}}{{.Path}},{{.Version}}{{end}}' -m all) | ||
if [[ "$deps" == *"${mod}"* ]]; then | ||
if [ -z "${ver}" ]; then | ||
run go get "${mod}" | ||
else | ||
run go get "${mod}@${ver}" | ||
fi | ||
fi | ||
} | ||
} | ||
|
||
print_current_dep_version | ||
if [ "$should_force_upgrade" = false ] ; then | ||
is_fully_indirect | ||
fi | ||
run_for_modules update_module | ||
print_current_dep_version | ||
|
||
go mod tidy | ||
run_for_modules maybe_update_module | ||
# check all dependencies across all go mod files have the same pinned version respectively | ||
PASSES="dep" ./scripts/test.sh |