github.com/rudderlabs/rudder-go-kit@v0.30.0/Makefile (about) 1 .PHONY: help default test test-run test-teardown generate lint fmt 2 3 GO=go 4 LDFLAGS?=-s -w 5 TESTFILE=_testok 6 7 default: lint 8 9 generate: install-tools 10 $(GO) generate ./... 11 12 test: install-tools test-run test-teardown 13 14 test-run: ## Run all unit tests 15 ifeq ($(filter 1,$(debug) $(RUNNER_DEBUG)),) 16 $(eval TEST_CMD = SLOW=0 gotestsum --format pkgname-and-test-fails --) 17 $(eval TEST_OPTIONS = -race -p=1 -v -failfast -shuffle=on -coverprofile=profile.out -covermode=atomic -coverpkg=./... -vet=all --timeout=15m) 18 else 19 $(eval TEST_CMD = SLOW=0 go test) 20 $(eval TEST_OPTIONS = -race -p=1 -v -failfast -shuffle=on -coverprofile=profile.out -covermode=atomic -coverpkg=./... -vet=all --timeout=15m) 21 endif 22 ifdef package 23 ifdef exclude 24 $(eval FILES = `go list ./$(package)/... | egrep -iv '$(exclude)'`) 25 $(TEST_CMD) -count=1 $(TEST_OPTIONS) $(FILES) && touch $(TESTFILE) || true 26 else 27 $(TEST_CMD) $(TEST_OPTIONS) ./$(package)/... && touch $(TESTFILE) || true 28 endif 29 else ifdef exclude 30 $(eval FILES = `go list ./... | egrep -iv '$(exclude)'`) 31 $(TEST_CMD) -count=1 $(TEST_OPTIONS) $(FILES) && touch $(TESTFILE) || true 32 else 33 $(TEST_CMD) -count=1 $(TEST_OPTIONS) ./... && touch $(TESTFILE) || true 34 endif 35 36 test-teardown: 37 @if [ -f "$(TESTFILE)" ]; then \ 38 echo "Tests passed, tearing down..." ;\ 39 rm -f $(TESTFILE) ;\ 40 echo "mode: atomic" > coverage.txt ;\ 41 find . -name "profile.out" | while read file; do grep -v 'mode: atomic' $${file} >> coverage.txt; rm -f $${file}; done ;\ 42 else \ 43 rm -f coverage.txt coverage.html ; find . -name "profile.out" | xargs rm -f ;\ 44 echo "Tests failed :-(" ;\ 45 exit 1 ;\ 46 fi 47 48 coverage: 49 go tool cover -html=coverage.txt -o coverage.html 50 51 test-with-coverage: test coverage 52 53 help: ## Show the available commands 54 @grep -E '^[0-9a-zA-Z_-]+:.*?## .*$$' ./Makefile | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' 55 56 install-tools: 57 go install github.com/golang/mock/mockgen@v1.6.0 58 go install mvdan.cc/gofumpt@latest 59 go install gotest.tools/gotestsum@v1.8.2 60 go install golang.org/x/tools/cmd/goimports@latest 61 bash ./internal/scripts/install-golangci-lint.sh v1.55.2 62 63 .PHONY: lint 64 lint: fmt ## Run linters on all go files 65 golangci-lint run -v --timeout 5m 66 67 .PHONY: fmt 68 fmt: install-tools ## Formats all go files 69 gofumpt -l -w -extra . 70 find . -type f -name '*.go' -exec grep -L -E 'Code generated by .*\. DO NOT EDIT.' {} + | xargs goimports -format-only -w -local=github.com/rudderlabs