-
Notifications
You must be signed in to change notification settings - Fork 0
/
Taskfile.yml
340 lines (303 loc) · 8.32 KB
/
Taskfile.yml
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
# https://taskfile.dev
version: "3"
vars:
############################################################
# Variables used by multiple tasks
############################################################
REV:
sh: git describe --long --tags --match='v*' --dirty 2>/dev/null || git rev-list -n1 HEAD
IMAGE_REPO: ghcr.com/act3-ai/hops
# Use port 5001 because the default podman machine uses port 5000
TEST_REGISTRY_PORT: 5001
TEST_REGISTRY_NAME: testreg
############################################################
# Tool versions
############################################################
# renovate: datasource=go depName=github.com/elastic/crd-ref-docs
CRD_REF_DOCS_VERSION: v0.0.12
# renovate: datasource=go depName=github.com/caarlos0/svu
SVU_VERSION: main
# renovate: datasource=go depName=github.com/google/ko
KO_VERSION: v0.15.2
# renovate: datasource=go depName=github.com/golangci/golangci-lint
GOLANGCILINT_VERSION: v1.58.2
# renovate: datasource=go depName=golang.org/x/vuln/cmd/govulncheck
GOVULNCHECK_VERSION: latest
# renovate: datasource=go depName=go.abhg.dev/doc2go
DOC2GO_VERSION: v0.8.1
tasks:
default:
desc: "Build from source with -race flag"
deps: [generate]
env:
CGO_ENABLED: 1
cmds:
- mkdir -p ./bin
- go build -race -o bin/hops ./cmd/hops
generates:
- bin/hops
build:
desc: "Build from source"
deps: [generate]
env:
CGO_ENABLED: 0
cmds:
- mkdir -p ./bin
- go build -o bin/hops ./cmd/hops
generates:
- bin/hops
build-trimmed:
desc: "Build from source (stripped/trimmed)"
deps: [generate]
env:
CGO_ENABLED: 0
cmds:
- mkdir -p ./bin
- go build -trimpath -ldflags="-s -w" -o bin/hops ./cmd/hops
generates:
- bin/hops
build-linux:
desc: "Build from source for linux/amd64"
aliases: [build-linux]
env:
GOOS: linux
GOARCH: amd64
CGO_ENABLED: 0
deps: [generate]
cmds:
- mkdir -p ./bin
- go build -o bin/hops--linux-amd64 ./cmd/hops
generates:
- bin/hops--linux-amd64
install:
desc: "Install from source with go install"
deps: [generate]
cmds:
- go install ./cmd/hops
generate:
desc: "Run go generate"
cmds:
- go generate ./...
sources:
- gen.go
- internal/cli/
- cmd/hops/
generates:
- docs/cli/
lint:
desc: "Lint project"
deps: [tool:golangci-lint]
cmds:
- tool/golangci-lint run
govulncheck:
desc: "Check Go package vulnerabilities"
deps: [tool:govulncheck]
cmds:
- tool/govulncheck ./...
test:
desc: "Run unit tests"
deps: [generate]
aliases: [test-unit]
cmds:
- go test ./...
runprof:
desc: "Run CPU/memory profiling"
deps: [generate]
sources:
- internal/**/*.go
generates:
- cpu.prof
- mem.prof
cmds:
- "go test -cpuprofile cpu.prof -memprofile mem.prof -bench=. ./internal/actions -count=10"
cpuprof:
desc: "Run CPU/memory profiling"
deps: [runprof]
cmds:
- "go tool pprof -http=: cpu.prof"
memprof:
desc: "Run CPU/memory profiling"
deps: [runprof]
cmds:
- "go tool pprof -http=: mem.prof"
clean:
desc: Clean test directories
cmds:
- rm -rf HOPS_CACHE
- rm -rf HOMEBREW_CACHE
- rm -rf HOMEBREW_PREFIX
- direnv reload
image:
desc: "Build container image with Docker"
deps: [build-linux]
cmds:
- |
docker build \
--build-arg HOPS_EXECUTABLE=bin/hops--linux-amd64 \
-t {{.IMAGE_REPO}} .
image-run:
desc: "Run latest docker container"
cmds:
- docker run -it {{.IMAGE_REPO}}:latest
image-scan:
desc: "Scan latest container image with grype"
aliases: [grype]
cmds:
- grype {{.IMAGE_REPO}}:latest
ko:
desc: "Build multiplatform distroless image with ko"
deps: [tool:ko]
env:
VERSION: "{{.REV}}"
KO_DOCKER_REPO: "{{.IMAGE_REPO}}/distroless"
cmds:
- tool/ko build -B --image-label version="{{.REV}}" ./cmd/hops
startreg:
desc: Start a local registry for testing purposes
cmds:
- podman run --name {{.TEST_REGISTRY_NAME}} --rm -d -p {{.TEST_REGISTRY_PORT}}:5000 registry:2
- |
echo "# To use the test registry, run the following:"
echo "export HOPS_REGISTRY=localhost:{{.TEST_REGISTRY_PORT}}"
echo "export HOPS_REGISTRY_PLAIN_HTTP=true"
stopreg:
desc: Start a local registry for testing purposes
cmds:
- podman stop {{.TEST_REGISTRY_NAME}}
next-version:
desc: Print next version
cmds:
- git cliff --bumped-version
next-changelog:
desc: Preview updated CHANGELOG.md
vars:
VERSION:
sh: git cliff --bumped-version
cmds:
- git cliff --tag {{.VERSION}} --unreleased --strip header
next-changelog-all:
desc: Preview updated CHANGELOG.md
vars:
VERSION:
sh: git cliff --bumped-version
cmds:
- git cliff --tag {{.VERSION}}
git-status-clean:
desc: Check Git status
internal: true
preconditions:
- sh: '[ -z "$(git status --porcelain)" ]'
msg: Git status unclean
release-tag-internal:
internal: true
deps: [git-status-clean]
requires:
vars: [TAG]
env:
RELEASE_NOTES:
sh: git cliff --tag "{{.TAG}}" --unreleased --strip header
prompt: 'Create release tag "{{.TAG}}"?'
cmds:
- echo "{{.TAG}}" > VERSION
- task: update-changelog
vars:
TAG: "{{.TAG}}"
- git add VERSION CHANGELOG.md
- 'git commit -m "chore(release): {{.TAG}}" -m "$RELEASE_NOTES"'
- git tag "{{.TAG}}"
release-tag:
desc: Create release tag
deps: [git-status-clean]
cmds:
- task: release-tag-internal
vars:
TAG:
sh: git cliff --bumped-version
release-tag-*:
desc: Create specific release tag
deps: [git-status-clean]
cmds:
- task: release-tag-internal
vars:
TAG: "{{index .MATCH 0}}"
goreleaser:
desc: Run GoReleaser
deps: [git-status-clean]
cmds:
- |
goreleaser release --clean \
--release-notes <(git cliff --current --strip header | tail -n +3)
update-changelog:
desc: Update CHANGELOG.md
requires:
vars: [TAG]
cmds:
- git cliff --tag "{{.TAG}}" --output CHANGELOG.md
# crd-ref-docs: Generates markdown documentation for CRDs
tool:crd-ref-docs:
desc: "Install crd-ref-docs CRD documentation generator"
cmds:
- task: versioned-go-pkg
vars:
VERSION: "{{.CRD_REF_DOCS_VERSION}}"
PKG: github.com/elastic/crd-ref-docs
# svu: manage semantic versions based on git log
tool:svu:
desc: "Install svu versioning tool"
cmds:
- task: versioned-go-pkg
vars:
VERSION: "{{.SVU_VERSION}}"
PKG: github.com/caarlos0/svu
# ko: builds application images for Go projects
tool:ko:
desc: "Install ko builder"
cmds:
- task: versioned-go-pkg
vars:
VERSION: "{{.KO_VERSION}}"
PKG: github.com/google/ko
# golangci-lint: lints Go code
tool:golangci-lint:
desc: "Install golangci-lint linter"
cmds:
- task: versioned-go-pkg
vars:
VERSION: "{{.GOLANGCILINT_VERSION}}"
PKG: github.com/golangci/golangci-lint/cmd/golangci-lint
# govulncheck: checks Go package vulnerabilities
tool:govulncheck:
desc: "Install govulncheck linter"
cmds:
- task: versioned-go-pkg
vars:
VERSION: "{{.GOVULNCHECK_VERSION}}"
PKG: golang.org/x/vuln/cmd/govulncheck
# doc2go: renders static Go package docs
tool:doc2go:
desc: "Install doc2go documentation generator"
cmds:
- task: versioned-go-pkg
vars:
VERSION: "{{.DOC2GO_VERSION}}"
PKG: go.abhg.dev/doc2go
# Generalized task for installing Go tools
versioned-go-pkg:
desc: "Installs a versioned Go tool"
internal: true
requires:
vars:
- PKG
- VERSION
vars:
NAME: "{{base .PKG}}"
MARKER: tool/.{{.NAME}}@{{.VERSION}}
TOOL: tool/{{.NAME}}
status:
- test -f {{.MARKER}}
- test -f {{.TOOL}}
cmds:
- rm -f tool/.{{.NAME}}@*
- mkdir -p tool
- GOBIN=$PWD/tool go install {{.PKG}}@{{.VERSION}}
- touch {{.MARKER}}