mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-14 06:15:45 +00:00
Fix golangci-lint for workspaces
This commit is contained in:
parent
3163fc4f69
commit
bad67dc973
@ -44,9 +44,11 @@ KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
|||||||
source "${KUBE_ROOT}/hack/lib/init.sh"
|
source "${KUBE_ROOT}/hack/lib/init.sh"
|
||||||
source "${KUBE_ROOT}/hack/lib/util.sh"
|
source "${KUBE_ROOT}/hack/lib/util.sh"
|
||||||
|
|
||||||
# Ensure that we find the binaries we build before anything else.
|
kube::golang::new::setup_env
|
||||||
|
kube::golang::verify_go_version
|
||||||
export GOBIN="${KUBE_OUTPUT_BIN}"
|
export GOBIN="${KUBE_OUTPUT_BIN}"
|
||||||
PATH="${GOBIN}:${PATH}"
|
|
||||||
|
kube::util::require-jq
|
||||||
|
|
||||||
invocation=(./hack/verify-golangci-lint.sh "$@")
|
invocation=(./hack/verify-golangci-lint.sh "$@")
|
||||||
golangci=("${GOBIN}/golangci-lint" run)
|
golangci=("${GOBIN}/golangci-lint" run)
|
||||||
@ -113,8 +115,6 @@ if [ "$base" ]; then
|
|||||||
golangci+=(--new --new-from-rev="$base")
|
golangci+=(--new --new-from-rev="$base")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
kube::golang::verify_go_version
|
|
||||||
|
|
||||||
# Filter out arguments that start with "-" and move them to the run flags.
|
# Filter out arguments that start with "-" and move them to the run flags.
|
||||||
shift $((OPTIND-1))
|
shift $((OPTIND-1))
|
||||||
targets=()
|
targets=()
|
||||||
@ -126,8 +126,6 @@ for arg; do
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
kube::golang::verify_go_version
|
|
||||||
|
|
||||||
# Explicitly opt into go modules
|
# Explicitly opt into go modules
|
||||||
export GO111MODULE=on
|
export GO111MODULE=on
|
||||||
|
|
||||||
@ -137,6 +135,8 @@ pushd "${KUBE_ROOT}/hack/tools" >/dev/null
|
|||||||
go install github.com/golangci/golangci-lint/cmd/golangci-lint
|
go install github.com/golangci/golangci-lint/cmd/golangci-lint
|
||||||
if [ "${golangci_config}" ]; then
|
if [ "${golangci_config}" ]; then
|
||||||
# This cannot be used without a config.
|
# This cannot be used without a config.
|
||||||
|
# This uses `go build` because `go install -buildmode=plugin` doesn't work
|
||||||
|
# (on purpose: https://github.com/golang/go/issues/64964).
|
||||||
go build -o "${GOBIN}/logcheck.so" -buildmode=plugin sigs.k8s.io/logtools/logcheck/plugin
|
go build -o "${GOBIN}/logcheck.so" -buildmode=plugin sigs.k8s.io/logtools/logcheck/plugin
|
||||||
fi
|
fi
|
||||||
popd >/dev/null
|
popd >/dev/null
|
||||||
@ -161,30 +161,25 @@ cd "${KUBE_ROOT}"
|
|||||||
|
|
||||||
res=0
|
res=0
|
||||||
run () {
|
run () {
|
||||||
if [[ "${#targets[@]}" -gt 0 ]]; then
|
if [[ "${#targets[@]}" -eq 0 ]]; then
|
||||||
echo "running ${golangci[*]} ${targets[*]}" >&2
|
# Doing it this way is MUCH faster than simply saying "all", and there doesn't
|
||||||
"${golangci[@]}" "${targets[@]}" 2>&1 | sed -e 's;^;ERROR: ;' >&2 || res=$?
|
# seem to be a simpler way to express "this whole workspace".
|
||||||
else
|
kube::util::read-array targets < <(
|
||||||
echo "running ${golangci[*]} ./..." >&2
|
go work edit -json | jq -r '.Use[].DiskPath + "/..."'
|
||||||
"${golangci[@]}" ./... 2>&1 | sed -e 's;^;ERROR: ;' >&2 || res=$?
|
)
|
||||||
for d in staging/src/k8s.io/*; do
|
|
||||||
MODPATH="staging/src/k8s.io/$(basename "${d}")"
|
|
||||||
echo "running ( cd ${KUBE_ROOT}/${MODPATH}; ${golangci[*]} --path-prefix ${MODPATH} ./... )"
|
|
||||||
pushd "${KUBE_ROOT}/${MODPATH}" >/dev/null
|
|
||||||
"${golangci[@]}" --path-prefix "${MODPATH}" ./... 2>&1 | sed -e 's;^;ERROR: ;' >&2 || res=$?
|
|
||||||
popd >/dev/null
|
|
||||||
done
|
|
||||||
fi
|
fi
|
||||||
|
echo "running ${golangci[*]} ${targets[*]}" >&2
|
||||||
|
"${golangci[@]}" "${targets[@]}" 2>&1 | sed -e 's;^;ERROR: ;' >&2 || res=$?
|
||||||
}
|
}
|
||||||
# First run with normal output.
|
# First run with normal output.
|
||||||
run "${targets[@]}"
|
run
|
||||||
|
|
||||||
# Then optionally do it again with github-actions as format.
|
# Then optionally do it again with github-actions as format.
|
||||||
# Because golangci-lint caches results, this is faster than the
|
# Because golangci-lint caches results, this is faster than the
|
||||||
# initial invocation.
|
# initial invocation.
|
||||||
if [ "$githubactions" ]; then
|
if [ "$githubactions" ]; then
|
||||||
golangci+=(--out-format=github-actions)
|
golangci+=("--out-format=github-actions")
|
||||||
run "$${targets[@]}" >"$githubactions" 2>&1
|
run >"$githubactions" 2>&1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# print a message based on the result
|
# print a message based on the result
|
||||||
|
Loading…
Reference in New Issue
Block a user