diff --git a/buildutil b/buildutil index b52809a..3f1b5f2 100755 --- a/buildutil +++ b/buildutil @@ -1,5 +1,5 @@ #!/usr/bin/env sh set -eu -go mod vendor +test -z "$(go env GOWORK)" && go mod vendor || go work vendor go generate ./... exec go run ./cmd/buildutil "$@" diff --git a/cmd/buildutil/info.go b/cmd/buildutil/info.go index c2488ec..c39ef98 100644 --- a/cmd/buildutil/info.go +++ b/cmd/buildutil/info.go @@ -153,6 +153,7 @@ type BuildInfo struct { Module string Dir string Version string + Work string } Commit struct { @@ -255,6 +256,7 @@ func CollectBuildInformation(ctx context.Context, p BuildParameters) (BuildInfo, info.Commit.Date = time.Unix(e.OutputInt64("git", "show", "-s", "--format=%ct"), 0).Format(time.RFC3339) info.Commit.Hash = e.OutputString("git", "rev-parse", "HEAD") info.Commit.Branch = e.OutputString("git", "rev-parse", "--abbrev-ref", "HEAD") + info.Go.Work = e.OutputString(p.GoCommand, "env", "GOWORK") info.SDKVersion, err = ParseVersion(e.OutputString(p.GoCommand, "list", "-mod=readonly", "-m", "-f", "{{.Version}}", "github.com/rebuy-de/rebuy-go-sdk/...")) if err != nil { diff --git a/cmd/buildutil/runner.go b/cmd/buildutil/runner.go index 2742007..e4420f2 100644 --- a/cmd/buildutil/runner.go +++ b/cmd/buildutil/runner.go @@ -139,13 +139,18 @@ func (r *Runner) RunClean(ctx context.Context, cmd *cobra.Command, args []string func (r *Runner) RunVendor(ctx context.Context, cmd *cobra.Command, args []string) { defer r.Inst.Durations.Steps.Stopwatch("vendor")() - call(ctx, r.Parameters.GoCommand, "mod", "vendor") + if r.Info.Go.Work == "" { + call(ctx, r.Parameters.GoCommand, "mod", "vendor") + } else { + call(ctx, r.Parameters.GoCommand, "work", "vendor") + } } func (r *Runner) RunTest(ctx context.Context, cmd *cobra.Command, args []string) { defer r.Inst.Durations.Steps.Stopwatch("test")() r.RunTestFormat(ctx, cmd, args) + r.RunTestStaticcheck(ctx, cmd, args) r.RunTestVet(ctx, cmd, args) r.RunTestPackages(ctx, cmd, args) } @@ -159,6 +164,22 @@ func (r *Runner) RunTestFormat(ctx context.Context, cmd *cobra.Command, args []s call(ctx, "gofmt", a...) } +func (r *Runner) RunTestStaticcheck(ctx context.Context, cmd *cobra.Command, args []string) { + fail := []string{ + "all", + "-SA1019", // Using a deprecated function, variable, constant or field + } + + logrus.Info("Testing staticcheck") + defer r.Inst.Durations.Testing.Stopwatch("staticcheck")() + call(ctx, r.Parameters.GoCommand, + "run", "honnef.co/go/tools/cmd/staticcheck", + "-f", "stylish", + "-fail", strings.Join(fail, ","), + "./...", + ) +} + func (r *Runner) RunTestVet(ctx context.Context, cmd *cobra.Command, args []string) { a := []string{"vet"} a = append(a, r.Info.Test.Packages...) diff --git a/go.mod b/go.mod index 09f688c..a17e91e 100644 --- a/go.mod +++ b/go.mod @@ -38,12 +38,14 @@ require ( golang.org/x/tools v0.18.0 google.golang.org/protobuf v1.32.0 gopkg.in/yaml.v3 v3.0.1 + honnef.co/go/tools v0.4.7 k8s.io/client-go v0.29.2 ) require ( dario.cat/mergo v1.0.0 // indirect github.com/AlekSi/pointer v1.2.0 // indirect + github.com/BurntSushi/toml v1.2.1 // indirect github.com/Masterminds/goutils v1.1.1 // indirect github.com/Masterminds/semver/v3 v3.2.1 // indirect github.com/Masterminds/sprig/v3 v3.2.3 // indirect @@ -137,6 +139,7 @@ require ( github.com/yuin/gopher-lua v1.1.0 // indirect gitlab.com/digitalxero/go-conventional-commit v1.0.7 // indirect golang.org/x/crypto v0.19.0 // indirect + golang.org/x/exp/typeparams v0.0.0-20221208152030-732eee02a75a // indirect golang.org/x/net v0.21.0 // indirect golang.org/x/sys v0.17.0 // indirect golang.org/x/term v0.17.0 // indirect diff --git a/go.sum b/go.sum index 1771a1d..8b1aafb 100644 --- a/go.sum +++ b/go.sum @@ -2,6 +2,8 @@ dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= github.com/AlekSi/pointer v1.2.0 h1:glcy/gc4h8HnG2Z3ZECSzZ1IX1x2JxRVuDzaJwQE0+w= github.com/AlekSi/pointer v1.2.0/go.mod h1:gZGfd3dpW4vEc/UlyfKKi1roIqcCgwOIvb0tSNSBle0= +github.com/BurntSushi/toml v1.2.1 h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak= +github.com/BurntSushi/toml v1.2.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/DmitriyVTitov/size v1.5.0/go.mod h1:le6rNI4CoLQV1b9gzp1+3d7hMAD/uu2QcJ+aYbNgiU0= github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI= github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= @@ -380,6 +382,8 @@ golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo= golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= golang.org/x/exp v0.0.0-20240213143201-ec583247a57a h1:HinSgX1tJRX3KsL//Gxynpw5CTOAIPhgL4W8PNiIpVE= golang.org/x/exp v0.0.0-20240213143201-ec583247a57a/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc= +golang.org/x/exp/typeparams v0.0.0-20221208152030-732eee02a75a h1:Jw5wfR+h9mnIYH+OtGT2im5wV1YGGDora5vTv/aa5bE= +golang.org/x/exp/typeparams v0.0.0-20221208152030-732eee02a75a/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= @@ -485,6 +489,8 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +honnef.co/go/tools v0.4.7 h1:9MDAWxMoSnB6QoSqiVr7P5mtkT9pOc1kSxchzPCnqJs= +honnef.co/go/tools v0.4.7/go.mod h1:+rnGS1THNh8zMwnd2oVOTL9QF6vmfyG6ZXBULae2uc0= k8s.io/api v0.29.2 h1:hBC7B9+MU+ptchxEqTNW2DkUosJpp1P+Wn6YncZ474A= k8s.io/api v0.29.2/go.mod h1:sdIaaKuU7P44aoyyLlikSLayT6Vb7bvJNCX105xZXY0= k8s.io/apimachinery v0.29.2 h1:EWGpfJ856oj11C52NRCHuU7rFDwxev48z+6DSlGNsV8= diff --git a/tools.go b/tools.go new file mode 100644 index 0000000..19374ad --- /dev/null +++ b/tools.go @@ -0,0 +1,9 @@ +//go:build tools +// +build tools + +package main + +// https://github.com/golang/go/wiki/Modules#how-can-i-track-tool-dependencies-for-a-module +import ( + _ "honnef.co/go/tools/cmd/staticcheck" +)