-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtaskfile.yml
More file actions
281 lines (251 loc) · 7.98 KB
/
Copy pathtaskfile.yml
File metadata and controls
281 lines (251 loc) · 7.98 KB
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
#https://taskfile.dev/
version: "3"
vars:
CHECK_COMMIT: github.com/haproxytech/check-commit/v5@v5.8.1
BETTERALIGN: github.com/dkorunic/betteralign/cmd/betteralign@v0.14.3
STATICCHECK: honnef.co/go/tools/cmd/staticcheck@v0.7.0
GOVULNCHECK: golang.org/x/vuln/cmd/govulncheck@v1.1.4
GOFUMPT: mvdan.cc/gofumpt@v0.11.0
REVIVE: github.com/mgechev/revive@v1.15.0
GOTESTSUM: gotest.tools/gotestsum@v1.13.0
GO_LICENSES: github.com/google/go-licenses@v1.6.0
env:
TMP: tmp
dotenv:
- .env
tasks:
ci:
desc: "run all checks"
cmds:
- task: check-commit
- task: tidy
- task: format
- task: lint
- task: test
vars:
COUNT: 1
build:
desc: "build gopherd binary for current platform"
cmds:
- go build -trimpath -ldflags="-s" -o gopherd .
build-upx:
desc: "build and UPX-compress gopherd (slower startup; not for all envs)"
deps:
- task: build
preconditions:
- sh: command -v upx
msg: "upx not found; install from https://upx.github.io/"
cmds:
- upx --best --lzma gopherd
build-all:
desc: "cross-compile gopherd for all release platforms"
vars:
OUT: '{{default "/tmp/gopherd-build" .OUT}}'
cmds:
- mkdir -p {{.OUT}}
- |
set -e
platforms=(
"linux/386"
"linux/amd64"
"linux/arm/5"
"linux/arm/6"
"linux/arm/7"
"linux/arm64"
"linux/ppc64le"
"linux/riscv64"
"linux/s390x"
"darwin/amd64"
"darwin/arm64"
"freebsd/amd64"
"freebsd/arm64"
)
for p in "${platforms[@]}"; do
IFS='/' read -r os arch goarm <<< "$p"
name="gopherd-${os}-${arch}"
if [ -n "$goarm" ]; then
name="${name}v${goarm}"
export GOARM="$goarm"
arch="arm"
else
unset GOARM
fi
echo "building ${name}..."
CGO_ENABLED=0 GOOS="$os" GOARCH="$arch" go build -trimpath -ldflags="-s" -o "{{.OUT}}/${name}" . || exit 1
done
echo "all builds OK ({{.OUT}}/)"
- rm -rf {{.OUT}}
test:
desc: "run Go tests"
deps:
- task: check-go-tool
vars:
TOOL: GOTESTSUM
vars:
PKG: '{{default "./..." .PKG}}'
FORMAT: '{{default "testdox" .FORMAT}}'
cmds:
- |
$(check-go-tool {{.GOTESTSUM}}) \
--format-icons=hivis \
--format={{.FORMAT}} \
--format-hide-empty-pkg \
-- {{if .COUNT}}-count={{.COUNT}}{{end}} \
-v \
{{.PKG}}
bench:
desc: "run performance benchmarks (zero-alloc logger hot path)"
vars:
COUNT: '{{default "3" .COUNT}}'
TIME: '{{default "2s" .TIME}}'
PKG: '{{default "./internal/logger/" .PKG}}'
cmds:
- go test -bench=. -benchmem -count={{.COUNT}} -benchtime={{.TIME}} {{.PKG}}
fuzz-yml-parse:
desc: "fuzz the YAML parser (yml.Parse); override duration with TIME=30s"
vars:
TIME: '{{default "10m" .TIME}}'
cmds:
- go test ./internal/yml/ -run='^$' -fuzz='^FuzzParse$' -fuzztime={{.TIME}}
fuzz-yml-unmarshal:
desc: "fuzz the YAML config decoder (yml.Unmarshal); override duration with TIME=30s"
vars:
TIME: '{{default "10m" .TIME}}'
cmds:
- go test ./internal/yml/ -run='^$' -fuzz='^FuzzUnmarshal$' -fuzztime={{.TIME}}
fuzz-memory-eval:
desc: "fuzz the memory expression evaluator (memory.Eval); override duration with TIME=30s"
vars:
TIME: '{{default "10m" .TIME}}'
cmds:
- go test ./internal/memory/ -run='^$' -fuzz='^FuzzEval$' -fuzztime={{.TIME}}
fuzz-cpu-eval:
desc: "fuzz the CPU expression evaluator (cpu.Eval); override duration with TIME=30s"
vars:
TIME: '{{default "10m" .TIME}}'
cmds:
- go test ./internal/cpu/ -run='^$' -fuzz='^FuzzEval$' -fuzztime={{.TIME}}
fuzz-service-env-refs:
desc: 'fuzz {{".VAR"}} env-ref expansion (service.ExpandEnvRefs); override duration with TIME=30s'
vars:
TIME: '{{default "10m" .TIME}}'
cmds:
- go test ./service/ -run='^$' -fuzz='^FuzzExpandEnvRefs$' -fuzztime={{.TIME}}
fuzz-service-file-refs:
desc: 'fuzz {{file "..."}} expansion (service.ExpandFileRefs); override duration with TIME=30s'
vars:
TIME: '{{default "10m" .TIME}}'
cmds:
- go test ./service/ -run='^$' -fuzz='^FuzzExpandFileRefs$' -fuzztime={{.TIME}}
fuzz-service-parse-signal:
desc: "fuzz the signal-name parser (service.ParseSignal); override duration with TIME=30s"
vars:
TIME: '{{default "10m" .TIME}}'
cmds:
- go test ./service/ -run='^$' -fuzz='^FuzzParseSignal$' -fuzztime={{.TIME}}
fuzz-control-handle-command:
desc: "fuzz the control-socket command parser (control.handleCommand); override duration with TIME=30s"
vars:
TIME: '{{default "10m" .TIME}}'
cmds:
- go test ./control/ -run='^$' -fuzz='^FuzzHandleCommand$' -fuzztime={{.TIME}}
fuzz:
desc: "run every fuzz target sequentially; per-target TIME defaults to 30s (override with TIME=10s)"
vars:
TIME: '{{default "30s" .TIME}}'
cmds:
- go test ./internal/yml/ -run='^$' -fuzz='^FuzzParse$' -fuzztime={{.TIME}}
- go test ./internal/yml/ -run='^$' -fuzz='^FuzzUnmarshal$' -fuzztime={{.TIME}}
- go test ./internal/memory/ -run='^$' -fuzz='^FuzzEval$' -fuzztime={{.TIME}}
- go test ./internal/cpu/ -run='^$' -fuzz='^FuzzEval$' -fuzztime={{.TIME}}
- go test ./service/ -run='^$' -fuzz='^FuzzExpandEnvRefs$' -fuzztime={{.TIME}}
- go test ./service/ -run='^$' -fuzz='^FuzzExpandFileRefs$' -fuzztime={{.TIME}}
- go test ./service/ -run='^$' -fuzz='^FuzzParseSignal$' -fuzztime={{.TIME}}
- go test ./control/ -run='^$' -fuzz='^FuzzHandleCommand$' -fuzztime={{.TIME}}
tidy:
desc: "run Go mod tidy"
cmds:
- go mod tidy
lint:
desc: "run Go linters"
deps:
- task: check-go-tools
vars:
TOOLS: [BETTERALIGN, REVIVE, STATICCHECK]
cmds:
- "$(check-go-tool {{.REVIVE}}) -formatter friendly -set_exit_status ./..."
- "$(check-go-tool {{.STATICCHECK}}) ./..."
- "$(check-go-tool {{.BETTERALIGN}}) ./..."
format:
desc: "format the code"
deps:
- task: check-go-tools
vars:
TOOLS: [BETTERALIGN, GOFUMPT]
cmds:
- go fix ./...
- "$(check-go-tool {{.BETTERALIGN}}) -apply ./... || true"
- "$(check-go-tool {{.GOFUMPT}}) -l -w ."
check-commit:
deps:
- task: check-go-tool
vars:
TOOL: CHECK_COMMIT
cmds:
- "$(check-go-tool {{.CHECK_COMMIT}})"
govulncheck:
deps:
- task: check-go-tool
vars:
TOOL: GOVULNCHECK
cmds:
- "$(check-go-tool {{.GOVULNCHECK}}) -show verbose ./..."
licenses:
desc: "check licenses"
deps:
- task: check-go-tool
vars:
TOOL: GO_LICENSES
cmds:
- |
PROJECT="$(go list -m)"
BIN="$(check-go-tool {{.GO_LICENSES}})"
$BIN report --ignore "$PROJECT" .
$BIN check --ignore "$PROJECT" .
legal:
desc: "check legal"
cmds:
- task: govulncheck
- task: licenses
git-install-pre-push-hook:
cmds:
- echo '#!/bin/sh' > .git/hooks/pre-push
- echo 'task ci' >> .git/hooks/pre-push
- chmod +x .git/hooks/pre-push
# internal
ensure-check-go-tool:
desc: 'ensure check-go-tool is installed'
silent: true
internal: true
status:
- command -v check-go-tool
cmds:
- go install github.com/oktalz/check-go-tool@latest
check-go-tool:
desc: 'ensure go tool is installed/available'
silent: true
internal: true
deps:
- task: ensure-check-go-tool
cmds:
- check-go-tool '{{ index . .TOOL }}' >/dev/null
check-go-tools:
desc: 'ensure all go tools are installed'
silent: true
internal: true
cmds:
- for:
var: TOOLS
task: check-go-tool
vars:
TOOL: '{{.ITEM}}'