-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
69 lines (48 loc) · 2.11 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
help: ## Show help messages.
@grep -E '^[0-9a-zA-Z_-]+:(.*?## .*)?$$' $(MAKEFILE_LIST) | sed 's/^Makefile://' | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
name=BINARYNAME
main=./cmd/*.go
timeout=10m
dir="./..."
run=.
flags=
# Export any env variable which may be needed.
# This automatically picks up the override, if provided.
#
# Try to run both "go run cmd/main.go" and "make run" and compare the outputs.
ifneq ($(shell find ./config -name "dev.env"),)
include ./config/dev.env
export $(shell sed 's/=.*//' ./config/dev.env)
else
include ./config/dev.env.example
export $(shell sed 's/=.*//' ./config/dev.env.example)
endif
.PHONY: dependencies
dependencies: ## Install dependencies needed to work on this repo
@go install mvdan.cc/gofumpt@latest
@go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
.PHONY: run
run: ## Example: make run env={env file} cmd={cmd} flags={flags}
@go run $(main) $(cmd) $(flags)
# This is a great place to use e.g. golangci
# This can be quite taxing, you don't need to have any linting set up.
.PHONY: lint
lint: ## Run various linters
gofumpt -w -l .
golangci-lint run ./...
.PHONY: build
build: ## Builds the binary
@CGO_ENABLED=0 go build -a -installsuffix cgo -ldflags="-w -s" -o ./bin/$(name) $(main)
.PHONY: unit_test
unit_test: ## Run unit tests. You can set: [run, timeout, short, dir, flags]. Example: make unit_test flags="-race".
@go mod tidy; go test -trimpath -failfast --timeout=$(timeout) $(short) $(dir) -run $(run) $(flags)
.PHONY: integration_test
integration_test: ## Run integration. You can set: [run, timeout, short, dir, flags]. Example: make integration_test flags="-race".
@go mod tidy; go test -trimpath -failfast --timeout=$(timeout) -tags=integration $(short) $(dir) -run $(run) $(flags)
.PHONY: setup_test_dependencies
setup_test_dependencies: ## Set up dependencies needed by the integration test, such as a database.
.PHONY: reset_test_dependencies
reset_test_dependencies: ## Tear down dependencies created by setup_test_dependencies
.PHONY: mocks
mocks: ## Generate mocks in all packages.
@go generate ./...