Bump golangci-lint to v2.0.2

This ended up slightly more complicated than anticipated, tin part
because golangci-lint v2 dropped support for --exclude-dirs, so
linter issues with GOOS=windows and GOOS=darwin which were previously
ignored had to be fixed now.

This is also the reason why the ./hack/golangci-lint was simplified.
In addition, it now runs linters on Linux without systemd tag set.

Tested locally with:

	for OS in linux windows darwin; do GOOS=$OS ./hack/golangci-lint.sh; done
	Linting for GOOS=linux
	+ ./bin/golangci-lint run --build-tags=apparmor,seccomp,selinux
	0 issues.
	+ ./bin/golangci-lint run --build-tags=apparmor,seccomp,selinux,systemd
	0 issues.
	+ ./bin/golangci-lint run --build-tags=apparmor,seccomp,selinux,remote
	0 issues.
	Linting for GOOS=windows
	+ ./bin/golangci-lint run --build-tags=remote,containers_image_openpgp
	0 issues.
	Linting for GOOS=darwin
	+ ./bin/golangci-lint run --build-tags=remote,containers_image_openpgp
	0 issues.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin
2025-03-29 23:03:52 -07:00
parent 8bd73b7d2c
commit c9b108d5b3
3 changed files with 46 additions and 59 deletions

View File

@@ -1,6 +1,6 @@
#!/bin/bash
# Need to run linter twice to cover all the build tags code paths
# Run golangci-lint with different sets of build tags.
set -e
# WARNING: This script executes on multiple operating systems that
@@ -8,38 +8,23 @@ set -e
# a very old version, where modern features (like `declare -A`) are
# absent.
# Makefile calls script with the 'run' argument, but developers may not.
# Handle both cases transparently.
[[ $1 == run ]] && shift
BUILD_TAGS_DEFAULT="apparmor,seccomp,selinux"
BUILD_TAGS_ABI="$BUILD_TAGS_DEFAULT,systemd"
BUILD_TAGS_TUNNEL="$BUILD_TAGS_DEFAULT,remote"
BUILD_TAGS_REMOTE="remote,containers_image_openpgp"
SKIP_DIRS_ABI=""
SKIP_DIRS_TUNNEL=""
SKIP_DIRS_REMOTE="libpod/events,pkg/machine/qemu,pkg/machine/wsl,test"
declare -a to_lint
to_lint=(ABI TUNNEL)
# Special-case, for Darwin and Windows only "remote" linting is possible and required.
if [[ "$GOOS" == "windows" ]] || [[ "$GOOS" == "darwin" ]]; then
to_lint=(REMOTE)
echo "Linting for GOOS=$GOOS"
# Special case: for Darwin and Windows only "remote" linting is possible and required.
if [[ "$GOOS" == "windows" || "$GOOS" == "darwin" ]]; then
(
set -x
./bin/golangci-lint run --build-tags="remote,containers_image_openpgp" "$@"
)
exit 0
fi
for to_lint in "${to_lint[@]}"; do
tags_var="BUILD_TAGS_${to_lint}"
skip_var="SKIP_DIRS_${to_lint}"
echo ""
echo Running golangci-lint for "$to_lint"
echo Build Tags "$to_lint": ${!tags_var}
echo Skipped directories "$to_lint": ${!skip_var}
# Normal case (Linux): run linter for various sets of build tags.
TAGS="apparmor,seccomp,selinux"
for EXTRA_TAGS in "" ",systemd" ",remote"; do
(
# Make it really easy for a developer to copy-paste the command-line
# to focus or debug a single, specific linting category.
set -x
./bin/golangci-lint run --timeout=10m --build-tags="${!tags_var}" --exclude-dirs="${!skip_var}" "$@"
./bin/golangci-lint run --build-tags="${TAGS}${EXTRA_TAGS}" "$@"
)
done