-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
98 lines (78 loc) · 2.44 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
ROOT := $(shell git rev-parse --show-toplevel)
OS := $(shell uname -s | awk '{print tolower($$0)}')
ARCH := amd64
VERSION := $(shell git describe --abbrev=0 --tags)
LD_FLAGS := -X main.version=$(VERSION) -s -w
SOURCE_FILES ?= ./internal/... ./pkg/... ./cmd/...
export CGO_ENABLED := 0
export GO111MODULE := on
export GOBIN := $(shell pwd)/bin
.PHONY: all
all: help
.PHONY: help
help: ### Show targets documentation
ifeq ($(OS), linux)
@grep -P '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | \
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
else
@awk -F ':.*###' '$$0 ~ FS {printf "%15s%s\n", $$1 ":", $$2}' \
$(MAKEFILE_LIST) | grep -v '@awk' | sort
endif
GOLANGCI_LINT := $(GOBIN)/golangci-lint
GOLANGCI_LINT_VERSION := v1.46.2
golangci-lint:
$(call go-install,github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION))
GORELEASER := $(GOBIN)/goreleaser
GORELEASER_VERSION := v1.9.2
goreleaser:
$(call go-install,github.com/goreleaser/goreleaser@$(GORELEASER_VERSION))
.PHONY: generate
generate: vendor ### Generate code
@bash ./hack/hack.sh
.PHONY: docker-redis
docker-redis: ### Spin up docker redis
@docker compose -f docker-compose.redis.yml up -d
.PHONY: docker
docker: ### Spin up docker services
@docker compose -f docker-compose.redis.yml -f docker-compose.yml up -d
.PHONY: clean
clean: ### Clean build files
@rm -rf ./bin
@go clean
.PHONY: build
build: build-catalog build-stock ### Build all binaries
.PHONY: build-%
build-%: clean ### Build binary
@go build -tags netgo -a -v -ldflags "${LD_FLAGS}" -o ./bin/app ./cmd/$*/*.go
@chmod +x ./bin/*
.PHONY: run-%
run-%: lint ### Quick run
@CGO_ENABLED=1 go run -race cmd/$*/*.go
.PHONY: deps
deps: ### Optimize dependencies
@go mod tidy
.PHONY: vendor
vendor: ### Vendor dependencies
@go mod vendor
.PHONY: lint
lint: golangci-lint ### Lint
$(GOLANGCI_LINT) run
.PHONY: release
release: goreleaser ### Dry-run release
$(GORELEASER) release --snapshot --rm-dist
.PHONY: test-clean
test-clean: ### Clean test cache
@go clean -testcache ./...
.PHONY: test
test: ### Run tests
@go test -v -coverprofile=cover.out -timeout 10s ./...
.PHONY: cover
cover: test ### Run tests and generate coverage
@go tool cover -html=cover.out -o=cover.html
# go-get-tool will 'go get' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-install
@[ -f $(1) ] || { \
go install $(1) ; \
}
endef