generated from zacscoding/go-rest-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
85 lines (65 loc) · 2.1 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
BUILD_DIR ?= build/bin
MODULE = $(shell go list -m)
define LD_FLAGS
"-X '$(MODULE)/pkg/version.Commit=$$(git rev-parse HEAD)'\
-X '$(MODULE)/pkg/version.Branch=$$(git rev-parse --abbrev-ref HEAD)'\
-X '$(MODULE)/pkg/version.Tag=$$(git name-rev --tags --name-only HEAD)'"
endef
.PHONY: tools
tools:
@go install github.com/vektra/mockery/[email protected]
@go install github.com/goreleaser/[email protected]
.PHONY: generate
generate:
@go generate ./...
.PHONY: docs
docs:
@npx @redocly/cli build-docs ./docs/api.yaml -o ./docs/docs.html
.PHONY: deps
deps:
@go mod tidy
tests: test.clean test test.build
test:
@echo "Run tests"
@go test ./... -timeout 5m
test.clean:
@echo "Clean test cache"
@go clean -testcache
test.race:
@echo "Run tests with race"
@go test ./... -race -timeout 5m
test.build:
@echo "Run build test"
@go build -o /dev/null $(MODULE)/cmd/server
.PHONY: lint
lint:
docker run --rm -v ${PWD}:/app -w /app golangci/golangci-lint:latest golangci-lint run -v --timeout 5m
.PHONY: precommit
precommit: generate deps lint
.PHONY: build run
build:
rm -rf $(BUILD_DIR)
mkdir -p $(BUILD_DIR)
@go build -ldflags=${LD_FLAGS} -v -o $(BUILD_DIR)/apiserver $(MODULE)/cmd/server
run: build
./$(BUILD_DIR)/apiserver --config ./config/local.yml
# FIXME: compose.%.% i.e. compose.${file}.${command}
compose.infra.%:
$(eval CMD = ${subst compose.infra.,,$(@)})
scripts/compose.sh infra $(CMD)
compose.local.%:
$(eval CMD = ${subst compose.local.,,$(@)})
scripts/compose.sh local $(CMD)
.PHONY: dist.clean dist release.local release.dry release
release.local: deps
export LD_FLAGS=$(LD_FLAGS) && goreleaser release --snapshot --clean
release.dry: deps
export LD_FLAGS=$(LD_FLAGS) && goreleaser build --clean
release: deps
export LD_FLAGS=$(LD_FLAGS) && goreleaser release --clean
.PHONY: relocate
relocate:
@test ${TARGET} || ( echo ">> TARGET is not set. Use: make relocate TARGET=<target>"; exit 1 )
@find . -type f -name '*.go' -exec sed -i '' -e 's/$(MODULE)/{NEW_MODULE}/g' {} \;
# Complete...
# NOTE: This does not update the git config nor will it update any imports of the root directory of this project.