Skip to content

Commit 5a7e336

Browse files
authored
Merge pull request kubernetes#79944 from liggitt/golang-deps
Allow hack/lint-dependencies.sh to skip golang.org/x/... deps, verify in verify-vendor.sh
2 parents b7faf3e + dd27662 commit 5a7e336

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

hack/lint-dependencies.sh

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,43 @@ fi
3434
kube::golang::verify_go_version
3535
kube::util::require-jq
3636

37-
outdated=$(go list -m -json all | jq -r '
37+
case "${1:-}" in
38+
"--all")
39+
echo "Checking all dependencies"
40+
filter=''
41+
;;
42+
"-a")
43+
echo "Checking all dependencies"
44+
filter=''
45+
;;
46+
"")
47+
# by default, skip checking golang.org/x/... dependencies... we pin to levels that match our go version for those
48+
echo "Skipping golang.org/x/... dependencies, pass --all to include"
49+
filter='select(.Path | startswith("golang.org/x/") | not) |'
50+
;;
51+
*)
52+
kube::log::error "Unrecognized arg: ${1}"
53+
exit 1
54+
;;
55+
esac
56+
57+
outdated=$(go list -m -json all | jq -r "
3858
select(.Replace.Version != null) |
3959
select(.Version != .Replace.Version) |
40-
"\(.Path)
60+
${filter}
61+
select(.Path) |
62+
\"\(.Path)
4163
pinned: \(.Replace.Version)
4264
preferred: \(.Version)
43-
hack/pin-dependency.sh \(.Path) \(.Version)"
44-
')
65+
hack/pin-dependency.sh \(.Path) \(.Version)\"
66+
")
4567
if [[ -n "${outdated}" ]]; then
4668
echo "These modules are pinned to versions different than the minimal preferred version."
47-
echo "That means that without require directives, a different version would be selected."
48-
echo "The command to switch to the minimal preferred version is listed for each module."
69+
echo "That means that without replace directives, a different version would be selected,"
70+
echo "which breaks consumers of our published modules."
71+
echo "1. Use hack/pin-dependency.sh to switch to the preferred version for each module"
72+
echo "2. Run hack/update-vendor.sh to rebuild the vendor directory"
73+
echo "3. Run hack/lint-dependencies.sh to verify no additional changes are required"
4974
echo ""
5075
echo "${outdated}"
5176
fi
@@ -55,13 +80,13 @@ unused=$(comm -23 \
5580
<(go list -m -json all | jq -r .Path | sort))
5681
if [[ -n "${unused}" ]]; then
5782
echo ""
58-
echo "Pinned module versions that aren't actually used:"
83+
echo "Use the given commands to remove pinned module versions that aren't actually used:"
5984
echo "${unused}" | xargs -L 1 echo 'GO111MODULE=on go mod edit -dropreplace'
6085
fi
6186

6287
if [[ -n "${unused}${outdated}" ]]; then
6388
exit 1
6489
fi
6590

66-
echo "All pinned dependencies match their preferred version."
91+
echo "All pinned versions of checked dependencies match their preferred version."
6792
exit 0

hack/verify-vendor.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ pushd "${KUBE_ROOT}" > /dev/null 2>&1
8383
echo "hack/update-vendor.sh" >&2
8484
ret=1
8585
fi
86+
87+
# Verify we are pinned to matching levels
88+
hack/lint-dependencies.sh >&2
8689
popd > /dev/null 2>&1
8790

8891
if [[ ${ret} -gt 0 ]]; then

0 commit comments

Comments
 (0)