Skip to content

Commit 403d126

Browse files
committed
hack/install_golang.sh: revamp
1. Strip leading v from VERSION. This will allow to simplify renovate rule at [1]. 2. Fix git branch in the URL. In golangci-lint v2 they've switched from master to main, and it's not clear what will happen to master over time, so let's just switch to main prophylactically. 3. Use -b option instead of undocumented hack. Instead of relying on an undocumented feature of having BINDIR, let's use -b option as recommended by the official docs at [2]. 4. Avoid stuttering in the output. Before: [kir@kir-tp1 podman]$ VERSION=2.0.2 ./hack/install_golangci.sh golangci-lint has version 2.0.2 built with go1.24.1 from 2b224c2c on 2025-03-25T21:36:18Z Using existing ./bin/golangci-lint has version 2.0.2 built with go1.24.1 from 2b224c2c on 2025-03-25T21:36:18Z After: [kir@kir-tp1 podman]$ VERSION=2.0.2 ./hack/install_golangci.sh golangci-lint has version 2.0.2 built with go1.24.1 from 2b224c2c on 2025-03-25T21:36:18Z Using existing ./bin/golangci-lint 5. Fix shellcheck warnings. 6. Also retry when reinstalling. The code logic to retry install for up to 5 times when installation fails was introduced by commit dd85740 ("CI: retry the golangci install"). For some reason, the above commit only uses the logic when the binary is not found. In a situation when the binary is found but is of the wrong version, no retries are done. Fix that. 7. Add -f option to curl. As recommended by the official installation docs at [2]. [1]: https://github.com/containers/automation/blame/16f757f69956514006cc26b4d0a78f9f252171c6/renovate/defaults.json5#L106-L108 [2]: https://golangci-lint.run/welcome/install/#binaries Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent 4f75d0b commit 403d126

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

hack/install_golangci.sh

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,34 @@
33
# This script is intended to be a convenience, to be called from the
44
# Makefile `.install.golangci-lint` target. Any other usage is not recommended.
55

6-
die() { echo "${1:-No error message given} (from $(basename $0))"; exit 1; }
6+
die() { echo "${1:-No error message given} (from $(basename "$0"))"; exit 1; }
77

88
[ -n "$VERSION" ] || die "\$VERSION is empty or undefined"
99

10+
# Strip the leading v, if found.
11+
VERSION=${VERSION#v}
12+
1013
function install() {
1114
local retry=$1
1215

1316
local msg="Installing golangci-lint v$VERSION into $BIN"
1417
if [[ $retry -ne 0 ]]; then
1518
msg+=" - retry #$retry"
1619
fi
17-
echo $msg
20+
echo "$msg"
1821

19-
curl -sSL --retry 5 https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v$VERSION
22+
curl -sSfL --retry 5 https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b $BINDIR "v$VERSION"
2023
}
2124

22-
# Undocumented behavior: golangci-lint installer requires $BINDIR in env,
23-
# will default to ./bin but we can't rely on that.
24-
export BINDIR="./bin"
25+
BINDIR="./bin"
2526
BIN="$BINDIR/golangci-lint"
26-
if [ ! -x "$BIN" ]; then
27-
# This flakes much too frequently with "crit unable to find v1.51.1"
28-
for retry in $(seq 0 5); do
29-
install $retry && exit 0
30-
sleep 5
31-
done
32-
else
33-
# Prints its own file name as part of --version output
34-
$BIN --version | grep "$VERSION"
35-
if [ $? -eq 0 ]; then
36-
echo "Using existing $BINDIR/$($BIN --version)"
37-
else
38-
install
39-
fi
27+
if [ -x "$BIN" ] && $BIN --version | grep "$VERSION"; then
28+
echo "Using existing $BIN"
29+
exit 0
4030
fi
31+
32+
# This flakes much too frequently with "crit unable to find v1.51.1"
33+
for retry in $(seq 0 5); do
34+
install "$retry" && exit 0
35+
sleep 5
36+
done

0 commit comments

Comments
 (0)