chore: install goimports automatically (#5609)
This commit is contained in:
@@ -18,14 +18,25 @@ set -o errexit
|
|||||||
set -o nounset
|
set -o nounset
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
|
|
||||||
. "$(dirname "${BASH_SOURCE[0]}")/lib/init.sh"
|
KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||||
|
source "${KUBE_ROOT}/hack/lib/init.sh"
|
||||||
|
source "${KUBE_ROOT}/hack/lib/util.sh"
|
||||||
|
|
||||||
cd "${KUBE_ROOT}/hack" || exit 1
|
kube::golang::verify_go_version
|
||||||
|
|
||||||
if ! command -v goimports &> /dev/null
|
# Ensure that we find the binaries we build before anything else.
|
||||||
then
|
export GOBIN="${KUBE_OUTPUT_BINPATH}"
|
||||||
echo "goimports could not be found on your machine, please install it first"
|
PATH="${GOBIN}:${PATH}"
|
||||||
exit
|
|
||||||
|
# Explicitly opt into go modules, even though we're inside a GOPATH directory
|
||||||
|
export GO111MODULE=on
|
||||||
|
|
||||||
|
if ! command -v goimports ; then
|
||||||
|
# Install goimports
|
||||||
|
echo 'installing goimports'
|
||||||
|
pushd "${KUBE_ROOT}/hack/tools" >/dev/null
|
||||||
|
GO111MODULE=auto go install -mod=mod golang.org/x/tools/cmd/goimports@v0.7.0
|
||||||
|
popd >/dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cd "${KUBE_ROOT}" || exit 1
|
cd "${KUBE_ROOT}" || exit 1
|
||||||
|
|||||||
@@ -18,14 +18,25 @@ set -o errexit
|
|||||||
set -o nounset
|
set -o nounset
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
|
|
||||||
. "$(dirname "${BASH_SOURCE[0]}")/lib/init.sh"
|
KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||||
|
source "${KUBE_ROOT}/hack/lib/init.sh"
|
||||||
|
source "${KUBE_ROOT}/hack/lib/util.sh"
|
||||||
|
|
||||||
cd "${KUBE_ROOT}/hack" || exit 1
|
kube::golang::verify_go_version
|
||||||
|
|
||||||
if ! command -v goimports &> /dev/null
|
# Ensure that we find the binaries we build before anything else.
|
||||||
then
|
export GOBIN="${KUBE_OUTPUT_BINPATH}"
|
||||||
echo "goimports could not be found on your machine, please install it first"
|
PATH="${GOBIN}:${PATH}"
|
||||||
exit 1
|
|
||||||
|
# Explicitly opt into go modules, even though we're inside a GOPATH directory
|
||||||
|
export GO111MODULE=on
|
||||||
|
|
||||||
|
if ! command -v goimports ; then
|
||||||
|
# Install goimports
|
||||||
|
echo 'installing goimports'
|
||||||
|
pushd "${KUBE_ROOT}/hack/tools" >/dev/null
|
||||||
|
GO111MODULE=auto go install -mod=mod golang.org/x/tools/cmd/goimports@v0.7.0
|
||||||
|
popd >/dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cd "${KUBE_ROOT}" || exit 1
|
cd "${KUBE_ROOT}" || exit 1
|
||||||
@@ -35,9 +46,9 @@ IFS=$'\n' read -r -d '' -a files < <( find . -type f -name '*.go' -not -path "./
|
|||||||
output=$(goimports -local kubesphere.io/kubesphere -l "${files[@]}")
|
output=$(goimports -local kubesphere.io/kubesphere -l "${files[@]}")
|
||||||
|
|
||||||
if [ "${output}" != "" ]; then
|
if [ "${output}" != "" ]; then
|
||||||
echo "The following files are not import formatted "
|
echo "The following files are not import formatted"
|
||||||
printf '%s\n' "${output[@]}"
|
printf '%s\n' "${output[@]}"
|
||||||
echo "Please run the following command:"
|
echo "Please run the following command:"
|
||||||
echo " make goimports"
|
echo "make goimports"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ export GO111MODULE=on
|
|||||||
|
|
||||||
if ! command -v golangci-lint ; then
|
if ! command -v golangci-lint ; then
|
||||||
# Install golangci-lint
|
# Install golangci-lint
|
||||||
echo 'installing golangci-lint '
|
echo 'installing golangci-lint'
|
||||||
pushd "${KUBE_ROOT}/hack/tools" >/dev/null
|
pushd "${KUBE_ROOT}/hack/tools" >/dev/null
|
||||||
GO111MODULE=auto go install -mod=mod github.com/golangci/golangci-lint/cmd/golangci-lint@v1.51.1
|
GO111MODULE=auto go install -mod=mod github.com/golangci/golangci-lint/cmd/golangci-lint@v1.51.1
|
||||||
popd >/dev/null
|
popd >/dev/null
|
||||||
@@ -53,7 +53,7 @@ function error_exit {
|
|||||||
}
|
}
|
||||||
trap "error_exit" EXIT
|
trap "error_exit" EXIT
|
||||||
|
|
||||||
echo "running golangci-lint: REV=HEAD^ "
|
echo "running golangci-lint: REV=HEAD^"
|
||||||
golangci-lint run \
|
golangci-lint run \
|
||||||
--timeout 30m \
|
--timeout 30m \
|
||||||
--disable-all \
|
--disable-all \
|
||||||
|
|||||||
Reference in New Issue
Block a user