-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTaskfile.yml
More file actions
293 lines (252 loc) · 7.96 KB
/
Copy pathTaskfile.yml
File metadata and controls
293 lines (252 loc) · 7.96 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
# Copyright AGNTCY Contributors (https://github.com/agntcy)
# SPDX-License-Identifier: Apache-2.0
version: "3"
env:
GOWORK: off
vars:
BIN_DIR: "{{ .ROOT_DIR }}/.bin"
ROOT_DIR:
sh: pwd
GO_VERSION: "1.26.4"
IMAGE_REPO: '{{ .IMAGE_REPO | default "ghcr.io/agntcy" }}'
IMAGE_TAG: '{{ .IMAGE_TAG | default "latest" }}'
GO_MODULES:
sh: find . -name go.mod -not -path "./tmp*" -exec dirname {} \;
GO_MODULES_UNIT_TEST:
sh: find . -name go.mod -not -path "./tmp*" -not -path "./tests*" -exec dirname {} \;
CONTROLLER_GEN_VERSION: "v0.17.3"
CONTROLLER_GEN_BIN: "sigs.k8s.io/controller-tools/cmd/controller-gen@{{ .CONTROLLER_GEN_VERSION }}"
GOLANGCI_LINT_VERSION: "2.11.3"
GOLANGCI_LINT_BIN: "{{ .BIN_DIR }}/golangci-lint-{{.GOLANGCI_LINT_VERSION}}"
LICENSEI_VERSION: "0.9.0"
LICENSEI_BIN: "{{ .BIN_DIR }}/licensei-{{.LICENSEI_VERSION}}"
MULTIMOD_VERSION: "0.29.0"
MULTIMOD_BIN: "{{ .BIN_DIR }}/multimod-{{.MULTIMOD_VERSION}}"
BAKE_ENV: 'IMAGE_REPO={{ .IMAGE_REPO }} IMAGE_TAG={{ .IMAGE_TAG }}'
IMAGE_BAKE_OPTS: "--file=docker-bake.hcl"
tasks:
default:
cmd: echo "Run the main Taskfile instead of this one."
##
## Code generation
##
crd:gen:
desc: Regenerate the DiscoveredWorkload CRD manifest from github.com/agntcy/dir/api/runtime/crd/v1
dir: ./store
deps:
- deps:controller-gen
cmds:
# Run from ./store because that module imports github.com/agntcy/dir/api/runtime/crd/v1
# (so controller-gen can resolve the Go types through its go.mod).
- go run {{ .CONTROLLER_GEN_BIN }} crd:ignoreUnexportedFields=true paths="github.com/agntcy/dir/api/runtime/crd/v1/..." output:crd:artifacts:config="../install/chart/templates"
gen:
desc: Generate all code
cmds:
- task: crd:gen
##
## Build
##
build:
desc: Build images for all components
vars:
GOARCH: "{{ .GOARCH | default ARCH }}"
cmds:
- '{{.BAKE_ENV}} docker buildx bake {{.IMAGE_BAKE_OPTS}} --set *.platform=linux/{{.GOARCH}}'
build:all:
desc: Build images for all components for multiple platforms
cmds:
- '{{.BAKE_ENV}} docker buildx bake {{.IMAGE_BAKE_OPTS}} --set *.platform=linux/amd64,linux/arm64'
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'
##
## Test
##
test:unit:
desc: Run unit tests on all modules
aliases: [test]
env:
GOWORK: off
cmds:
- for: { var: GO_MODULES_UNIT_TEST }
cmd: |
echo "Running tests in {{.ITEM}}"
go -C {{.ITEM}} test ./...
test:unit:coverage:
desc: Run unit tests with coverage
cmds:
- for: { var: GO_MODULES_UNIT_TEST }
cmd: |
echo "Running coverage tests in {{.ITEM}}"
go -C {{.ITEM}} test -race -coverprofile=coverage.out ./...
##
## Linters
##
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 each module sequentially (single process; global lock)
internal: true
cmds:
- |
set -euo pipefail
modules="{{ .GO_MODULES }}"
[ -z "$modules" ] && exit 0
for m in $modules; do
echo "Running golangci-lint in $m"
(cd "$m" && {{ .GOLANGCI_LINT_BIN }} run --config {{ .ROOT_DIR }}/.golangci.yml{{if eq .FIX "true"}} --fix{{end}} --new-from-rev="{{ .REV }}")
done
lint:helm:
desc: Run Helm linters
cmds:
- helm dependency update ./install/chart
- helm lint ./install/chart --with-subcharts
lint:
desc: Run all linters
cmds:
- task: lint:go
- task: 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: Cache license information
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: Tidy all Go module dependencies
cmds:
- for: { var: GO_MODULES }
cmd: go -C {{.ITEM}} mod tidy -go={{.GO_VERSION}}
deps:bin-dir:
desc: Create bin directory
run: once
cmd: mkdir -p {{.BIN_DIR}}
status:
- test -d {{.BIN_DIR}}
deps:controller-gen:
desc: Ensure controller-gen is installed
internal: true
preconditions:
- which go
cmds:
- cmd: go install {{.CONTROLLER_GEN_BIN}}
status:
- which controller-gen
deps:golangci-lint:
desc: Install golangci-lint
internal: true
deps:
- deps:bin-dir
cmds:
- curl -sSfL https://golangci-lint.run/install.sh | sh -s -- -b {{.BIN_DIR}} v{{.GOLANGCI_LINT_VERSION}}
- mv {{.BIN_DIR}}/golangci-lint {{.GOLANGCI_LINT_BIN}}
- chmod +x {{.GOLANGCI_LINT_BIN}}
status:
- test -x {{.GOLANGCI_LINT_BIN}}
deps:licensei:
desc: Install licensei
internal: true
deps:
- deps:bin-dir
cmds:
- curl -sfL https://raw.githubusercontent.com/goph/licensei/master/install.sh | sh -s -- -b {{.BIN_DIR}} v{{.LICENSEI_VERSION}}
- mv {{.BIN_DIR}}/licensei {{.LICENSEI_BIN}}
- chmod +x {{.LICENSEI_BIN}}
status:
- test -x {{.LICENSEI_BIN}}
deps:multimod-bin:
desc: Build the multimod binary
internal: true
deps:
- deps:bin-dir
vars:
MULTIMOD_REPO_DIR: "{{ .BIN_DIR }}/opentelemetry-go-build-tools"
cmds:
- git clone https://github.com/open-telemetry/opentelemetry-go-build-tools --branch multimod/v{{.MULTIMOD_VERSION}} {{.MULTIMOD_REPO_DIR}}
- go build -C {{.MULTIMOD_REPO_DIR}}/multimod -o {{.MULTIMOD_BIN}} main.go
- rm -rf {{.MULTIMOD_REPO_DIR}}
status:
- test -x {{.MULTIMOD_BIN}}
##
## Release
##
release:create:
desc: Prepare release
deps:
- task: deps:multimod-bin
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"
# Add release changes
- |
git add .
git commit -S --signoff -m "release(dir-runtime): 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-runtime): 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
##
## Pre-commit hooks
##
pre-commit:golangci-lint:
desc: Run golangci-lint pre-commit hook
deps:
- task: deps:golangci-lint
cmds:
- task: lint:go
vars:
FIX: "true"
##
## Cleanup
##
clean:
desc: Clean build artifacts
cmds:
- rm -rf {{ .BIN_DIR }}