Repository navigation
Expand file tree
/
Copy pathTaskfile.yml
More file actions
339 lines (297 loc) · 10.1 KB
/
Copy pathTaskfile.yml
File metadata and controls
339 lines (297 loc) · 10.1 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
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
version: "3"
# include .env files using dotenv
dotenv: [".env", ".env.local"]
# When doing interpolation of variables, Task will look for the below.
# They are listed below in order of importance (i.e. most important first):
#
# * Variables declared in the task definition
# * Variables given while calling a task from another (See Calling another task above)
# * Variables of the included Taskfile (when the task is included)
# * Variables of the inclusion of the Taskfile (when the task is included)
# * Global variables (those declared in the vars: option in the Taskfile)
# * Environment variables
vars:
NAME: valkyrie
BUILD_DIR: '{{if eq .OS "Windows_NT"}}$PWD/build{{else}}build{{end}}'
GIT_VERSION:
sh: bash .github/tools/version.sh
VERSION: "{{ coalesce .VERSION .GIT_VERSION }}" # pick first non-empty version
BUILD_CMD: CGO_ENABLED=0 go build -ldflags="-w -s -X main.appVersion={{.VERSION}}"
# workaround to use built-in windows commands
SHELL: '{{if eq .OS "Windows_NT"}}powershell{{end}}'
FORCE: '{{if eq .OS "Windows_NT"}}-fo{{end}}'
# https://taskfile.dev/usage/#watch-tasks
interval: "500ms"
tasks:
default:
desc: default task
cmds: # run the tasks sequentially
- task: tidy
- task: dependency:vulncheck
- task: gen
- task: lint
- task: test
tidy:
desc: tidy module
sources:
- ./go.mod
generates:
- ./go.sum
cmds:
- go mod tidy
generate:
desc: generate code
aliases:
- gen
sources:
- ./**/generate.go
- ./provider/*/service.go
- ./provider/caleta/caletagaming-caleta-gaming_system_api_operators_guide-1.5-oapi3.yaml
- ./pam/pam_api.yml
generates:
- ./**/*.gen.go
- ./**/generated/*
cmds:
- go generate ./...
lint:
desc: run linters
cmds:
- task: lint:go
- task: lint:docker
lint:go:
desc: run linters configured by .golangci.yml
sources:
- ./**/*.go
- go.mod
cmds:
- golangci-lint run
preconditions:
- sh: "command -v golangci-lint"
msg: "Please install golangci-lint first: https://golangci-lint.run/usage/install/"
lint:yaml:
desc: lint yaml files
cmds:
- docker run --rm -it -v $(pwd):/data cytopia/yamllint -f parsable $(git ls-files '*.yml' '*.yaml')
lint:docker:
desc: lint Dockerfile
sources:
- Dockerfile
cmds:
- docker run --rm -i hadolint/hadolint hadolint - < ./Dockerfile
test:
desc: run all tests
sources:
- ./**/*.go
- go.mod
cmds:
- go install gotest.tools/gotestsum@latest
- gotestsum
test:coverage:
desc: run all tests with code coverage
cmds:
- go test -cover -covermode=count -coverprofile=profile.cov ./...
- go tool cover -func profile.cov
- defer: "{{.SHELL}} rm profile.cov"
run:
desc: run the application locally
aliases:
- run:local
cmds:
- go run -tags=dev main.go -config configs/testdata/valkyrie_config.test.yml
build:prepare:
internal: true
run: once
cmds:
- "{{.SHELL}} mkdir {{.FORCE}} -p {{.BUILD_DIR}}"
build:
desc: build binary. Use cli args to build dev variant "-- -tags=dev"
aliases: [build:local]
deps:
- build:prepare
sources:
- ./**/*.go
- go.mod
vars:
FILE: '{{if eq .OS "Windows_NT"}}.exe{{end}}'
generates:
- "{{.BUILD_DIR}}/{{.NAME}}{{.FILE}}"
cmds:
- "go build {{.CLI_ARGS}} -o {{.BUILD_DIR}}/{{.NAME}}{{.FILE}}"
build:linux:
desc: build linux binary. Use cli args to build dev variant "-- -tags=dev"
deps:
- build:prepare
cmds:
- "{{.SHELL}} mkdir {{.FORCE}} -p {{.BUILD_DIR}}/linux-amd64"
- GOOS=linux GOARCH=amd64 {{.BUILD_CMD}} {{.CLI_ARGS}} -o {{.BUILD_DIR}}/linux-amd64/{{.NAME}}
build:windows:
desc: build windows binary. Use cli args to build dev variant "-- -tags=dev"
deps:
- build:prepare
cmds:
- "{{.SHELL}} mkdir {{.FORCE}} -p {{.BUILD_DIR}}/windows-amd64"
- GOOS=windows GOARCH=amd64 {{.BUILD_CMD}} {{.CLI_ARGS}} -o {{.BUILD_DIR}}/windows-amd64/{{.NAME}}.exe
build:osx:
desc: build OSX binary. Use cli args to build dev variant "-- -tags=dev"
deps:
- build:prepare
- build:osx:amd64
- build:osx:arm64
build:osx:amd64:
desc: build OSX amd64 binary
internal: true
cmds:
- "{{.SHELL}} mkdir {{.FORCE}} -p {{.BUILD_DIR}}/darwin-amd64"
- GOOS=darwin GOARCH=amd64 {{.BUILD_CMD}} {{.CLI_ARGS}} -o {{.BUILD_DIR}}/darwin-amd64/{{.NAME}}
build:osx:arm64:
desc: build OSX arm64 binary
internal: true
cmds:
- "{{.SHELL}} mkdir {{.FORCE}} -p {{.BUILD_DIR}}/darwin-arm64"
- GOOS=darwin GOARCH=arm64 {{.BUILD_CMD}} {{.CLI_ARGS}} -o {{.BUILD_DIR}}/darwin-arm64/{{.NAME}}
build:all:
desc: build for all supported platforms. Use cli args to build dev variant "-- -tags=dev"
deps:
- build:linux
- build:windows
- build:osx
package:linux:
desc: package linux binary
deps:
- build:linux
cmds:
- "{{.SHELL}} cp scripts/svc.sh {{.BUILD_DIR}}/linux-amd64"
- "{{.SHELL}} cp scripts/valkyrie.service.template {{.BUILD_DIR}}/linux-amd64"
- "{{.SHELL}} cp configs/testdata/valkyrie_config.minimal.yml {{.BUILD_DIR}}/linux-amd64/config.yml"
- tar -C {{.BUILD_DIR}}/linux-amd64 -zcf {{.BUILD_DIR}}/{{.NAME}}-{{.VERSION}}-linux-amd64.tar.gz {{.NAME}} svc.sh valkyrie.service.template config.yml
package:windows:
desc: package windows binary
deps:
- build:windows
cmds:
- "{{.SHELL}} cp configs/testdata/valkyrie_config.minimal.yml {{.BUILD_DIR}}/windows-amd64/config.yml"
- tar -C {{.BUILD_DIR}}/windows-amd64 -zcf {{.BUILD_DIR}}/{{.NAME}}-{{.VERSION}}-windows-amd64.tar.gz {{.NAME}}.exe config.yml
package:osx:
desc: package osx binary
deps:
- build:osx
cmds:
- "{{.SHELL}} cp configs/testdata/valkyrie_config.minimal.yml {{.BUILD_DIR}}/darwin-amd64/config.yml"
- "{{.SHELL}} cp configs/testdata/valkyrie_config.minimal.yml {{.BUILD_DIR}}/darwin-arm64/config.yml"
- tar -C {{.BUILD_DIR}}/darwin-amd64 -zcf {{.BUILD_DIR}}/{{.NAME}}-{{.VERSION}}-darwin-amd64.tar.gz {{.NAME}} config.yml
- tar -C {{.BUILD_DIR}}/darwin-arm64 -zcf {{.BUILD_DIR}}/{{.NAME}}-{{.VERSION}}-darwin-arm64.tar.gz {{.NAME}} config.yml
package:all:
desc: package all binaries
deps:
- package:linux
- package:windows
- package:osx
changelog:
desc: print latest changes in CHANGELOG.md
cmds:
- bash .github/tools/changelog.sh {{.VERSION}}
clean:
desc: clean project
vars:
FORCE: '{{if eq .OS "Windows_NT"}}-fo{{else}}-f{{end}}'
cmds:
- "{{.SHELL}} rm -r {{.FORCE}} {{.BUILD_DIR}}"
- go clean
release:
desc: create a release
cmds:
- "{{.SHELL}} cat .github/RELEASING.md" # print instructions, as releases are not automated
docker:build:
desc: build a docker image
vars:
DOCKER_REPO: '{{ default "localhost:5000" .DOCKER_REPO }}'
TAG: '{{ default "latest" .VERSION }}'
WIN_SED: git ls-remote --get-url | %{$_ -replace "\.git$",""}
SED: git ls-remote --get-url | sed "s/\.git$//g"
REMOTE: '{{if eq .OS "Windows_NT"}} ''{{.WIN_SED}}'' {{else}} {{.SED}} {{end}}' # Remove ".git" from remote url
SRC_REPO:
sh: "{{.SHELL}} {{.REMOTE}}"
cmds:
- docker build --tag "{{.DOCKER_REPO}}/{{.NAME}}:{{.TAG}}" --tag "{{.DOCKER_REPO}}/{{.NAME}}:latest" --label="org.opencontainers.image.source={{.SRC_REPO}}" --build-arg VERSION={{.VERSION}} .
docker:push:
desc: push docker image
deps:
- docker:build
vars:
DOCKER_REPO: '{{ default "localhost:5000" .DOCKER_REPO }}'
TAG: '{{ default "latest" .VERSION }}'
cmds:
- docker push "{{.DOCKER_REPO}}/{{.NAME}}:{{.TAG}}"
- docker push "{{.DOCKER_REPO}}/{{.NAME}}:latest"
helm:package:
desc: package helm chart
dir: helm
cmds:
- helm package . --app-version {{.VERSION}} --version {{.VERSION}}
preconditions:
- sh: "command -v helm"
msg: "Please install helm first: https://helm.sh/docs/intro/install/"
helm:push:
desc: push helm chart to registry
dir: helm
deps:
- helm:package
cmds:
- helm push $(ls valkyrie-*.tgz) "oci://{{.HELM_REPO}}"
preconditions:
- sh: test $HELM_REPO
msg: Please set the $HELM_REPO environment variable to an OCI compatible repository
doc:
desc: documentation
cmds:
- go install golang.org/x/tools/cmd/godoc@latest
- echo 'documentation served from http://localhost:8080/'
- godoc -http=localhost:8080
dependency:outdated:
desc: list directly dependent modules that can be upgraded
cmds:
- bash ./scripts/dependency-outdated.sh
dependency:graph:
desc: graph of upstream modules with gmchart
cmds:
- go install github.com/PaulXu-cn/go-mod-graph-chart/gmchart@latest
- go mod graph | gmchart
dependency:licenses:
desc: list project dependency licenses
cmds:
- go install github.com/google/go-licenses@latest
- go-licenses report .
binmap:
desc: treemap breakdown of binary
vars:
FILE: '{{if eq .OS "Windows_NT"}}.exe{{end}}'
OPEN: '{{if eq .OS "Windows_NT"}}start{{else}}open{{end}}'
deps:
- build
cmds:
- go install github.com/nikolaydubina/go-binsize-treemap@latest
- go tool nm -size ./build/valkyrie{{.FILE}} | go-binsize-treemap > ./build/binsize.svg
- "{{.SHELL}} {{.OPEN}} ./build/binsize.svg"
dependency:vulncheck:
desc: analyze dependencies for known vulnerabilities
sources:
- ./go.mod
cmds:
- go run golang.org/x/vuln/cmd/govulncheck@latest ./...
dependency:list:
desc: List all module dependencies
cmds:
- go list -m -u all
test:bench:
desc: run benchmarks
cmds:
- go test -bench=. -benchmem ./...
version:
desc: print project version
silent: true
cmds:
- echo {{.VERSION}}
c4model:
desc: run structurizr lite on localhost:8090 for viewing and editing the c4 model of Valkyrie
cmds:
- docker run -it --rm -p 8090:8080 -v $PWD/structurizr:/usr/local/structurizr structurizr/lite