Skip to content

Commit a07094e

Browse files
committed
exit with error only when deps from *k8s.io/* have version mismatch
On-behalf-of: SAP robert.vasek@sap.com Signed-off-by: Robert Vasek <robert.vasek@clyso.com>
1 parent 583c0f4 commit a07094e

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

hack/verify-go-modules.sh

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -112,23 +112,18 @@ function diff_version_deps {
112112
function print_diff_version_deps {
113113
jq -r '
114114
to_entries
115-
| map("Error: version mismatch: \(.key) is \(.value.has), but \(.value.wants) expected")
115+
| map("Version mismatch: \(.key) is \(.value.has), but \(.value.wants) expected")
116116
| join("\n")
117-
| halt_error(1)
118117
'
119118
}
120119

121120
# Compares versions of dependencies in the supplied go.mod to
122121
# makes sure they are in line with the ones declared in
123-
# k8s.io/kubernetes module and prints the result.
124-
function compare_mod_versions_or_fail {
122+
# k8s.io/kubernetes module.
123+
function compare_mod_versions_with_k8s_deps {
125124
gomod_file="${1}"
126-
echo "Verifying dependency versions in ${gomod_file} against ${k8s_gomod}"
127125
deps="$(list_deps ${gomod_file})"
128-
129-
diff_version_deps <(echo "${deps}") <(echo "${k8s_deps}") \
130-
| print_diff_version_deps "${gomod_file}" 1>&2 \
131-
|| { echo ; exit 1 ; }
126+
diff_version_deps <(echo "${deps}") <(echo "${k8s_deps}")
132127
}
133128

134129
function gomod_filepath_for {
@@ -149,9 +144,17 @@ for dir in "${MODULE_DIRS[@]}"; do
149144
exit 1
150145
fi
151146

152-
compare_mod_versions_or_fail "${dir}/go.mod"
147+
gomod_file="${dir}/go.mod"
148+
echo "Verifying dependency versions in ${gomod_file} against ${k8s_gomod}"
149+
150+
diff="$(compare_mod_versions_with_k8s_deps ${dir}/go.mod)"
151+
if [[ -n "${diff}" ]]; then
152+
echo "${diff}" | print_diff_version_deps 1>&2
153+
echo "${diff}" | grep -q "k8s.io/" && {
154+
echo "Error: dependencies from '*k8s.io/*' must be in line with ${k8s_gomod}" 1>&2
155+
exit 1
156+
} || true
157+
echo "Continuing because no fatal errors found"
158+
fi
153159
)
154160
done
155-
156-
compare_mod_versions_or_fail "$(gomod_filepath_for github.com/kcp-dev/client-go)"
157-
compare_mod_versions_or_fail "$(gomod_filepath_for github.com/kcp-dev/apimachinery/v2)"

0 commit comments

Comments
 (0)