-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
88 lines (74 loc) · 1.88 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# Build Variables
VERSION ?= $(shell git describe --tags --always)
# Go variables
GO ?= go
GOOS ?= $(shell $(GO) env GOOS)
GOARCH ?= $(shell $(GO) env GOARCH)
GOHOST ?= GOOS=$(GOOS) GOARCH=$(GOARCH) $(GO)
LDFLAGS ?= "-X main.version=$(VERSION)"
.PHONY: all
all: help
###############
##@ Development
.PHONY: clean
clean: ## Clean workspace
@ $(MAKE) --no-print-directory log-$@
rm -rf cover.out
go mod tidy
.PHONY: test
test: ## Run tests
@ $(MAKE) --no-print-directory log-$@
$(GOHOST) test -covermode count -coverprofile cover.out -v -run ^Test ./...
.PHONY: lint
lint: ## Run linters
@ $(MAKE) --no-print-directory log-$@
golangci-lint run
###########
##@ Release
.PHONY: check
check: ## Check if version exists
@ $(MAKE) --no-print-directory log-$@
ifeq ($(shell git tag -l | grep -c $(VERSION) 2>/dev/null), 0)
else
@git tag -l
@echo "VERSION: $(VERSION) has already been used. Please pass in a different version value."
@exit 2
endif
.PHONY: changelog
changelog: check ## Generate changelog
@ $(MAKE) --no-print-directory log-$@
git-chglog --next-tag $(VERSION) -o CHANGELOG.md
.PHONY: release
release: changelog ## Release a new tag
@ $(MAKE) --no-print-directory log-$@
git add CHANGELOG.md
git commit -m "chore: update changelog for $(VERSION)"
git tag $(VERSION)
git push origin main $(VERSION)
########
##@ Help
.PHONY: help
help: ## Display this help
@awk \
-v "col=\033[36m" -v "nocol=\033[0m" \
' \
BEGIN { \
FS = ":.*##" ; \
printf "Usage:\n make %s<target>%s\n", col, nocol \
} \
/^[a-zA-Z_-]+:.*?##/ { \
printf " %s%-12s%s %s\n", col, $$1, nocol, $$2 \
} \
/^##@/ { \
printf "\n%s%s%s\n", nocol, substr($$0, 5), nocol \
} \
' $(MAKEFILE_LIST)
log-%:
@grep -h -E '^$*:.*?## .*$$' $(MAKEFILE_LIST) | \
awk \
'BEGIN { \
FS = ":.*?## " \
}; \
{ \
printf "\033[36m==> %s\033[0m\n", $$2 \
}'