This repository was archived by the owner on Jan 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathTaskfile.yml
More file actions
261 lines (219 loc) · 8.53 KB
/
Taskfile.yml
File metadata and controls
261 lines (219 loc) · 8.53 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
# https://taskfile.dev
version: '3'
vars:
PACKAGE: github.com/microsoft/azure-schema-operator
CONTROLLER_APP: manager
SCRIPTS_ROOT: ./scripts
CHART_ROOT: ./charts/azure-schema-operator/
TEST_RESOURCE_PREFIX: schematest
TEST_LIVE_RESOURCE_PREFIX: schemalivetest
VERSION: "v0.1.2"
# Version tags for the controller must start with "v1", e.g. "v1.0.0-alpha.0".
# sh: '{{.SCRIPTS_ROOT}}/build-version.py v0'
DEBUG:
sh: if [ $DEBUG ]; then echo "-v"; fi
VERSION_FLAGS: -ldflags "-X {{.PACKAGE}}/internal/version.BuildVersion={{.VERSION}}"
ENVTEST_K8S_VERSION: 1.24.2
CONTROLLER_DOCKER_IMAGE: azureschemaoperator:{{.VERSION}}
PUBLIC_REGISTRY: ghcr.io/microsoft/azure-schema-operator/
LOCAL_REGISTRY_CONTROLLER_DOCKER_IMAGE: rscomplianceacr.azurecr.io/schema-operator:v0.0.4
dotenv: ['.env']
tasks:
default:
cmds:
- echo "{{.ENVTEST}}"
silent: true
ci:
desc: Run all CI checks.
deps:
- controller:test-deps
- controller:ci
cmds:
- echo 'task verify-no-changes'
ci-live:
desc: Run all CI checks with live Azure resources. Requires that auth environment variables are set.
deps:
- controller:test-deps
cmds:
- task: controller:test-integration-envtest
controller:gen-helm-manifest:
desc: Generate helm manifest using Kustomize for the release
cmds:
- '{{.SCRIPTS_ROOT}}/generate-helm-manifest_mac.sh {{.LOCAL_REGISTRY_CONTROLLER_DOCKER_IMAGE}} {{.PUBLIC_REGISTRY}} {{.VERSION}} `pwd`/'
package-helm:
desc: Package the helm chart
cmds:
- helm package ./charts/azure-schema-operator/ -d ./charts --version {{.VERSION}}
helm-docs:
desc: generate helm docs (readme file)
dir: '{{.CHART_ROOT}}'
cmds:
- helm-docs
controller:generate-crds:
desc: Run controller-gen to generate {{.CONTROLLER_APP}} CRD files.
cmds:
- make generate
controller:test-deps:
desc: Run make to prepare for tests.
cmds:
- make manifests generate fmt vet envtest
controller:build:
desc: Generate the {{.CONTROLLER_APP}} binary.
deps: [controller:generate-crds]
sources:
# excluding the ./apis directory here
- 'go.mod'
- 'go.sum'
- '*.go'
- 'internal/**/*.go'
- 'pkg/**/*.go'
- 'cmd/main.go'
cmds:
- CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build {{.VERSION_FLAGS}} -o ./bin/{{.CONTROLLER_APP}} main.go
controller:docker-build:
desc: Builds the {{.CONTROLLER_APP}} Docker image.
deps: [controller:build]
sources:
- Dockerfile
- ./bin/{{.CONTROLLER_APP}}
cmds:
- docker build . -t {{.CONTROLLER_DOCKER_IMAGE}}
controller:docker-tag-version:
desc: Tags the {{.CONTROLLER_APP}} Docker image with the appropriate version.
deps: [controller:docker-build]
cmds:
- 'if [ -z "{{.DOCKER_PUSH_TARGET}}" ]; then echo "Error: DOCKER_PUSH_TARGET must be set"; exit 1; fi'
- docker tag {{.CONTROLLER_DOCKER_IMAGE}} "{{.DOCKER_PUSH_TARGET}}/{{.CONTROLLER_DOCKER_IMAGE}}"
- task: package-helm
controller:docker-push-local:
desc: Pushes the controller container image to a local registry
deps: [controller:docker-build]
cmds:
- docker tag {{.CONTROLLER_DOCKER_IMAGE}} {{.LOCAL_REGISTRY_CONTROLLER_DOCKER_IMAGE}}
- docker push {{.LOCAL_REGISTRY_CONTROLLER_DOCKER_IMAGE}}
controller:ci:
desc: Run Tests to make sure the code works as intended
deps: [controller:generate-crds]
cmds:
- task: controller:test-cover
# - task: controller:test-integration-ci
# checks must be after test as that will generate code
- task: basic-checks
# lint must be at end after code is formatted
- task: controller:lint-full
controller:lint:
desc: Run fast lint checks.
# deps: [controller:generate-crds]
dir: '{{.CONTROLLER_ROOT}}'
cmds:
- golangci-lint run -v ./...
controller:lint-full:
desc: Run all lint checks.
# deps: [controller:generate-crds]
dir: '{{.CONTROLLER_ROOT}}'
cmds:
- golangci-lint run -v --fast=false --timeout 5m ./...
controller:test:
desc: Run {{.CONTROLLER_APP}} unit tests.
dir: '{{.CONTROLLER_ROOT}}'
# controller:run-kustomize-for-envtest isn't strictly required here, but running it here so that
# integration tests can be run manually (via IDE) after running "task"
# deps: [controller:generate-crds, controller:run-kustomize-for-envtest]
cmds:
- go test -short -tags=noexit -v -timeout 10m -run '{{default ".*" .TEST_FILTER}}' ./pkg/...
pkg:filtered-test:
desc: Run ginkgo tests for a specific filter
dir: '{{.CONTROLLER_ROOT}}'
cmds:
- ginkgo -v --label-filter={{.FILTER}} ./pkg/...
controller:test-cover:
desc: Run {{.CONTROLLER_APP}} unit tests and output coverage.
# deps: [controller:generate-crds]
cmds:
- ginkgo -v --procs=4 --compilers=4 --label-filter="!live" --timeout 10m --keep-going --cover -covermode set --coverprofile=controller-coverage.out -coverpkg="./pkg/..." ./pkg/...
controller:test-integration-ci:
desc: Run integration tests for CI
deps: [controller:test-integration-envtest-cover]
controller:test-integration-envtest:
desc: Run integration tests with envtest using record/replay.
deps: [controller:test-deps]
cmds:
# -race fails at the moment in controller-runtime
- go test -timeout 15m -run '{{default ".*" .TEST_FILTER}}' {{.VERBOSE}} ./...
vars:
VERBOSE:
sh: if [ $TEST_FILTER ]; then echo "-v"; fi
env:
KUBEBUILDER_ASSETS:
sh: ./bin/setup-envtest use {{.ENVTEST_K8S_VERSION}} -p path
# sh: $(pwd)/bin/setup-envtest use {{.ENVTEST_K8S_VERSION}} -p path
test-integration-envtest-live:
desc: Run integration tests with envtest using record/replay.
deps: [controller:test-deps]
cmds:
- go test -timeout 15m -run '{{default ".*" .TEST_FILTER}}' {{.VERBOSE}} ./...
vars:
VERBOSE:
sh: if [ $TEST_FILTER ]; then echo "-v"; fi
env:
LIVE_TEST: true
KUBEBUILDER_ASSETS:
sh: setup-envtest use {{.ENVTEST_K8S_VERSION}} -p path
controller:test-integration-envtest-cover:
desc: Run integration tests with envtest using record/replay and output coverage.
deps: [controller:test-deps]
cmds:
# -race fails at the moment in controller-runtime
- go test -covermode atomic -coverprofile=coverage-integration-envtest.out -coverpkg="./..." -timeout 15m -run '{{default ".*" .TEST_FILTER}}' ./...
env:
KUBEBUILDER_ASSETS:
sh: $(pwd)/bin/setup-envtest use {{.ENVTEST_K8S_VERSION}} -p path
basic-checks:
deps: [header-check] #, specifier-check]
header-check:
desc: Ensure all files have an appropriate license header.
cmds:
- '{{.SCRIPTS_ROOT}}/check_headers.py'
# specifier-check:
# desc: Check that format specifiers %v and %+v are not used
# # Both %v and %+v result in all the values from structs being dumped into the string. If that
# # struct happens to contain a secret or sensitive information, it ends up dumped out in an
# # uncontrolled way, potentially leading to a security issue or a problem with PII disclosure.
# # The buried risk here is that while %v might be safe now, a future change to the struct might
# # introduce a disclosure later on.
# cmds:
# - cmd: echo "==> Checking format specifiers <=="
# silent: true
# - cmd: '! git grep -e "%+v" -e "%v" --break --heading --line-number -I "*.go"'
format-code:
desc: Ensure all code is formatted
cmds:
- gofmt -l -s -w .
build-docs-site:
dir: docs/site
cmds:
- hugo
run-docs-site:
dir: docs/site
cmds:
- hugo server
verify-no-changes:
desc: Checks that there are no uncommitted modifications to files
cmds:
- cmd: 'if [ -n "{{.CHANGED}}" ]; then echo "Error: files were modified during the build (did you forget to commit generated files?):"; echo "{{.CHANGED}}"; git diff; exit 1; fi'
silent: true
vars:
CHANGED:
sh: git status --porcelain
az-login:
desc: Runs AZ login
cmds:
- echo "Place holder for az login"
# - az login --service-principal -u {{.AZURE_CLIENT_ID}} -p {{.AZURE_CLIENT_SECRET}} --tenant {{.AZURE_TENANT_ID}}
# - az account set --subscription {{.AZURE_SUBSCRIPTION_ID}}
cleanup-azure-resources:
desc: Removes any resources created by the integration tests.
deps: [az-login]
cmds:
- echo "Place holder for test resource group cleanup"
# - '{{.SCRIPTS_ROOT}}/delete-old-resourcegroups.sh -p "{{.TEST_RESOURCE_PREFIX}}"'