diff --git a/hack/golangci-lint.sh b/hack/golangci-lint.sh index 457d56e7a1..0ab51b30bd 100755 --- a/hack/golangci-lint.sh +++ b/hack/golangci-lint.sh @@ -10,6 +10,9 @@ set -e declare -a EXTRA_TAGS +# Prefer the one from $PATH, if available. +BIN="$(command -v golangci-lint || echo ./bin/golangci-lint)" + echo "Linting for GOOS=$GOOS" case "$GOOS" in windows|darwin) @@ -31,6 +34,6 @@ for EXTRA in "" "${EXTRA_TAGS[@]}"; do # the command-line to focus or debug a single, specific linting category. ( set -x - ./bin/golangci-lint run --build-tags="${TAGS}${EXTRA}" "$@" + "$BIN" run --build-tags="${TAGS}${EXTRA}" "$@" ) done diff --git a/hack/install_golangci.sh b/hack/install_golangci.sh index fa3652eab1..35ef385a2f 100755 --- a/hack/install_golangci.sh +++ b/hack/install_golangci.sh @@ -10,6 +10,10 @@ die() { echo "${1:-No error message given} (from $(basename "$0"))"; exit 1; } # Strip the leading v, if found. VERSION=${VERSION#v} +# Local installation path. +BINDIR="./bin" +LBIN="$BINDIR/golangci-lint" + function install() { local retry=$1 @@ -22,10 +26,20 @@ function install() { curl -sSfL --retry 5 https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b $BINDIR "v$VERSION" } -BINDIR="./bin" -BIN="$BINDIR/golangci-lint" -if [ -x "$BIN" ] && $BIN --version | grep "$VERSION"; then +# Check if it's already installed globally. +BIN=$(command -v golangci-lint) +if [ -n "$BIN" ] && $BIN --version | grep "$VERSION"; then echo "Using existing $BIN" + # Remove the locally installed one, as it is: + # - no longer needed; + # - might be old/wrong version. + rm -f $LBIN + exit 0 +fi + +# Check the locally installed one. +if [ -x "$LBIN" ] && $LBIN --version | grep "$VERSION"; then + echo "Using existing local $LBIN" exit 0 fi