diff --git a/Dockerfile b/Dockerfile index b642e75ad..45ab2ef06 100644 --- a/Dockerfile +++ b/Dockerfile @@ -69,6 +69,11 @@ RUN --mount=type=bind,target=.,rw < /dev/null ; then + echo Please install jq + exit 1 +fi + +# Load the requires and replaces section in the root go.mod file +declare -A map_requires_1 +declare -A map_replaces_1 +pushd "${ROOT}" > /dev/null +while IFS='#' read -r key value +do + map_requires_1[$key]="$value" +done<<<$(go mod edit -json | jq -r '.Require[] | .Path + " # " + .Version') +while IFS='#' read -r key value +do + [ "$key" = "" ] || map_replaces_1[$key]="$value" +done<<<$(go mod edit -json | jq -r 'try .Replace[] | .Old.Path + " # " + .New.Path + " : " + .New.Version') +popd > /dev/null + +# Load the requires and replaces section in the other go.mod file +declare -A map_requires_2 +declare -A map_replaces_2 +pushd "${ROOT}/$1" > /dev/null +while IFS='#' read -r key value +do + [ "$key" = "" ] || map_requires_2[$key]="$value" +done<<<$(go mod edit -json | jq -r '.Require[] | .Path + " # " + .Version') +while IFS='#' read -r key value +do + map_replaces_2[$key]="$value" +done<<<$(go mod edit -json | jq -r 'try .Replace[] | .Old.Path + " # " + .New.Path + " : " + .New.Version') +popd > /dev/null + +# signal for errors later +ERRORS=0 + +# iterate through the second go.mod's require section and ensure that all items +# have the same values in the root go.mod replace section +for k in "${!map_requires_2[@]}" +do + if [ -v "map_requires_1[$k]" ]; then + if [ "${map_requires_2[$k]}" != "${map_requires_1[$k]}" ]; then + echo "${k} has different values in the go.mod files require section:" \ + "${map_requires_1[$k]} in root go.mod ${map_requires_2[$k]} in $1/go.mod" + ERRORS=$(( ERRORS + 1 )) + fi + fi +done + +# iterate through the second go.mod's replace section and ensure that all items +# have the same values in the root go.mod's replace section. Except for the +# containerd/containerd which we know will be different +for k in "${!map_replaces_2[@]}" +do + if [[ "${k}" == "github.com/containerd/containerd"* ]]; then + continue + fi + if [ -v "map_replaces_1[$k]" ]; then + if [ "${map_replaces_2[$k]}" != "${map_replaces_1[$k]}" ]; then + echo "${k} has different values in the go.mod files replace section:" \ + "${map_replaces_1[$k]} in root go.mod ${map_replaces_2[$k]} in $1/go.mod" + ERRORS=$(( ERRORS + 1 )) + fi + fi +done + +# iterate through the root go.mod's replace section and ensure that all the +# same items are present in the second go.mod's replace section and nothing is missing +for k in "${!map_replaces_1[@]}" +do + if [[ "${k}" == "github.com/containerd/containerd"* ]]; then + continue + fi + if [ ! -v "map_replaces_2[$k]" ]; then + echo "${k} has an entry in root go.mod replace section, but is missing from" \ + " replace section in $1/go.mod" + ERRORS=$(( ERRORS + 1 )) + fi +done + +if [ "$ERRORS" -ne 0 ]; then + echo "Found $ERRORS error(s)." + exit 1 +fi \ No newline at end of file