Skip to content

Commit

Permalink
Update go.mod to specify the module is go1.14 (#866)
Browse files Browse the repository at this point in the history
* Update go.mod to specify the module is go1.14

Thus the go commands will default to -mod=vendor

See: https://golang.org/doc/go1.14#go-command

* install goimports as a tool

* drop mod=vendor usage as that's the default with go1.14

* remove comment about using -mod=vendor

* Revert "drop mod=vendor usage as that's the default with go1.14"

This reverts commit 567004d.

* Revert "remove comment about using -mod=vendor"

This reverts commit 2a71393.

* Revert "install goimports as a tool"

This reverts commit 9616d5e.

* use go_run_tool to run goimports

* inline go_run_tool

* include required env var REPO_ROOT_DIR
  • Loading branch information
dprotaso authored Jun 8, 2020
1 parent 2a42ee1 commit a7ea77d
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 17 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ replace (
k8s.io/code-generator => k8s.io/code-generator v0.16.4
)

go 1.13
go 1.14
46 changes: 33 additions & 13 deletions hack/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

set -o pipefail

[[ ! -v REPO_ROOT_DIR ]] && REPO_ROOT_DIR="$(git rev-parse --show-toplevel)"
readonly REPO_ROOT_DIR

source_dirs="cmd pkg test lib"

# Store for later
Expand Down Expand Up @@ -110,21 +113,38 @@ go_fmt() {
find $(echo $source_dirs) -name "*.go" -print0 | xargs -0 gofmt -s -w
}

# Run a go tool, installing it first if necessary.
# Parameters: $1 - tool package/dir for go get/install.
# $2 - tool to run.
# $3..$n - parameters passed to the tool.
run_go_tool() {
local tool=$2
local install_failed=0
if [[ -z "$(which ${tool})" ]]; then
local action=get
[[ $1 =~ ^[\./].* ]] && action=install
# Avoid running `go get` from root dir of the repository, as it can change go.sum and go.mod files.
# See discussions in https://github.com/golang/go/issues/27643.
if [[ ${action} == "get" && $(pwd) == "${REPO_ROOT_DIR}" ]]; then
local temp_dir="$(mktemp -d)"
# Swallow the output as we are returning the stdout in the end.
pushd "${temp_dir}" > /dev/null 2>&1
GOFLAGS="" go ${action} "$1" || install_failed=1
popd > /dev/null 2>&1
else
GOFLAGS="" go ${action} "$1" || install_failed=1
fi
fi
(( install_failed )) && return ${install_failed}
shift 2
${tool} "$@"
}


source_format() {
set +e
which goimports >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "✋ No 'goimports' found. Please use"
echo "✋ go install golang.org/x/tools/cmd/goimports"
echo "✋ to enable import cleanup. Import cleanup skipped."

# Run go fmt instead
go_fmt
else
echo "🧽 ${X}Format"
goimports -w $(echo $source_dirs)
find $(echo $source_dirs) -name "*.go" -print0 | xargs -0 gofmt -s -w
fi
run_go_tool golang.org/x/tools/cmd/goimports goimports -w $(echo $source_dirs)
find $(echo $source_dirs) -name "*.go" -print0 | xargs -0 gofmt -s -w
set -e
}

Expand Down
3 changes: 0 additions & 3 deletions hack/verify-codegen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ set -o pipefail

source $(dirname $0)/../scripts/test-infra/library.sh

# Needed later
go install golang.org/x/tools/cmd/goimports

"${REPO_ROOT_DIR}"/hack/build.sh --codegen
if output="$(git status --porcelain)" && [ -z "$output" ]; then
echo "${REPO_ROOT_DIR} is up to date."
Expand Down
21 changes: 21 additions & 0 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ github.com/mailru/easyjson/buffer
github.com/mailru/easyjson/jlexer
github.com/mailru/easyjson/jwriter
# github.com/mitchellh/go-homedir v1.1.0
## explicit
github.com/mitchellh/go-homedir
# github.com/mitchellh/mapstructure v1.1.2
github.com/mitchellh/mapstructure
Expand All @@ -108,13 +109,16 @@ github.com/spf13/afero/mem
# github.com/spf13/cast v1.3.1
github.com/spf13/cast
# github.com/spf13/cobra v0.0.6 => github.com/chmouel/cobra v0.0.0-20191021105835-a78788917390
## explicit
github.com/spf13/cobra
github.com/spf13/cobra/doc
# github.com/spf13/jwalterweatherman v1.1.0
github.com/spf13/jwalterweatherman
# github.com/spf13/pflag v1.0.5
## explicit
github.com/spf13/pflag
# github.com/spf13/viper v1.6.2
## explicit
github.com/spf13/viper
# github.com/subosito/gotenv v1.2.0
github.com/subosito/gotenv
Expand All @@ -130,6 +134,7 @@ go.uber.org/zap/internal/color
go.uber.org/zap/internal/exit
go.uber.org/zap/zapcore
# golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073
## explicit
golang.org/x/crypto/ssh/terminal
# golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e
golang.org/x/net/context
Expand Down Expand Up @@ -184,12 +189,14 @@ gopkg.in/ini.v1
# gopkg.in/yaml.v2 v2.3.0
gopkg.in/yaml.v2
# gotest.tools v2.2.0+incompatible
## explicit
gotest.tools/assert
gotest.tools/assert/cmp
gotest.tools/internal/difflib
gotest.tools/internal/format
gotest.tools/internal/source
# k8s.io/api v0.17.6 => k8s.io/api v0.16.4
## explicit
k8s.io/api/admissionregistration/v1
k8s.io/api/admissionregistration/v1beta1
k8s.io/api/apps/v1
Expand Down Expand Up @@ -229,6 +236,7 @@ k8s.io/api/storage/v1
k8s.io/api/storage/v1alpha1
k8s.io/api/storage/v1beta1
# k8s.io/apimachinery v0.17.6 => k8s.io/apimachinery v0.16.4
## explicit
k8s.io/apimachinery/pkg/api/apitesting/fuzzer
k8s.io/apimachinery/pkg/api/equality
k8s.io/apimachinery/pkg/api/errors
Expand Down Expand Up @@ -278,6 +286,7 @@ k8s.io/apimachinery/pkg/watch
k8s.io/apimachinery/third_party/forked/golang/json
k8s.io/apimachinery/third_party/forked/golang/reflect
# k8s.io/cli-runtime v0.17.3 => k8s.io/cli-runtime v0.16.4
## explicit
k8s.io/cli-runtime/pkg/genericclioptions
k8s.io/cli-runtime/pkg/kustomize
k8s.io/cli-runtime/pkg/kustomize/k8sdeps
Expand All @@ -291,6 +300,7 @@ k8s.io/cli-runtime/pkg/kustomize/k8sdeps/validator
k8s.io/cli-runtime/pkg/printers
k8s.io/cli-runtime/pkg/resource
# k8s.io/client-go v11.0.1-0.20190805182717-6502b5e7b1b5+incompatible => k8s.io/client-go v0.16.4
## explicit
k8s.io/client-go/discovery
k8s.io/client-go/discovery/cached/disk
k8s.io/client-go/dynamic
Expand Down Expand Up @@ -462,6 +472,7 @@ k8s.io/utils/buffer
k8s.io/utils/integer
k8s.io/utils/trace
# knative.dev/eventing v0.15.1-0.20200608083719-c024353a712c
## explicit
knative.dev/eventing/pkg/apis/config
knative.dev/eventing/pkg/apis/configs
knative.dev/eventing/pkg/apis/configs/v1alpha1
Expand All @@ -484,6 +495,7 @@ knative.dev/eventing/pkg/client/clientset/versioned/typed/sources/v1alpha2
knative.dev/eventing/pkg/client/clientset/versioned/typed/sources/v1alpha2/fake
knative.dev/eventing/pkg/logging
# knative.dev/pkg v0.0.0-20200606224418-7ed1d4a552bc
## explicit
knative.dev/pkg/apis
knative.dev/pkg/apis/duck
knative.dev/pkg/apis/duck/v1
Expand All @@ -500,6 +512,7 @@ knative.dev/pkg/profiling
knative.dev/pkg/ptr
knative.dev/pkg/tracker
# knative.dev/serving v0.15.1-0.20200608114919-92e849c1db9c
## explicit
knative.dev/serving/pkg/apis/autoscaling
knative.dev/serving/pkg/apis/autoscaling/v1alpha1
knative.dev/serving/pkg/apis/config
Expand Down Expand Up @@ -537,4 +550,12 @@ sigs.k8s.io/kustomize/pkg/transformers/config
sigs.k8s.io/kustomize/pkg/transformers/config/defaultconfig
sigs.k8s.io/kustomize/pkg/types
# sigs.k8s.io/yaml v1.2.0
## explicit
sigs.k8s.io/yaml
# github.com/spf13/cobra => github.com/chmouel/cobra v0.0.0-20191021105835-a78788917390
# k8s.io/api => k8s.io/api v0.16.4
# k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.16.4
# k8s.io/apimachinery => k8s.io/apimachinery v0.16.4
# k8s.io/cli-runtime => k8s.io/cli-runtime v0.16.4
# k8s.io/client-go => k8s.io/client-go v0.16.4
# k8s.io/code-generator => k8s.io/code-generator v0.16.4

0 comments on commit a7ea77d

Please sign in to comment.