forked from FalcoSuessgott/golang-cli-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
51 lines (38 loc) · 1.32 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
projectname?={{ .appName }}
default: help
.PHONY: help
help: ## list makefile targets
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.PHONY: build
build: ## build golang binary
@go build -ldflags "-X main.version=$(shell git describe --abbrev=0 --tags)" -o $(projectname)
.PHONY: install
install: ## install golang binary
@go install -ldflags "-X main.version=$(shell git describe --abbrev=0 --tags)"
.PHONY: run
run: ## run the app
@go run -ldflags "-X main.version=$(shell git describe --abbrev=0 --tags)" main.go
.PHONY: bootstrap
bootstrap: ## install build deps
go generate -tags tools tools/tools.go
PHONY: test
test: clean ## display test coverage
go test --cover -parallel=1 -v -coverprofile=coverage.out ./...
go tool cover -func=coverage.out | sort -rnk3
PHONY: clean
clean: ## clean up environment
@rm -rf coverage.out dist/ $(projectname)
PHONY: cover
cover: ## display test coverage
go test -v -race $(shell go list ./... | grep -v /vendor/) -v -coverprofile=coverage.out
go tool cover -func=coverage.out
PHONY: fmt
fmt: ## format go files
gofumpt -w .
gci write .
PHONY: lint
lint: ## lint go files
golangci-lint run -c .golang-ci.yml
.PHONY: pre-commit
pre-commit: ## run pre-commit hooks
pre-commit run --all-files