Skip to content

Commit 18f748a

Browse files
committed
Add tools.go
1 parent 23042cf commit 18f748a

File tree

8 files changed

+939
-9
lines changed

8 files changed

+939
-9
lines changed

Makefile

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,23 @@ generate: ## Run all code generators
2727

2828
.PHONY: test
2929
test: ## Run all unit tests.
30-
go test ./...
30+
go test -v ./...
3131

3232
.PHONY: verify
33-
verify: ## Run all code analysis tools and linters.
33+
verify: ## Run all static analysis checks.
3434
# Check if codebase is formatted.
35-
@echo "gofmt -l ."
36-
@bash -c "[ -z $$(gofmt -l .) ] && echo 'OK' || (echo 'ERROR: files are not formatted:' && gofmt -l . && false)"
35+
@which goimports > /dev/null || ! echo 'goimports not found'
36+
@bash -c "[ -z \"$(goimports -l cmd pkg)\" ] && echo 'OK' || (echo 'ERROR: files are not formatted:' && goimports -l cmd pkg && echo -e \"\nRun 'make format' or manually fix the formatting issues.\n\" && false)"
3737
# Run static checks on codebase.
38-
go vet ./...
38+
go vet ./cmd/... ./pkg/...
3939

4040
.PHONY: format
4141
format: ## Run all formatters on the codebase.
42-
go fmt ./...
42+
# Format the Go codebase.
43+
goimports -w cmd pkg
44+
45+
# Format the go.mod file.
46+
go mod tidy
4347

4448
.PHONY: release
4549
release: clean generate verify test ## Build and release goversion, publishing the artifacts on Github and Dockerhub.

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ TODO
2323
### Using Go tools
2424

2525

26-
### Using Go install
26+
27+
### Using Go install (deprecated)
2728
```bash
2829
GO11MODULE=off go install github.com/erwinvaneyk/goversion/cmd/goversion
2930
```

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.13
55
require (
66
github.com/erwinvaneyk/cobras v0.0.0-20200610150702-9e7b3fed53bf
77
github.com/ghodss/yaml v1.0.0
8+
github.com/goreleaser/goreleaser v0.143.0
89
github.com/spf13/cobra v1.0.0
9-
github.com/spf13/pflag v1.0.5 // indirect
10+
golang.org/x/tools v0.0.0-20200928112810-42b62fc93869 // indirect
1011
)

go.sum

Lines changed: 902 additions & 0 deletions
Large diffs are not rendered by default.
File renamed without changes.

version.go renamed to goversion.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//go:generate goversion generate --goversion "" --pkg goversion -o version.gen.go
1+
//go:generate goversion generate --goversion "" --pkg goversion -o goversion.gen.go
22
package goversion
33

44
import (

pkg/goversion/cmd/ldflags.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func NewCmdLDFlags() *cobra.Command {
2626

2727
cmd := &cobra.Command{
2828
Use: "ldflags",
29+
Short: "Collect version information from host and print as valid Go ldflags.",
2930
Run: cobras.Run(opts),
3031
}
3132

tools.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// +build tools
2+
// The build tag above ensures that the imports in this file will not be
3+
// included in the binaries using this package.
4+
//
5+
// To add dependencies, add the tool to the go mod
6+
// `go get -u golang.org/x/lint/golint`
7+
// Then, add it as an import to this file.
8+
//
9+
// To install the tools specified in this file, run the following:
10+
// `go generate tools.go`
11+
// or directly from tools.go:
12+
// `cat tools.go | grep '^\s_ ' | sed 's/^.*_ "\(.*\)"/\1/g' | xargs -tI % go install %`
13+
14+
//go:generate go install github.com/goreleaser/goreleaser
15+
//go:generate go install golang.org/x/tools/cmd/goimports
16+
package goversion
17+
18+
import (
19+
_ "github.com/goreleaser/goreleaser"
20+
_ "golang.org/x/tools/cmd/goimports"
21+
)

0 commit comments

Comments
 (0)