hack: reuse already installed golangci-lint

When a specific version of golangci-lint is already available in $PATH,
use it instead of installing one locally.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin
2026-05-19 15:38:25 -07:00
parent 43fc762a47
commit cf021c4ba9
2 changed files with 21 additions and 4 deletions

View File

@@ -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

View File

@@ -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