-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
190 lines (170 loc) · 4.35 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
override APP_NAME=inizio
override GO_VERSION=1.18
override GOLANGCI_LINT_VERSION=v1.46.2
override SECUREGO_GOSEC_VERSION=2.12.0
override HADOLINT_VERSION=v2.10.0
override WIRE_VERSION=v0.5.0
override PROTOC_VERSION=3.3.0
override MOCKERY_VERSION=v2.13.1
override CHANGELOG_GENERATOR_VERSION=1.15.2
GOOS?=$(shell go env GOOS || echo linux)
GOARCH?=$(shell go env GOARCH || echo amd64)
CGO_ENABLED?=0
DOCKER_REGISTRY?=docker.io
DOCKER_IMAGE?=${DOCKER_REGISTRY}/insidieux/${APP_NAME}
DOCKER_TAG?=latest
CHANGELOG_GITHUB_TOKEN?=
ifeq (, $(shell which docker))
$(error "Binary docker not found in $(PATH)")
endif
.PHONY: all
all: cleanup vendor lint test build
# --- [ CI helpers ] ---------------------------------------------------------------------------------------------------
.PHONY: cleanup
cleanup:
@rm ${PWD}/bin/${APP_NAME} || true
@rm ${PWD}/coverage.out || true
@rm -r ${PWD}/vendor || true
.PHONY: tidy
tidy:
@docker run --rm \
-v ${PWD}:/project \
-w /project \
golang:${GO_VERSION} \
go mod tidy
.PHONY: vendor
vendor:
@docker run --rm \
-v ${PWD}:/project \
-w /project \
golang:${GO_VERSION} \
go mod vendor
.PHONY: lint-golangci-lint
lint-golangci-lint:
@docker run --rm \
-v ${PWD}:/project \
-w /project \
golangci/golangci-lint:${GOLANGCI_LINT_VERSION} \
golangci-lint run -v
.PHONY: lint-gosec
lint-gosec:
@docker run --rm \
-v ${PWD}:/project \
-w /project \
securego/gosec:${SECUREGO_GOSEC_VERSION} \
/project/...
.PHONY: lint-dockerfile
lint-dockerfile:
@docker run --rm \
-v ${PWD}:/project \
-w /project \
hadolint/hadolint:${HADOLINT_VERSION} \
hadolint \
/project/build/docker/cmd/inizio/Dockerfile
.PHONY: lint
lint:
@make lint-golangci-lint
@make lint-gosec
@make lint-dockerfile
.PHONY: test
test:
@rm -r ${PWD}/coverage.out || true
@docker run --rm \
-v ${PWD}:/project \
-w /project \
golang:${GO_VERSION} \
go test \
-race \
-mod vendor \
-covermode=atomic \
-coverprofile=/project/coverage.out \
/project/...
.PHONY: build
build:
@rm ${PWD}/bin/${APP_NAME} || true
@docker run --rm \
-v ${PWD}:/project \
-w /project \
-e GOOS=${GOOS} \
-e GOARCH=${GOARCH} \
-e CGO_ENABLED=${CGO_ENABLED} \
-e GO111MODULE=on \
golang:${GO_VERSION} \
go build \
-mod vendor \
-o /project/bin/${APP_NAME} \
-v /project/cmd/${APP_NAME}
# --- [ Local helpers ] ------------------------------------------------------------------------------------------------
.PHONY: wire
wire:
@docker build \
--build-arg GO_VERSION=${GO_VERSION} \
--build-arg WIRE_VERSION=${WIRE_VERSION} \
-f ${PWD}/build/docker/utils/wire/Dockerfile \
-t wire:custom \
build/docker/utils/wire
@find ${PWD} -type f -name "wire_gen.go" -delete
@docker run --rm \
-v ${PWD}:/project \
-w /project \
wire:custom \
/project/...
.PHONY: protoc
protoc: $(shell find api/protobuf -type f -name "*.proto")
@find ${PWD}/internal -type f -name "*.pb.go" -delete
for file in $^ ; do \
docker run --rm \
-v ${PWD}:/project \
-w /project \
rvolosatovs/protoc:${PROTOC_VERSION} \
--proto_path /project \
--go_out /project/pkg \
--go_opt=paths=source_relative \
--go-grpc_out=/project/pkg \
--go-grpc_opt=paths=source_relative \
$${file}; \
done
.PHONY: mockery
mockery:
ifndef MOCKERY_SOURCE_DIR
$(error MOCKERY_SOURCE_DIR is not set)
endif
ifndef MOCKERY_INTERFACE
$(error MOCKERY_INTERFACE is not set)
endif
@find ${PWD} -type f -name "mock_*_test.go" -delete
@docker run \
--rm \
-v ${PWD}:/project \
-w /project \
vektra/mockery:${MOCKERY_VERSION} \
--testonly \
--inpackage \
--case snake \
--log-level trace \
--output /project/${MOCKERY_SOURCE_DIR} \
--dir /project/${MOCKERY_SOURCE_DIR} \
--name=${MOCKERY_INTERFACE}
.PHONY: docker-image-build
docker-image-build:
ifndef DOCKER_IMAGE
$(error DOCKER_IMAGE is not set)
endif
ifndef DOCKER_TAG
$(error DOCKER_TAG is not set)
endif
@docker rmi ${DOCKER_IMAGE}:${DOCKER_TAG} || true
@docker build \
-f ${PWD}/build/docker/cmd/inizio/Dockerfile \
-t ${DOCKER_IMAGE}:${DOCKER_TAG} \
.
.PHONY: generate-changelog
generate-changelog:
@docker run --rm \
-v ${PWD}:/project \
-w /project \
-e CHANGELOG_GITHUB_TOKEN=${CHANGELOG_GITHUB_TOKEN} \
ferrarimarco/github-changelog-generator:${CHANGELOG_GENERATOR_VERSION} \
--user insidieux \
--project inizio \
--no-unreleased