Last active
July 26, 2021 15:27
-
-
Save lggomez/21be58fc6f01a58558541f4a82018f5e to your computer and use it in GitHub Desktop.
Generic go project pre commit runner
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| echo "** running formatters" | |
| goimports -e -w -local my.domain.corp $(find . -type f -name '*.go' -not -path "./vendor/*") | |
| # use gofumpt if available, see https://github.com/mvdan/gofumpt | |
| if ! command -v gofumpt -version &> /dev/null | |
| then | |
| echo "gofumpt could not be found, defaulting to gofmt" | |
| gofmt -s -w $(find . -type f -name '*.go' -not -path "./vendor/*") | |
| else | |
| echo "gofumpt found, executing as formatter" | |
| gofumpt -l -w . | |
| fi | |
| echo "** running golangci-lint" | |
| golangci-lint run ./... | |
| echo "** running mod tidy" | |
| go mod tidy | |
| echo "** running tests" | |
| go test $(go list ./...) -cover |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment