Skip to content

Instantly share code, notes, and snippets.

@lggomez
Last active July 26, 2021 15:27
Show Gist options
  • Save lggomez/21be58fc6f01a58558541f4a82018f5e to your computer and use it in GitHub Desktop.
Save lggomez/21be58fc6f01a58558541f4a82018f5e to your computer and use it in GitHub Desktop.
Generic go project pre commit runner
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