Merge pull request #113978 from liggitt/check-canonical

Guard against merging non-canonical replace directives
This commit is contained in:
Kubernetes Prow Robot 2022-12-10 00:47:39 -08:00 committed by GitHub
commit 565667f403
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -65,6 +65,20 @@ if [[ -n "${outdated}" ]]; then
echo "${outdated}"
fi
noncanonical=$(go list -m -json all | jq -r "
select(.Replace.Version != null) |
select(.Path != .Replace.Path) |
select(.Path) |
\" \(.Path) is replaced with \(.Replace.Path)\"
")
if [[ -n "${noncanonical}" ]]; then
echo ""
echo "These modules are pinned to non-canonical repos."
echo "Revert to using the canonical repo for these modules before merge"
echo ""
echo "${noncanonical}"
fi
unused=$(comm -23 \
<(go mod edit -json | jq -r '.Replace[] | select(.New.Version != null) | .Old.Path' | sort) \
<(go list -m -json all | jq -r .Path | sort))
@ -74,9 +88,10 @@ if [[ -n "${unused}" ]]; then
echo "${unused}" | xargs -L 1 echo 'GO111MODULE=on go mod edit -dropreplace'
fi
if [[ -n "${unused}${outdated}" ]]; then
if [[ -n "${unused}${outdated}${noncanonical}" ]]; then
rc=1
else
echo "All pinned versions of checked dependencies match their preferred version."
fi
echo "All pinned versions of checked dependencies match their preferred version."
exit $rc