-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
106 lines (88 loc) · 2.28 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# Build Variables
NAME = rsgrants
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 bin/
rm -rf build/
rm -rf dist/
rm -rf cover.out
rm -f ./$(NAME)
go mod tidy
.PHONY: test
test: ## Run tests
@ $(MAKE) --no-print-directory log-$@
$(GOHOST) test -covermode atomic -coverprofile cover.out -v ./...
.PHONY: lint
lint: ## Run linters
@ $(MAKE) --no-print-directory log-$@
golangci-lint run
#########
##@ Build
.PHONY: build
build: clean ## Build rsgrants
@ $(MAKE) --no-print-directory log-$@
@mkdir -p bin/
CGO_ENABLED=0 $(GOHOST) build -ldflags=$(LDFLAGS) -o bin/$(NAME) ./main.go
alpine: clean ## Build binary for alpine docker image
@ $(MAKE) --no-print-directory log-$@
env GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags=$(LDFLAGS) -o $(NAME) ./main.go
.PHONY: docker
docker: DOCKER_TAG ?= dev
docker: alpine ## Build Docker image
@ $(MAKE) --no-print-directory log-$@
docker build --pull --tag ghcr.io/goodwaygroup/$(NAME):$(DOCKER_TAG) .
make clean
###########
##@ Release
.PHONY: changelog
changelog: ## Generate changelog
@ $(MAKE) --no-print-directory log-$@
git-chglog --next-tag $(VERSION) -o CHANGELOG.md
.PHONY: release
release: ## Release a new tag
@ $(MAKE) --no-print-directory log-$@
./release.sh $(VERSION)
.PHONY: docs
docs: ## Generate new docs
@ $(MAKE) --no-print-directory log-$@
DOCS_MD=1 go run ./main.go > docs/$(NAME).md
DOCS_MAN=1 go run ./main.go > docs/$(NAME).8
########
##@ 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 \
}'