hack: verify to verify-golangci-lint.sh

This commit is contained in:
Oleksandr Redko 2025-03-10 14:37:13 +02:00
parent 67f0e95b3a
commit 77758c185b
2 changed files with 17 additions and 6 deletions

View File

@ -15,7 +15,7 @@
# limitations under the License.
# This script checks that all generated golangci-lint configurations
# are up-to-date and the config hack/golangci.yaml is valid.
# are up-to-date.
set -o errexit
set -o nounset
@ -24,9 +24,4 @@ set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "${KUBE_ROOT}/hack/lib/verify-generated.sh"
golangci=("${GOBIN}/golangci-lint")
golangci_config="${KUBE_ROOT}/hack/golangci.yaml"
kube::verify::generated "" "Please run 'hack/update-golangci-lint-config.sh'" hack/update-golangci-lint-config.sh
"${golangci[@]}" config verify --config="${golangci_config}"

View File

@ -129,6 +129,22 @@ if [ "${golangci_config}" ]; then
GOTOOLCHAIN="$(kube::golang::hack_tools_gotoolchain)" go -C "${KUBE_ROOT}/hack/tools" build -o "${GOBIN}/logcheck.so" -buildmode=plugin sigs.k8s.io/logtools/logcheck/plugin
fi
# Verify that the given config is valid. "golangci-lint run" does not
# do that, which makes it easy to miss mistakes while editing the configuration.
if ! failures=$( ${GOBIN}/golangci-lint config verify --config="${golangci_config:-}" 2>&1 ); then
cat >&2 <<EOF
Verification of the configuration failed. Command:
${GOBIN}/golangci-lint config verify --config="${golangci_config:-}")
Result:
$failures
EOF
exit 1
fi
if [ "${golangci_config}" ]; then
# The relative path to _output/local/bin only works if that actually is the
# GOBIN. If not, then we have to make a temporary copy of the config and