@@ -26,7 +26,22 @@ set -o pipefail
26
26
27
27
REPO_ROOT=$( cd " $( dirname " ${BASH_SOURCE[0]} " ) /.." && pwd)
28
28
29
- mapfile -t DIRS < <( find " ${REPO_ROOT} " -name go.mod -print0 | xargs -0 dirname)
29
+ # This is the list of directories that host the individual kcp go modules.
30
+ #
31
+ # KEEP IT UP TO DATE and SORTED!
32
+ #
33
+ # The items must be sorted such that the module that is being dependent on
34
+ # comes before the one that depends on it (i.e. topological order).
35
+ DIRS=(
36
+ " ${REPO_ROOT} /sdk"
37
+ " ${REPO_ROOT} /cli"
38
+ " ${REPO_ROOT} "
39
+ " ${REPO_ROOT} /docs/generators/cli-doc"
40
+ )
41
+
42
+ # Check that DIRS is up to date.
43
+ [[ " $( printf ' %s\n' " ${DIRS[@]} " | sort) " == " $( find " ${REPO_ROOT} " -name go.mod -print0 | xargs -0 dirname | sort) " ]] \
44
+ || { echo " Error: DIRS list in ${BASH_SOURCE[0]} is out-of-date, and needs to be manually updated" 1>&2 ; exit 1 ; }
30
45
31
46
# list_deps lists dependencies of the supplied go.mod file (dependencies
32
47
# with version "v0.0.0" are skipped). The output is a json dictionary in the
@@ -75,22 +90,29 @@ function diff_version_deps {
75
90
' " ${has_deps} " " ${wants_deps} "
76
91
}
77
92
78
- # print_diff_version_deps prints the output of diff_version_deps as a
79
- # human-readable multi-line text.
93
+ # print_diff_version_deps prints the output of diff_version_deps (expected in stdin)
94
+ # as a human-readable multi-line text.
95
+ # Returns 1 if any lines were printed (i.e. errors were found).
80
96
function print_diff_version_deps {
81
- jq -r " to_entries | map(\" Warning: version mismatch: has \(.key)@\(.value.has), but \(.value.wants) expected\" ) | join(\"\\ n\" )"
97
+ jq -r '
98
+ to_entries
99
+ | map("Error: version mismatch: \(.key) is \(.value.has), but \(.value.wants) expected")
100
+ | join("\n")
101
+ | halt_error(1)
102
+ '
82
103
}
83
104
84
105
# Compares versions of dependencies in the supplied go.mod to
85
106
# makes sure they are in line with the ones declared in
86
107
# k8s.io/kubernetes module and prints the result.
87
- function compare_mod_versions {
108
+ function compare_mod_versions_or_fail {
88
109
gomod_file=" ${1} "
89
110
echo " Verifying dependency versions in ${gomod_file} against ${k8s_gomod} "
90
111
deps=" $( list_deps ${gomod_file} ) "
91
112
92
113
diff_version_deps <( echo " ${deps} " ) <( echo " ${k8s_deps} " ) \
93
- | print_diff_version_deps " ${gomod_file} "
114
+ | print_diff_version_deps " ${gomod_file} " 1>&2 \
115
+ || { echo ; exit 1 ; }
94
116
}
95
117
96
118
function gomod_filepath_for {
@@ -111,9 +133,9 @@ for dir in "${DIRS[@]}"; do
111
133
exit 1
112
134
fi
113
135
114
- compare_mod_versions " ${dir} /go.mod"
136
+ compare_mod_versions_or_fail " ${dir} /go.mod"
115
137
)
116
138
done
117
139
118
- compare_mod_versions " $( gomod_filepath_for github.com/kcp-dev/client-go) "
119
- compare_mod_versions " $( gomod_filepath_for github.com/kcp-dev/apimachinery/v2) "
140
+ compare_mod_versions_or_fail " $( gomod_filepath_for github.com/kcp-dev/client-go) "
141
+ compare_mod_versions_or_fail " $( gomod_filepath_for github.com/kcp-dev/apimachinery/v2) "
0 commit comments