diff --git a/hack/update-goimports.sh b/hack/update-goimports.sh index a092a6242..2174e3a1e 100755 --- a/hack/update-goimports.sh +++ b/hack/update-goimports.sh @@ -18,14 +18,25 @@ set -o errexit set -o nounset 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 -then - echo "goimports could not be found on your machine, please install it first" - exit +# Ensure that we find the binaries we build before anything else. +export GOBIN="${KUBE_OUTPUT_BINPATH}" +PATH="${GOBIN}:${PATH}" + +# 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 cd "${KUBE_ROOT}" || exit 1 diff --git a/hack/verify-goimports.sh b/hack/verify-goimports.sh index 4aaa12d2d..6f8e26da8 100755 --- a/hack/verify-goimports.sh +++ b/hack/verify-goimports.sh @@ -18,14 +18,25 @@ set -o errexit set -o nounset 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 -then - echo "goimports could not be found on your machine, please install it first" - exit 1 +# Ensure that we find the binaries we build before anything else. +export GOBIN="${KUBE_OUTPUT_BINPATH}" +PATH="${GOBIN}:${PATH}" + +# 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 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[@]}") if [ "${output}" != "" ]; then - echo "The following files are not import formatted " + echo "The following files are not import formatted" printf '%s\n' "${output[@]}" echo "Please run the following command:" - echo " make goimports" + echo "make goimports" exit 1 fi diff --git a/hack/verify-golangci-lint.sh b/hack/verify-golangci-lint.sh index 904a760a8..87ea6f1e5 100755 --- a/hack/verify-golangci-lint.sh +++ b/hack/verify-golangci-lint.sh @@ -37,7 +37,7 @@ export GO111MODULE=on if ! command -v golangci-lint ; then # Install golangci-lint - echo 'installing golangci-lint ' + echo 'installing golangci-lint' pushd "${KUBE_ROOT}/hack/tools" >/dev/null GO111MODULE=auto go install -mod=mod github.com/golangci/golangci-lint/cmd/golangci-lint@v1.51.1 popd >/dev/null @@ -53,7 +53,7 @@ function error_exit { } trap "error_exit" EXIT -echo "running golangci-lint: REV=HEAD^ " +echo "running golangci-lint: REV=HEAD^" golangci-lint run \ --timeout 30m \ --disable-all \