-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskfile.yaml
More file actions
215 lines (186 loc) · 5.06 KB
/
Copy pathTaskfile.yaml
File metadata and controls
215 lines (186 loc) · 5.06 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
version: '3'
vars:
LOCALBIN:
sh: echo "$(pwd)/bin"
GOBIN:
sh: |
gobin=$(go env GOBIN)
[ -n "$gobin" ] && echo "$gobin" || echo "$(go env GOPATH)/bin"
GOLANGCI_LINT: '{{.LOCALBIN}}/golangci-lint'
CONTROLLER_GEN: '{{.LOCALBIN}}/controller-gen'
CHAINSAW: '{{.LOCALBIN}}/chainsaw'
YAMLFMT: '{{.LOCALBIN}}/yamlfmt'
CRD_REF_DOCS: '{{.LOCALBIN}}/crd-ref-docs'
GOLANGCI_LINT_VERSION: v2.1.6
CONTROLLER_GEN_VERSION: v0.18.0
CHAINSAW_VERSION: v0.2.15
YAMLFMT_VERSION: v0.21.0
CRD_REF_DOCS_VERSION: v0.2.0
tasks:
default:
silent: true
cmds:
- task --list
##
## Development
##
fmt:
desc: Run go fmt against code
run: once
cmds:
- go fmt ./...
vet:
desc: Run go vet against code
run: once
cmds:
- GOOS=linux go vet ./...
test:
desc: Run unit tests then e2e tests
cmds:
- task: test:unit
- task: test:e2e
test:unit:
desc: Run unit tests
deps: [fmt, vet]
cmds:
- GOOS=linux go test $(go list ./... | grep -v /e2e) -coverprofile cover.out
lint:
desc: Run golangci-lint, yamlfmt, and yaml extension check
deps: [install:golangci-lint, install:yamlfmt]
cmds:
- '{{.GOLANGCI_LINT}} run'
- '{{.YAMLFMT}} -lint ./...'
- |
files=$(find . -name "*.yml" \
-not -path "./.git/*" \
-not -path "./bin/*" \
-not -path "./vendor/*")
if [ -n "$files" ]; then
echo "error: .yml files must use .yaml extension:"
echo "$files" | sed 's/^/ /'
exit 1
fi
lint-fix:
desc: Run golangci-lint and yamlfmt with fixes
deps: [install:golangci-lint, install:yamlfmt]
cmds:
- '{{.GOLANGCI_LINT}} run --fix'
- '{{.YAMLFMT}} ./...'
##
## Build
##
build:
desc: Build all packages
deps: [fmt, vet]
cmds:
- go build ./...
##
## Code generation
##
generate:
desc: Run all code generators in order
cmds:
- task: generate:methods
- task: generate:manifests
- task: generate:docs
generate:methods:
desc: Generate deepcopy methods
deps: [install:controller-gen]
cmds:
- '{{.CONTROLLER_GEN}} object:headerFile="hack/boilerplate.go.txt" paths="./..."'
generate:manifests:
desc: Generate CRD manifests
deps: [install:controller-gen]
cmds:
- '{{.CONTROLLER_GEN}} crd paths="./api/..." output:crd:artifacts:config=config/crd'
generate:docs:
desc: Generate API reference documentation
deps: [install:crd-ref-docs]
cmds:
- rm -rf docs/api && mkdir -p docs/api
- '{{.CRD_REF_DOCS}} --renderer=markdown --source-path=api/v1alpha1 --output-path=docs/api/vpc.md --config=.crd-ref-docs.yaml'
##
## Testing
##
ci:
desc: Run the full CI pipeline locally
cmds:
- task: build
- task: lint
- task: test:unit
- task: test:e2e
test:e2e:
desc: Run the full E2E suite
cmds:
- scripts/e2e.sh
##
## Cleanup
##
clean:
desc: Remove build artifacts and temporary files
cmds:
- rm -rf bin/
- rm -f cover.out
##
## Dependencies
##
install:
desc: Install all development tools
deps: [install:golangci-lint, install:controller-gen, install:chainsaw, install:yamlfmt, install:crd-ref-docs]
install:golangci-lint:
desc: Download golangci-lint locally if necessary
run: once
cmds:
- task: install-tool
vars:
TARGET: '{{.GOLANGCI_LINT}}'
PACKAGE: github.com/golangci/golangci-lint/v2/cmd/golangci-lint
VERSION: '{{.GOLANGCI_LINT_VERSION}}'
install:controller-gen:
desc: Download controller-gen locally if necessary
run: once
cmds:
- task: install-tool
vars:
TARGET: '{{.CONTROLLER_GEN}}'
PACKAGE: sigs.k8s.io/controller-tools/cmd/controller-gen
VERSION: '{{.CONTROLLER_GEN_VERSION}}'
install:chainsaw:
desc: Download chainsaw locally if necessary
run: once
cmds:
- task: install-tool
vars:
TARGET: '{{.CHAINSAW}}'
PACKAGE: github.com/kyverno/chainsaw
VERSION: '{{.CHAINSAW_VERSION}}'
install:yamlfmt:
desc: Download yamlfmt locally if necessary
run: once
cmds:
- task: install-tool
vars:
TARGET: '{{.YAMLFMT}}'
PACKAGE: github.com/google/yamlfmt/cmd/yamlfmt
VERSION: '{{.YAMLFMT_VERSION}}'
install:crd-ref-docs:
desc: Download crd-ref-docs locally if necessary
run: once
cmds:
- task: install-tool
vars:
TARGET: '{{.CRD_REF_DOCS}}'
PACKAGE: github.com/elastic/crd-ref-docs
VERSION: '{{.CRD_REF_DOCS_VERSION}}'
install-tool:
internal: true
cmds:
- mkdir -p {{.LOCALBIN}}
- |
if [ ! -f "{{.TARGET}}-{{.VERSION}}" ]; then
echo "Downloading {{.PACKAGE}}@{{.VERSION}}"
rm -f "{{.TARGET}}" || true
GOBIN={{.LOCALBIN}} go install {{.PACKAGE}}@{{.VERSION}}
mv "{{.TARGET}}" "{{.TARGET}}-{{.VERSION}}"
fi
ln -sf "{{.TARGET}}-{{.VERSION}}" "{{.TARGET}}"