Skip to content

Commit

Permalink
Update update_dep.sh
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
henrybear327 committed Sep 22, 2024
1 parent 2f9532b commit f94117c
Showing 1 changed file with 35 additions and 5 deletions.
40 changes: 35 additions & 5 deletions scripts/update_dep.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,51 @@ set -euo pipefail

source ./scripts/test_lib.sh

if [ "$#" -ne 2 ]; then
echo "Illegal number of parameters"
exit 1
fi

mod="$1"
ver="$2"

function maybe_update_module {
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 {
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
}
}

is_fully_indirect
run_for_modules update_module
print_current_dep_version

# check all dependencies across all go mod files have the same pinned version respectively
PASSES="dep" ./scripts/test.sh

go mod tidy
run_for_modules maybe_update_module
./scripts/fix.sh

0 comments on commit f94117c

Please sign in to comment.