Add golangci github action and replace the deprecated golint (#10187)

* Add golangci github action and replace the deprecated golint

Signed-off-by: z1cheng <imchench@gmail.com>

* Install if golangci-lint not exists

Signed-off-by: z1cheng <imchench@gmail.com>

* Use -z operator

Signed-off-by: z1cheng <imchench@gmail.com>

* Fix json tag for DatadogSampleRate field in config.go

Signed-off-by: z1cheng <imchench@gmail.com>

* Add golangci linters

Signed-off-by: z1cheng <imchench@gmail.com>

* Revert DatadogSampleRate fix

Signed-off-by: z1cheng <imchench@gmail.com>

* Fix comments

Signed-off-by: z1cheng <imchench@gmail.com>

* Add a new line

Signed-off-by: z1cheng <imchench@gmail.com>

* fixup! Add a new line

Signed-off-by: z1cheng <imchench@gmail.com>

* Add trigger condition

Signed-off-by: z1cheng <imchench@gmail.com>

* Add golint-check entry in makefile

Signed-off-by: Chen Chen <imchench@gmail.com>

* Run golint-check in a container

Signed-off-by: Chen Chen <imchench@gmail.com>

---------

Signed-off-by: z1cheng <imchench@gmail.com>
Signed-off-by: Chen Chen <imchench@gmail.com>
This commit is contained in:
Chen Chen 2023-09-07 01:06:53 +08:00 committed by GitHub
parent c9ca168364
commit 8a6af6068d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 289 additions and 33 deletions

View file

@ -22,19 +22,13 @@ KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
cd "${KUBE_ROOT}"
GOLINT=${GOLINT:-"golint"}
PACKAGES=($(go list ./internal/... | grep -v /vendor/))
bad_files=()
for package in "${PACKAGES[@]}"; do
out=$("${GOLINT}" -min_confidence=0.9 "${package}" | grep -v -E '(should not use dot imports|internal/file/bindata.go)' || :)
if [[ -n "${out}" ]]; then
bad_files+=("${out}")
fi
done
if [[ "${#bad_files[@]}" -ne 0 ]]; then
echo "!!! '$GOLINT' problems: "
echo "${bad_files[@]}"
exit 1
LINT=${LINT:-golangci-lint}
if [[ -z "$(command -v ${LINT})" ]]; then
echo "${LINT} is missing. Installing it now."
# See: https://golangci-lint.run/usage/install/#local-installation
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.53.3
LINT=$(go env GOPATH)/bin/golangci-lint
fi
# ex: ts=2 sw=2 et filetype=sh
${LINT} run