-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
252 lines (211 loc) · 7.05 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
.PHONY: all clean docs-gen \
changelogs-gen \
readme-version-table-update \
lint sec-scan upgrade release test-all coverage test leak \
bench bench-compare
help: ## show this help
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z0-9_-]+:.*?## / {sub("\\\\n",sprintf("\n%22c"," "), $$2);printf "\033[36m%-25s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
all: docs-gen changelogs-gen readme-version-table-update
# ALL_MODULES=$(shell go work edit -json | grep DiskPath | sed -E 's:^.*gocom/(.*)":\1:' | sed -E 's:/v[0-9]+$$::')
ALL_MODULES=$(shell go work edit -print | grep "./" | cut -d ' ' -f 8 | sed 's|\./||')
ALL_MODULES_SPACE_SEP=$(shell echo $(ALL_MODULES) | xargs printf "%s ")
ALL_MODULES_DOTDOTDOT=$(shell echo $(ALL_MODULES) | xargs printf "./%s/... ")
SHELL = /bin/bash
########
# docs #
########
test-echo:
echo $(ALL_MODULES_SPACE_SEP)
docs-gen: ## generate docs for every module, as markdown thanks to https://github.com/princjef/gomarkdoc
@( \
for module in $(ALL_MODULES_SPACE_SEP); do \
gomarkdoc --output ./$$module/README.md ./$$module/ && \
printf "docs generated for $$module!\n"; \
git commit -m "docs: update docs for module $$module" ./$$module/README.md; \
done \
)
##############
# changelogs #
##############
changelogs-gen: ## generate changelog for every module.
@for module in $(ALL_MODULES_SPACE_SEP); do \
awk -v module="$$module" '{gsub(/TAG_MODULE/, module); print}' ./cliff.toml > ./cliff.toml.tmp && \
mv ./cliff.toml.tmp ./cliff.toml && \
git cliff \
--include-path "**/$$module/*" \
-o ./$$module/CHANGELOG.md && \
awk -v module="$$module" '{gsub(module, "TAG_MODULE"); print}' ./cliff.toml > ./cliff.toml.tmp && \
mv ./cliff.toml.tmp ./cliff.toml && \
printf "\nchangelog generated for $$module!\n"; \
git commit -m "docs(changelog): update CHANGELOG.md for $$(git describe --abbrev=0 --tags $$(git rev-list --tags="$$module/v[0-9].*" --max-count=1))" ./$$module/CHANGELOG.md; \
done
#############################
# versions update in README #
#############################
readme-version-table-update: ## update version table in README.md to latest version.
@( \
while IFS= read -r line; do \
module=$$(echo "$$line" | grep -oE '\[\w+/\w+\]' | tr -d '[]'); \
if [ ! -z "$$module" ]; then \
latest_version=$$(git tag --list "$${module}/v*" | sed "s:$${module}/v::" | sort -t . -k1n -k2n -k3n | tail -n 1); \
echo "$$line" | sed "s:\(.*| \)[[:digit:]]\+\(\.[[:digit:]]\+\)\{0,2\}\(.*\):\1$$latest_version\3:"; \
else \
echo "$$line"; \
fi; \
done < README.md > README.md.tmp; \
mv README.md.tmp README.md; \
git commit -m "docs(readme): update latest versions" ./README.md \
)
########
# lint #
########
lint-all: ## lints the entire codebase
@( \
for module in $(ALL_MODULES_SPACE_SEP); do \
if [ -z $$module ]; then \
break; \
fi; \
pushd $$module > /dev/null; \
echo "checking" $$module; \
golangci-lint run ; \
popd > /dev/null; \
done \
)
lint-specific: ## lints a specific module
@( \
select module in $(ALL_MODULES_SPACE_SEP); do \
if [ -z $$module ]; then \
break; \
fi; \
pushd $$module > /dev/null; \
golangci-lint run ; \
popd > /dev/null; \
break; \
done \
)
#######
# sec #
#######
sec-scan: trivy-scan vuln-scan-all ## scan for sec issues
trivy-scan: ## scan for sec issues with trivy (trivy binary needed)
trivy fs --exit-code 1 --no-progress --severity HIGH ./
vuln-scan-all: ## scan for sec issues with govulncheck (govulncheck binary needed)
@( \
for module in $(ALL_MODULES_SPACE_SEP); do \
if [ -z $$module ]; then \
break; \
fi; \
pushd $$module > /dev/null && \
govulncheck ./... && \
popd > /dev/null; \
done \
)
###########
# upgrade #
###########
upgrade: ## upgrade selection module dependencies (beware, it can break everything)
@( \
select module in $(ALL_MODULES_SPACE_SEP); do \
if [ -z $$module ]; then \
break; \
fi; \
pushd $$module > /dev/null; \
go mod tidy && \
go get -t -u ./... && \
go mod tidy ; \
popd > /dev/null; \
break; \
done \
)
########
# deps #
########
download-all: ## download all dependencies for the different modules
@( \
for module in $(ALL_MODULES_SPACE_SEP); do \
if [ -z $$module ]; then \
break; \
fi; \
pushd $$module > /dev/null; \
go mod download ; \
popd > /dev/null; \
done \
)
###########
# release #
###########
release: release-specific readme-version-table-update ## release selection module, gen-changelog, gen docs, commit and tag and update the version table
release-specific: ## release selection module, gen-changelog, gen docs, commit and tag
@( \
select module in $(ALL_MODULES_SPACE_SEP); do \
if [ -z $$module ]; then \
break; \
fi; \
printf "here is the $$module latest tag present: "; \
git tag --list --sort=version:refname "$$module/v*" | tail -1; \
printf "what tag do you want to give? (use the form $$module/vX.X.X): "; \
read -r TAG; \
sed -i '' -E "s:TAG_MODULE:$$module:g" ./cliff.toml && \
git cliff \
--tag $$TAG \
--include-path "**/$$module/*" \
-o ./$$module/CHANGELOG.md && \
sed -i '' -E "s:$$module:TAG_MODULE:g" ./cliff.toml && \
printf "\nchangelog generated for $$module!\n"; \
git add ./$$module/CHANGELOG.md && \
git commit -m "docs(changelog): update CHANGELOG.md for $$TAG" ./$$module/CHANGELOG.md; \
gomarkdoc --output ./$$module/README.md ./$$module/ && \
printf "docs generated for $$module!\n"; \
git add ./$$module/README.md && \
git commit -m "docs: update docs for module $$module" ./$$module/README.md; \
go work sync && \
git add ./go.work ./go.work.sum && \
git commit -m "chore: update go.work" ./go.work ./go.work.sum; \
git tag $$TAG && \
printf "\nrelease tagged $$TAG !\n"; \
printf "\nrelease and tagging has been done, if you are OK with everything, just git push origin $$(git describe --abbrev=0 --tags $$(git rev-list --tags="$$module/v[0-9].*" --max-count=1))\n"; \
break; \
done \
)
#########
# tests #
#########
test-all:
@go test -race -failfast $(ALL_MODULES_DOTDOTDOT)
coverage:
go test $(ALL_MODULES_DOTDOTDOT) -race -failfast -covermode=atomic -coverprofile=./coverage.out
test: ## launch tests for a selection module
@( \
select module in $(ALL_MODULES_SPACE_SEP); do \
if [ -z $$module ]; then \
break; \
fi; \
go test ./$$module/... -cover -race -covermode=atomic -failfast -coverprofile=./$$module/coverage.out; \
break; \
done \
)
bench: ## launch bench for a selection module
@( \
select module in $(ALL_MODULES_SPACE_SEP); do \
if [ -z $$module ]; then \
break; \
fi; \
go test ./$$module/... -bench=. -benchmem | tee ./$$module/bench.txt; \
break; \
done \
)
bench-compare: ## compare benchs results for selection module
@( \
select module in $(ALL_MODULES_SPACE_SEP); do \
if [ -z $$module ]; then \
break; \
fi; \
benchstat ./$$module/bench.txt; \
break; \
done \
)
###########
# GCI #
###########
gci-format: ## format repo through gci linter
gci write ./ --skip-generated -s standard -s default -s "Prefix(github.com/induzo)"