-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
246 lines (193 loc) · 7.62 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
include ./standard.mk
# go install golang.org/dl/go{VERSION}@latest
# go{VERSION} download
GO=$(shell which go)
#-------------------------------------------------------------------------------
# Environment
.PHONY: install-hooks
## install-hooks: [tools] Install/upgrade the Git hooks used for ensuring consistency.
install-hooks:
@ $(HEADER) "=====> Installing Git hooks..."
cp -vf .githooks/commit-msg.sh .git/hooks/commit-msg
chmod +x .git/hooks/*
pre-commit install
@ $(BORDER) "Learn more about 'pre-commit' at:" " https://pre-commit.com" " " "Learn more about 'gommit' at:" " https://github.com/antham/gommit"
# goplicate-start:golang
#-------------------------------------------------------------------------------
# Go(lang)
.PHONY: tidy
## tidy: [go] Tidies go.mod and downloads dependencies.
tidy:
@ $(HEADER) "=====> Tidy and download the Go dependencies..."
$(GO) mod tidy -v
.PHONY: godeps
## godeps: [go] Attempts to perform a minor version upgrade of all Go dependencies.
godeps:
@ $(HEADER) "=====> Upgrade the minor versions of Go dependencies..."
find . -type f -name "go.mod" | xargs -I% dirname "%" | xargs -I@ bash -c 'cd "@" && $(GO) mod tidy -go=$(GO_VER) && $(GO) get -u -t -v ./...'
@ echo ""
@ $(YELLOW) "Run 'make tidy' to clean up the go.mod file."
.PHONY: clean-go
## clean-go: [clean] Clean Go's module cache.
clean-go:
@ $(HEADER) "=====> Cleaning Go cache..."
$(GO) clean -i -r -x -testcache -modcache -cache
.PHONY: clean-bench
## clean-bench: [clean] Cleans all benchmarking-related files.
clean-bench:
@ $(HEADER) "=====> Cleaning artifacts from benchmarks..."
- find . -type f -name "__*.out" | xargs -I% rm -fv "%"
- find . -type f -name "*.test" | xargs -I% rm -fv "%"
.PHONY: docs-cli
## docs-cli: [docs] Preview the Go library documentation on the CLI.
docs-cli:
@ $(HEADER) "=====> Displaying Go CLI documentation..."
$(GO) doc -C -all
.PHONY: docs-serve
## docs-serve: [docs] Preview the Go library documentation as displayed on pkg.go.dev.
docs-serve:
@ $(HEADER) "=====> Displaying Go HTTP documentation..."
open http://localhost:6060/pkg/github.com/northwood-labs/
godoc -index -links
.PHONY: binsize
## binsize: [docs] Analyze the size of the binary by Go package.
binsize:
@ $(HEADER) "=====> Displaying Go HTTP documentation..."
$(GO) tool nm -size "$(GOBIN)/$(BINARY_NAME)" | go-binsize-treemap > binsize.svg
rsvg-convert --width=2000 --format=png --output="binsize.png" "binsize.svg"
.PHONY: view-cov-cli
## view-cov-cli: [test] After running 'test' or 'unit', this will view the coverage report on the CLI.
view-cov-cli:
gocovsh --profile=__coverage.out
.PHONY: view-cov-html
## view-cov-html: [test] After running 'test' or 'unit', this will launch a browser to view the coverage report.
view-cov-html:
$(GO) tool cover -html=__coverage.out
.PHONY: view-cpupprof
## view-cpupprof: [test] After running 'bench', this will launch a browser to view the CPU profiler results.
view-cpupprof:
$(GO) tool pprof -http :8080 __cpu.out
.PHONY: view-mempprof
## view-mempprof: [test] After running 'bench', this will launch a browser to view the memory profiler results.
view-mempprof:
$(GO) tool pprof -http :8080 __mem.out
.PHONY: view-trace
## view-trace: [test] After running 'bench', this will launch a browser to view the trace results.
view-trace:
$(GO) tool trace __trace.out
# goplicate-end:golang
# goplicate-start:iac
#-------------------------------------------------------------------------------
# Infrastructure-as-Code
.PHONY: clean-tests
## clean-tests: [clean] Cleans all OpenTofu test artifacts.
clean-tests:
@ $(HEADER) "=====> Cleaning artifacts from tests..."
- find . -type d -name ".terraform" | xargs -I% rm -fv "%"
- find . -type d -name "terratest-*" | xargs -I% rm -fv "%"
- find . -type f -name "terraform.tfstate*" | xargs -I% rm -fv "%"
- find ./examples -type d -name "\.*" | xargs -I% rm -fv "%"
.PHONY: clean-tf
## clean-tf: [clean] Clean OpenTofu leftovers.
clean-tf:
@ $(HEADER) "=====> Cleaning OpenTofu artifacts..."
find . -type d -name "terraform.d" | xargs -I% rm -Rfv "%"
find . -type d -name ".terraform" | xargs -I% rm -Rfv "%"
find . -type f -name ".terraform.lock.hcl" | xargs -I% rm -fv "%"
# goplicate-end:iac
# goplicate-start:linting
#-------------------------------------------------------------------------------
# Linting
.PHONY: pre-commit
## pre-commit: [lint]* Runs `pre-commit` against all files.
pre-commit:
@ $(HEADER) "=====> Running pre-commit..."
pre-commit run --all-files
.PHONY: license
## license: [lint]* Checks the licenses of all files and dependencies.
license:
@ $(HEADER) "=====> Checking license usage..."
@ - trivy fs --config trivy-license.yaml --format json . 2>/dev/null > .licenses.cache.json
@ cat .licenses.cache.json | jq -Mr '[.Results[] | select(.Packages) | .Packages[] | select(.Licenses) | .Licenses[]] | to_entries | group_by(.value)[] | {Name: .[0].value, Count: length} | "\(.Name): \(.Count)"'
@ $(HEADER) "=====> Checking license headers..."
@ echo "Missing/outdated:"
@ - licensei header
# goplicate-end:linting
# goplicate-start:git
#-------------------------------------------------------------------------------
# Git Tasks
.PHONY: changelog
## changelog: [release]* Generates the CHANGELOG for the release.
changelog:
@ $(HEADER) "=====> Updating the CHANGELOG..."
git cliff -o CHANGELOG.md
.PHONY: tag
## tag: [release]* Signs and tags the release.
tag:
@ $(HEADER) "=====> Signing and tagging the release..."
@ if [ $$(git status -s -uall | wc -l) != 1 ]; then $(ERROR) "Git workspace must be clean."; exit 1; fi;
@ $(WHITE) "This release will be tagged as: $(NEXT_VERSION)"
@ echo "---------------------------------------------------------------------"
@ read -p "Press any key to continue, or press Control+C to cancel. " x;
@ echo " "
@ chag update $(NEXT_VERSION)
@ echo " "
@ $(HEADER) "These are the contents of the CHANGELOG for this release. Are these correct?"
@ $(WHITE) "---------------------------------------------------------------------"
@ chag contents
@ $(WHITE) "---------------------------------------------------------------------"
@ echo "Are these release notes correct? If not, cancel and update CHANGELOG.md."
@ read -p "Press any key to continue, or press Control+C to cancel. " x;
@ echo " "
git add .
git commit -a -m "relprep: Preparing the $(NEXT_VERSION) release." --no-verify
chag tag --sign
# goplicate-end:git
#-------------------------------------------------------------------------------
# Specific to this project.
.PHONY: clean
## clean: [clean]* Run standard cleanup tasks.
clean: clean-ds clean-bench clean-tests
.PHONY: lint
## lint: [lint]* Run linting tasks.
lint: license pre-commit
.PHONY: build
## build: [website] Perform a production build of the website.
build:
cd themes/dst2024 && npm run build
HUGO_ENV=production hugo \
--cleanDestinationDir \
--enableGitInfo \
--forceSyncStatic \
--gc \
--templateMetrics \
--templateMetricsHints \
;
.PHONY: serve
## serve: [website] Perform a development build of the website, and run a local web server.
serve:
hugo serve \
--buildDrafts \
--cleanDestinationDir \
--enableGitInfo \
--forceSyncStatic \
--gc \
--noHTTPCache \
--templateMetrics \
--templateMetricsHints \
--watch \
;
# Implement make test
# Implement make list-tests
# Implement make unit
# Implement make acc
# Implement make examples
# Implement make mutate
# Implement make fuzz
# Implement make bench
# Implement make quickbench
# Implement make terratest
# go install github.com/mdempsky/unconvert@latest
# go install github.com/nikolaydubina/smrcptr@latest
# go install golang.org/x/vuln/cmd/govulncheck@latest
# brew install k1LoW/tap/tbls