From dfda61bbbf76aa4ded208bb38bcdf9d86f44d586 Mon Sep 17 00:00:00 2001 From: Ivan Valdes Date: Tue, 18 Jun 2024 17:06:30 -0700 Subject: [PATCH] make: fix verify-dep Makefile's target `verify-dep` current behavior is to use `go list` to check consistent dependency versions from direct dependencies. Ignoring indirect dependencies in a multi-module project could lead to version mismatches. If module A imports module B, module B's dependency will be an indirect dependency in module A. Which can potentially have a version mismatch. Therefore, use `go mod edit` with indirect dependencies, too. So it can work with all dependencies defined in go.mod. Fix displaying dependencies with mismatches, as the old code was searching with grep just for the prefix, which would show other dependencies that shared the same prefix. Signed-off-by: Ivan Valdes --- scripts/test.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/test.sh b/scripts/test.sh index 5fa115487..9bc5a3f51 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -535,7 +535,7 @@ function dump_deps_of_module() { if ! module=$(run go list -m); then return 255 fi - run go list -f "{{if not .Indirect}}{{if .Version}}{{.Path}},{{.Version}},${module}{{end}}{{end}}" -m all + run go mod edit -json | jq -r '.Require[] | .Path+","+.Version+","+if .Indirect then " (indirect)" else "" end+",'"${module}"'"' } # Checks whether dependencies are consistent across modules @@ -548,7 +548,7 @@ function dep_pass { for dup in ${duplicates}; do log_error "FAIL: inconsistent versions for dependency: ${dup}" - echo "${all_dependencies}" | grep "${dup}" | sed "s|\\([^,]*\\),\\([^,]*\\),\\([^,]*\\)| - \\1@\\2 from: \\3|g" + echo "${all_dependencies}" | grep "${dup}," | sed 's|\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\)| - \1@\2\3 from: \4|g' done if [[ -n "${duplicates}" ]]; then log_error "FAIL: inconsistent dependencies"