Skip to content

Commit 5df7ff2

Browse files
committed
Improve Makefile help message
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
1 parent 23436be commit 5df7ff2

File tree

1 file changed

+56
-32
lines changed

1 file changed

+56
-32
lines changed

Makefile

Lines changed: 56 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -46,41 +46,41 @@ GOLANGCI_VERSION := v1.38.0
4646
.PHONY: all
4747
all: clean verify checkfmt lint test build
4848

49-
#########################
50-
## Development targets ##
51-
#########################
49+
###############
50+
##@ Development
51+
5252
.PHONY: checkfmt
53-
checkfmt: ## Check formatting of all go files
53+
checkfmt: ## Check formatting of all go files
5454
@ $(MAKE) --no-print-directory log-$@
5555
@ goimports -l $(GOIMPORTS_LOCAL_ARG) main.go cmd/ internal/ scripts/docs/ && echo "OK"
5656

5757
.PHONY: clean
58-
clean: ## Clean workspace
58+
clean: ## Clean workspace
5959
@ $(MAKE) --no-print-directory log-$@
6060
rm -rf ./$(BUILD_DIR) ./$(COVERAGE_OUT)
6161

6262
.PHONY: fmt
63-
fmt: ## Format all go files
63+
fmt: ## Format all go files
6464
@ $(MAKE) --no-print-directory log-$@
6565
goimports -w $(GOIMPORTS_LOCAL_ARG) main.go cmd/ internal/ scripts/docs/
6666

6767
.PHONY: lint
68-
lint: ## Run linter
68+
lint: ## Run linter
6969
@ $(MAKE) --no-print-directory log-$@
7070
golangci-lint run ./...
7171

7272
.PHONY: staticcheck
73-
staticcheck: ## Run staticcheck
73+
staticcheck: ## Run staticcheck
7474
@ $(MAKE) --no-print-directory log-$@
7575
$(GO) run honnef.co/go/tools/cmd/staticcheck -- ./...
7676

7777
.PHONY: test
78-
test: ## Run tests
78+
test: ## Run tests
7979
@ $(MAKE) --no-print-directory log-$@
8080
$(GO) test -coverprofile=$(COVERAGE_OUT) -covermode=atomic -v ./...
8181

8282
.PHONY: verify
83-
verify: ## Verify 'vendor' dependencies
83+
verify: ## Verify 'vendor' dependencies
8484
@ $(MAKE) --no-print-directory log-$@
8585
$(GO) mod verify
8686

@@ -89,82 +89,106 @@ verify: ## Verify 'vendor' dependencies
8989
vendor:
9090
deps:
9191

92-
###################
93-
## Build targets ##
94-
###################
92+
#########
93+
##@ Build
94+
9595
.PHONY: build
9696
build: clean ## Build binary for current OS/ARCH
9797
@ $(MAKE) --no-print-directory log-$@
9898
$(GOBUILD) -o ./$(BUILD_DIR)/$(GOOS)-$(GOARCH)/$(PROJECT_NAME)
9999

100100
.PHONY: docker
101-
docker: ## Build Docker image
101+
docker: ## Build Docker image
102102
@ $(MAKE) --no-print-directory log-$@
103103
docker build --pull --tag $(DOCKER_IMAGE):$(DOCKER_TAG) --file Dockerfile .
104104

105105
.PHONY: push
106-
push: ## Push Docker image
106+
push: ## Push Docker image
107107
@ $(MAKE) --no-print-directory log-$@
108108
docker push $(DOCKER_IMAGE):$(DOCKER_TAG)
109109

110110
.PHONY: docs
111-
docs: ## Generate document of formatter commands
111+
docs: ## Generate document of formatter commands
112112
@ $(MAKE) --no-print-directory log-$@
113113
$(GORUN) ./scripts/docs/generate.go
114114

115-
#####################
116-
## Release targets ##
117-
#####################
115+
###########
116+
##@ Release
117+
118118
PATTERN =
119119

120120
# if the last relase was alpha, beta or rc, 'release' target has to used with current
121121
# cycle release. For example if latest tag is v0.8.0-rc.2 and v0.8.0 GA needs to get
122122
# released the following should be executed: "make release version=0.8.0"
123123
.PHONY: release
124124
release: VERSION ?= $(shell echo $(CUR_VERSION) | sed 's/^v//' | awk -F'[ .]' '{print $(PATTERN)}')
125-
release: ## Prepare release
125+
release: ## Prepare release
126126
@ $(MAKE) --no-print-directory log-$@
127127
@ ./scripts/release/release.sh "$(VERSION)" "$(CUR_VERSION)" "1"
128128

129129
.PHONY: patch
130130
patch: PATTERN = '\$$1\".\"\$$2\".\"\$$3+1'
131-
patch: release ## Prepare Patch release
131+
patch: release ## Prepare Patch release
132132

133133
.PHONY: minor
134134
minor: PATTERN = '\$$1\".\"\$$2+1\".0\"'
135-
minor: release ## Prepare Minor release
135+
minor: release ## Prepare Minor release
136136

137137
.PHONY: major
138138
major: PATTERN = '\$$1+1\".0.0\"'
139-
major: release ## Prepare Major release
139+
major: release ## Prepare Major release
140+
141+
###########
142+
##@ Helpers
140143

141-
####################
142-
## Helper targets ##
143-
####################
144144
.PHONY: goimports
145-
goimports:
145+
goimports: ## Install goimports
146146
ifeq (, $(shell which goimports))
147147
GO111MODULE=off $(GO) get -u golang.org/x/tools/cmd/goimports
148148
endif
149149

150150
.PHONY: golangci
151-
golangci:
151+
golangci: ## Install golangci
152152
ifeq (, $(shell which golangci-lint))
153153
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(shell $(GO) env GOPATH)/bin $(GOLANGCI_VERSION)
154154
endif
155155

156156
.PHONY: tools
157-
tools: ## Install required tools
157+
tools: ## Install required tools
158158
@ $(MAKE) --no-print-directory log-$@
159159
@ $(MAKE) --no-print-directory goimports golangci
160160

161161
########################################################################
162162
## Self-Documenting Makefile Help ##
163163
## https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html ##
164164
########################################################################
165+
166+
########
167+
##@ Help
168+
165169
.PHONY: help
166-
help:
167-
@ grep -h -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
170+
help: ## Display this help
171+
@awk \
172+
-v "col=\033[36m" -v "nocol=\033[0m" \
173+
' \
174+
BEGIN { \
175+
FS = ":.*##" ; \
176+
printf "Usage:\n make %s<target>%s\n", col, nocol \
177+
} \
178+
/^[a-zA-Z_-]+:.*?##/ { \
179+
printf " %s%-12s%s %s\n", col, $$1, nocol, $$2 \
180+
} \
181+
/^##@/ { \
182+
printf "\n%s%s%s\n", nocol, substr($$0, 5), nocol \
183+
} \
184+
' $(MAKEFILE_LIST)
168185

169186
log-%:
170-
@ grep -h -E '^$*:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m==> %s\033[0m\n", $$2}'
187+
@grep -h -E '^$*:.*?## .*$$' $(MAKEFILE_LIST) | \
188+
awk \
189+
'BEGIN { \
190+
FS = ":.*?## " \
191+
}; \
192+
{ \
193+
printf "\033[36m==> %s\033[0m\n", $$2 \
194+
}'

0 commit comments

Comments
 (0)