-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathTaskfile.yml
More file actions
491 lines (421 loc) · 14.7 KB
/
Taskfile.yml
File metadata and controls
491 lines (421 loc) · 14.7 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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
# Copyright AGNTCY Contributors (https://github.com/agntcy)
# SPDX-License-Identifier: Apache-2.0
version: "3"
env:
GOWORK: off
includes:
vars:
taskfile: Taskfile.vars.yml
flatten: true
excludes: [default]
api:
taskfile: proto/Taskfile.yml
flatten: true
excludes: [default]
cli:
taskfile: cli/Taskfile.yml
flatten: true
excludes: [default]
test-env:
taskfile: tests/Taskfile.test-env.yml
flatten: true
excludes: [default]
deps:
taskfile: Taskfile.deps.yml
dir: "{{.BIN_DIR}}"
flatten: true
excludes: [default]
e2e:
taskfile: tests/Taskfile.yml
flatten: true
excludes: [default]
gui:
taskfile: gui/Taskfile.yml
flatten: true
excludes: [default]
importer:
taskfile: importer/Taskfile.yml
flatten: true
excludes: [default]
helm:
taskfile: install/Taskfile.yml
flatten: true
excludes: [default]
mcp:
taskfile: mcp/Taskfile.yml
flatten: true
excludes: [default]
runtime:
taskfile: runtime/Taskfile.yml
flatten: true
excludes: [default]
sdk:
taskfile: sdk/Taskfile.yml
flatten: true
excludes: [default]
server:
taskfile: server/Taskfile.yml
flatten: true
excludes: [default]
tasks:
##
## General
##
default:
cmds:
- task -l
gen:
desc: Generate code for all components
cmds:
- task: api:gen
- task: helm:gen
check:
desc: Checks for all code violations
cmds:
- task: lint
- task: license
build:
desc: Build images for all components
deps:
- task: deps:tidy
- task: gen
vars:
GOARCH: "{{ .GOARCH | default ARCH }}"
EXTRA_FLAGS: '{{ .EXTRA_FLAGS | default "" }}'
cmds:
# NOTE: Always build the images locally to include changes which are not commited
- |
# NOTE: CI env var is set by default on GitHub Actions
if [ "${CI}" != "true" ]; then
{{.BAKE_ENV}} docker buildx bake {{.IMAGE_BAKE_OPTS}} --set *.platform=linux/{{.GOARCH}} {{.EXTRA_FLAGS}}
else
images=$({{.BAKE_ENV}} docker buildx bake default --print | jq -r '.target | with_entries(.value |= .tags[0]) | to_entries[] | .value')
echo "$images" | while IFS= read -r image; do
if ! docker image inspect "$image" > /dev/null 2>&1; then
echo "Image missing: $image"
{{.BAKE_ENV}} docker buildx bake {{.IMAGE_BAKE_OPTS}} --set *.platform=linux/{{.GOARCH}} {{.EXTRA_FLAGS}}
exit 0 # NOTE: Exit as all bake target built, no need for more check
fi
done
echo "All images already exist locally. Skipping build."
fi
build:coverage:
desc: Build images for all components with coverage instrumentation
cmds:
- task: build
vars:
BAKE_ENV: "{{ .COVERAGE_BAKE_ENV }}"
# TODO: -coverpkg should be set to include all packages (server, api, utils) in the coverage report
# but it's not working as expected, so we're using the default coverage package for now
EXTRA_FLAGS: 'coverage --set *.args.BUILD_OPTS="-cover -covermode=atomic"'
build:all:
desc: Build images for all components for multiple platforms
cmds:
# TODO: make a platform variable and use build task to avoid duplication
# NOTE: Always build the images locally to include changes which are not commited
- |
# NOTE: CI env var is set by default on GitHub Actions
if [ "${CI}" != "true" ]; then
{{.BAKE_ENV}} docker buildx bake {{.IMAGE_BAKE_OPTS}} --set *.platform=linux/amd64,linux/arm64
else
images=$({{.BAKE_ENV}} docker buildx bake default --print | jq -r '.target | with_entries(.value |= .tags[0]) | to_entries[] | .value')
echo "$images" | while IFS= read -r image; do
if ! docker image inspect "$image" > /dev/null 2>&1; then
echo "Image missing: $image"
{{.BAKE_ENV}} docker buildx bake {{.IMAGE_BAKE_OPTS}} --set *.platform=linux/amd64,linux/arm64
exit 0 # NOTE: Exit as all bake target built, no need for more check
fi
done
echo "All images already exist locally. Skipping build."
fi
pull:
desc: Pull images for all components
cmds:
- |
images=$({{.BAKE_ENV}} docker buildx bake default --print | jq -r '.target | with_entries(.value |= .tags[0]) | to_entries[] | .value')
echo "$images" | while read image; do
echo "Pulling image: $image"
docker pull $image
done
push:
desc: Build and push images for all components
prompt:
- Are you sure you want to push the images to remote registry?
cmds:
- "{{.BAKE_ENV}} docker buildx bake {{.IMAGE_BAKE_OPTS}} --set=*.output=type=registry"
release:create:
desc: Prepare release
deps:
- task: deps:multimod-bin
- task: sdk:deps:python
- task: sdk:deps:javascript
vars:
RELEASE_VERSION: "{{ .RELEASE_VERSION }}"
cmds:
# Switch to new branch
- 'if [ "$(git rev-parse --abbrev-ref HEAD)" != "release/{{.RELEASE_VERSION}}" ]; then git checkout -b release/{{.RELEASE_VERSION}}; fi'
# Update versions.yaml with the new version
- 'awk ''{gsub(/version: .*/,"version: {{.RELEASE_VERSION}}")}1'' versions.yaml > versions.yaml.tmp'
- "mv versions.yaml.tmp versions.yaml"
# Update SDK packages with the new version
- "cd sdk/dir-py && {{ .UV_BIN }} version {{.RELEASE_VERSION}} && cd -"
- "cd sdk/dir-js && npm version {{.RELEASE_VERSION}} --allow-same-version --no-git-tag-version && cd -"
# Add release changes
- |
git add .
git commit -S --signoff -m "release(dir): prepare release {{.RELEASE_VERSION}}"
# Verify Go release
- |
{{ .MULTIMOD_BIN }} verify
{{ .MULTIMOD_BIN }} prerelease --all-module-sets --skip-go-mod-tidy=true --commit-to-different-branch=false
- |
git commit --amend -S --signoff -m "release(dir): prepare release {{.RELEASE_VERSION}}"
# Push prepared release
- task: release:push
release:push:
internal: true
vars:
RELEASE_VERSION: "{{ .RELEASE_VERSION }}"
prompt:
- "Are you sure you want to push the release branch release/{{.RELEASE_VERSION}} to remote repository?"
cmds:
- |
git push --set-upstream origin release/{{.RELEASE_VERSION}} || true
##
## Test
##
test:unit:
desc: Run unit tests on codebase
aliases: [test]
env:
GOWORK: off
vars:
EXTRA_ARGS: '{{ .EXTRA_ARGS | default "" }}'
cmds:
- for: { var: GO_MODULES_UNIT_TEST }
cmd: |
echo "Running tests in {{.ITEM}}"
go -C {{.ITEM}} test ./... {{.EXTRA_ARGS}}
test:unit:coverage:
desc: Run all unit tests with coverage
cmds:
- cmd: |
echo "Removing existing reports in {{.COVERAGE_DIR}}/unit"
rm -rf {{.COVERAGE_DIR}}/unit/*
if: "[ -d {{.COVERAGE_DIR}}/unit ]"
- cmd: |
echo "Creating new coverage directory: {{.COVERAGE_DIR}}/unit"
mkdir -p {{.COVERAGE_DIR}}/unit
if: "[ ! -d {{.COVERAGE_DIR}}/unit ]"
- for: { var: GO_MODULES_UNIT_TEST }
# NOTE: CI does not need go test stdout, local uses separate command to show the report
cmd: |
{{if ne .OVERRIDEN_COVERAGE_MODULES ""}}
if ! echo {{.OVERRIDEN_COVERAGE_MODULES}} | grep -q $(echo "{{.ITEM}}" | sed 's/^\.\///g'); then
echo "Skipping module {{.ITEM}}"
exit 0; # NOTE: Skip module if not in the list
fi
{{end}}
path={{.ITEM}}
coverage_dir_path="${path%/*}"
mkdir -p {{.COVERAGE_DIR}}/unit/${coverage_dir_path}
echo "Running coverage tests in {{.ITEM}}"
go test -C {{.ITEM}} -covermode=atomic -coverprofile="{{.COVERAGE_DIR}}/unit/{{.ITEM}}.out" ./... > /dev/null
test:unit:coverage:local:
desc: Run all unit tests with coverage
vars:
COVERAGE_IGNORED_FILES: '\.pb\.go|mock_|tests|testdata' # NOTE: Need to keep sync with codecov.yml manually
SHOW_TOTAL_ONLY: '{{ .SHOW_TOTAL_ONLY | default "true" }}'
cmds:
- task: test:unit:coverage
- cmd: (test -f /tmp/total_report_results.txt && rm /tmp/total_report_results.txt) || true
if: '{{ eq .SHOW_TOTAL_ONLY "true" }}'
- for: { var: GO_MODULES_UNIT_TEST }
cmd: |
{{if ne .OVERRIDEN_COVERAGE_MODULES ""}}
if ! echo {{.OVERRIDEN_COVERAGE_MODULES}} | grep -q $(echo "{{.ITEM}}" | sed 's/^\.\///g'); then
echo "Skipping module {{.ITEM}} as it is not in the list of modules to cover"
exit 0; # NOTE: Skip module if not in the list
fi
{{end}}
echo "Filtering out ignored files from coverage for {{.ITEM}}"
grep -vE "{{.COVERAGE_IGNORED_FILES}}" {{.COVERAGE_DIR}}/unit/{{.ITEM}}.out > {{.COVERAGE_DIR}}/unit/{{.ITEM}}.out.tmp
mv {{.COVERAGE_DIR}}/unit/{{.ITEM}}.out.tmp {{.COVERAGE_DIR}}/unit/{{.ITEM}}.out
echo "Running go tool cover -func={{.COVERAGE_DIR}}/unit/{{.ITEM}}.out"
{{if eq .SHOW_TOTAL_ONLY "true"}}
go tool -C {{.ITEM}} cover -func={{.COVERAGE_DIR}}/unit/{{.ITEM}}.out | grep total | sed 's@total@{{.ITEM}} - total@g' >> /tmp/total_report_results.txt
{{else}}
go tool -C {{.ITEM}} cover -func={{.COVERAGE_DIR}}/unit/{{.ITEM}}.out
{{end}}
- cmd: |
cat /tmp/total_report_results.txt | column -t | sort
rm /tmp/total_report_results.txt
if: '{{ eq .SHOW_TOTAL_ONLY "true" }}'
bench:
desc: Run bench tests on codebase
cmds: # run in sequence
- task: server:bench
- echo "Done"
##
## Linters
##
pre-commit:golangci-lint:
desc: Run golangci-lint pre-commit hook
vars:
# Override global GO_MODULES to include only changed
# modules based on files passed by pre-commit
GO_MODULES:
sh: |
# A space-separated list of file names, passed by pre-commit
# e.g. "server/controller/store.go tests/e2e/local/10_referrers_test.go"
go_files="{{.CLI_ARGS}}"
go_modules='{{.GO_MODULES | splitLines | join " " }}'
get_go_module() {
local go_file="$1"
result=""
length=0
for go_module in $go_modules; do
if [[ "./$go_file" == "$go_module"* ]]; then
if (( length < ${#go_module} )); then
result="$go_module"
length=${#go_module}
fi
fi
done
echo "$result"
}
result=()
for go_file in $go_files; do
# The file's module, e.g. "server", "tests"
go_module=$(get_go_module "$go_file")
[ -n "$go_module" ] && result+=("$go_module")
done
# sort -u to remove duplicates
result=($(printf "%s\n" "${result[@]}" | sort -u))
echo "${result[@]}"
cmds:
- task: lint:go
vars:
GO_MODULES: "{{ .GO_MODULES }}"
FIX: "true"
REV: "HEAD"
lint:go:
desc: Run Golang linters
vars:
GO_MODULES: "{{ .GO_MODULES }}"
FIX: '{{ .FIX | default "" }}'
REV: '{{ .REV | default "" }}'
deps:
- task: deps:golangci-lint
cmds:
- task: lint:go:modules
vars:
GO_MODULES: "{{ .GO_MODULES }}"
FIX: "{{ .FIX }}"
REV: "{{ .REV }}"
lint:go:modules:
desc: Run golangci-lint for all modules in parallel using Taskfile deps
internal: true
cmd:
for: { var: GO_MODULES }
task: lint:go:module
vars:
GO_MODULE: "{{.ITEM}}"
FIX: "{{.FIX}}"
REV: "{{.REV}}"
lint:go:module:
desc: Run golangci-lint for given module
internal: true
vars:
GO_MODULE: '{{ .GO_MODULE | default "." }}'
FIX: '{{ .FIX | default "" }}'
REV: '{{ .REV | default "" }}'
dir: "{{ .GO_MODULE }}"
cmd: |
echo "Running golangci-lint in {{ .GO_MODULE }}"
{{.GOLANGCI_LINT_BIN}} run \
--config {{.ROOT_DIR}}/.golangci.yml \
{{if eq .FIX "true"}}--fix{{end}} \
--new-from-rev="{{.REV}}"
lint:buf:
desc: Run Buf linters
deps:
- task: deps:protoc
- task: deps:bufbuild
dir: ./proto
cmds:
- "{{.BUFBUILD_BIN}} lint"
lint:helm:
desc: Run Helm linters
deps:
- task: deps:helm
vars:
HELM_CHARTS:
sh: find ./install/charts -maxdepth 1 -mindepth 1 -type d -exec basename {} \;
cmds:
- for: { var: HELM_CHARTS }
cmd: |
echo "Running helm lint on {{.ITEM}}"
{{.HELM_BIN}} dependency update ./install/charts/{{.ITEM}}
{{.HELM_BIN}} lint ./install/charts/{{.ITEM}} --with-subcharts
lint:
desc: Run all linters
deps:
- lint:go
- lint:buf
- lint:helm
##
## License
##
license:
desc: Check licenses
deps:
- task: deps:licensei
cmds:
- for: { var: GO_MODULES }
cmd: echo "Running licensei in {{.ITEM}}" && cd {{.ITEM}} && {{ .LICENSEI_BIN }} check --config {{.ROOT_DIR}}/.licensei.toml
license:cache:
desc: Check licenses
deps:
- task: deps:licensei
cmds:
- for: { var: GO_MODULES }
cmd: echo "Running licensei in {{.ITEM}}" && cd {{.ITEM}} && {{ .LICENSEI_BIN }} cache --config {{.ROOT_DIR}}/.licensei.toml
##
## Dependency management
##
deps:tidy:
desc: Ensure dependencies are up-to-date
cmds:
- for: { var: GO_MODULES }
cmd: go -C {{.ITEM}} mod tidy -go={{.GO_VERSION}}
##
## Various proof-of-concept tasks
##
poc:integration:
desc: Run integration against VS Code and Continue proof-of-concept.
dir: ./docs/research/integrations
prompt:
- |
Are you sure you want to run integration proof-of-concept?
This will overwrite your local workspace VSCode and Continue configuration.
vars:
RECORD_FILE: '{{ .RECORD_FILE | default "docs/research/integrations/demo.record.json" }}'
cmd: |
# Prepare Python environment
python3 -m venv venv
. ./venv/bin/activate
python3 -m pip install pyyaml
# Run script
python3 ./importer.py \
-record={{.ROOT_DIR}}/{{.RECORD_FILE}} \
-vscode_path={{.ROOT_DIR}}/.vscode \
-continue_path={{.ROOT_DIR}}/.continue/assistants
# Print env requirements
cat .env.example
poc:mcp-to-oasf:
desc: Import MCP-to-OASF Exporter Agent into the current workspace.
cmds:
- task: poc:integration
vars:
RECORD_FILE: "docs/research/integrations/mcp-to-oasf-agent/extractor.record.json"