Skip to content

Commit 47770c3

Browse files
phlogistonjohnmergify[bot]
authored andcommitted
hack: make install-tools.sh more robust against missing deps
If a dependency of the script (go, python) is missing the script would silently fail very early on. This change tries to avoid any failure unless the tool in question actually depends on that dependency while also making the missing dependency more obvious with more output. Signed-off-by: John Mulligan <[email protected]>
1 parent 7308438 commit 47770c3

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

hack/install-tools.sh

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,29 @@
55
# GOBIN=<dir> install-tools.sh --<tool-name>
66
#
77
set -e
8-
GO_CMD=${GO_CMD:-$(command -v go)}
9-
PY_CMD="${PY_CMD:-$(command -v python3)}"
10-
GOBIN=${GOBIN:-${GOPATH}/bin}
118

129
_require_gobin() {
1310
mkdir -p "${GOBIN}"
1411
}
1512

13+
_require_go() {
14+
if [ -z "$GO_CMD" ]; then
15+
echo "error: go command required, but not found" >&2
16+
echo "(set GO_CMD to specify go command)" >&2
17+
exit 5
18+
fi
19+
}
20+
21+
_require_py() {
22+
if [ -z "$PY_CMD" ]; then
23+
echo "error: python3 command required, but not found" >&2
24+
echo "(set PY_CMD to specify python command)" >&2
25+
exit 5
26+
fi
27+
}
28+
1629
_install_tool() {
30+
_require_go
1731
GOBIN="${GOBIN}" ${GO_CMD} install "$1"
1832
}
1933

@@ -43,11 +57,25 @@ _install_gosec() {
4357

4458
_install_gitlint() {
4559
_require_gobin
60+
_require_py
4661
"${PY_CMD}" -m venv "${GOBIN}/.py"
4762
"${GOBIN}/.py/bin/pip" install "gitlint==0.19.1"
4863
ln -s "${GOBIN}/.py/bin/gitlint" "${GOBIN}/gitlint"
4964
}
5065

66+
GOBIN="${GOBIN:-${GOPATH}/bin}"
67+
68+
if [ -z "$GO_CMD" ]; then
69+
if ! GO_CMD="$(command -v go)"; then
70+
echo "warning: failed to find go command" >&2
71+
fi
72+
fi
73+
if [ -z "$PY_CMD" ]; then
74+
if ! PY_CMD="$(command -v python3)"; then
75+
echo "warning: failed to find python3 command" >&2
76+
fi
77+
fi
78+
5179
case "$1" in
5280
--kustomize)
5381
_require_gobin

0 commit comments

Comments
 (0)