diff --git a/.gitignore b/.gitignore index bd43436..461da1e 100644 --- a/.gitignore +++ b/.gitignore @@ -122,3 +122,4 @@ Temporary Items *.icloud # End of https://www.toptal.com/developers/gitignore/api/go,linux,emacs,macos +my-log diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9fb50c4 --- /dev/null +++ b/Makefile @@ -0,0 +1,43 @@ +SOURCES = $(wildcard *.go) $(wildcard **/*.go) +OUT=my-log +GOBIN=$(shell go env GOBIN) +COVEROUT=cover.out +COVERHTML=cover.html + +.PHONY: help +help: ## Show help for documented recipes + @echo "Make recipes:" + @echo + @grep -E '^[a-zA-Z0-9_#-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' + +.PHONY: clean +clean: ## Removes temporary and build files + rm -v $(COVEROUT) $(COVERHTML) $(OUT) || true + +.PHONY: fmt ## Runs go fmt +fmt: ## Runs go fmt + go fmt ./... + +.PHONY: test +test: ## Test application and generate coverage report + rm $(COVEROUT) 2>/dev/null || true + $(MAKE) $(COVEROUT) + +$(COVEROUT): $(SOURCES) + go test ./... -race -cover -coverprofile $@ + +$(COVERHTML): $(COVEROUT) + go tool cover -html=$< -o $@ + +.PHONY: report +report: $(COVERHTML) ## Generate a coverage report + +.PHONY: open-report +open-report: report ## Open the coverage report in the default browser + xdg-open $(COVERHTML) + +.PHONY: build +build: $(OUT) ## Builds the application + +$(OUT): $(SOURCES) + go build -o $@