Guard against merging non-canonical replace directives

This commit is contained in:
Jordan Liggitt 2022-11-17 13:00:12 -05:00
parent 3f823c0daa
commit 9cb283796f
No known key found for this signature in database

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