-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathTaskInternal.yml
More file actions
291 lines (253 loc) · 10.1 KB
/
TaskInternal.yml
File metadata and controls
291 lines (253 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
# Contains internal implementation details, variables, and helper tasks.
version: '3'
vars:
# --- Basic ---
GO_CMD: go
GOTOOL_CMD: "{{.GO_CMD}} tool"
CONTAINER_TOOL:
sh: 'command -v podman || command -v docker'
OPENAPI_URL: https://api.aiven.io/doc/openapi.json # Source URL for the spec
OPENAPI_FILE: openapi.json
OPA: opa # Open Policy Agent binary for policy checks
# --- Architecture & Build Paths ---
USER_HOME:
sh: 'echo $HOME'
ARCH:
sh: "{{.GO_CMD}} env GOOS GOARCH | tr '\n' '_' | sed 's/_$//'" # Get OS/Arch (e.g., linux_amd64)
BUILD_DEV_DIR: '{{.USER_HOME}}/.terraform.d/plugins/registry.terraform.io/aiven-dev/aiven/0.0.0+dev/{{.ARCH}}'
BUILD_DEV_BIN: "{{.BUILD_DEV_DIR}}/terraform-provider-aiven_v0.0.0+dev"
# --- Go Tools ---
GOLANGCILINT: "{{.GOTOOL_CMD}} golangci-lint"
TFPLUGINDOCS: "{{.GOTOOL_CMD}} tfplugindocs"
TERRAFMT: "{{.GOTOOL_CMD}} terrafmt"
SELPROJ: "{{.GOTOOL_CMD}} selproj"
MOCKERY: "{{.GOTOOL_CMD}} mockery"
TESTSUM: "{{.GOTOOL_CMD}} gotestsum"
# --- Pre-commit ---
PRECOMMIT_IMAGE: "ghcr.io/antonbabenko/pre-commit-terraform:v1.99.1"
PRECOMMIT_CONFIG: ".pre-commit-config.yaml"
# --- Defaults ---
PKG_PATH: internal # Default Go package path for acceptance tests
TEST_COUNT: 1 # Default count for running tests
ACC_TEST_TIMEOUT: 180m # Default timeout for acceptance tests
ACC_TEST_PARALLELISM: 10 # Default parallelism for acceptance tests
SWEEP: global # Default scope for resource sweeper
OLD_SCHEMA: .oldSchema.json # Temp file to store previous provider schema for diffing
CHANGELOG_CMD: "{{.GO_CMD}} run ./generators/changelog/..." # Command to run the internal changelog generation tool
CHANGELOG_FILE: CHANGELOG.md
# --- Docs ---
DEPRECATED_RESOURCES: "alloydbomni cassandra influxdb m3 redis" # List of deprecated resources and data sources to exclude from docs
env:
CGO_ENABLED: 0 # Disable CGO for all Go commands by default for static builds
tasks:
#-------------------------------------
# Lint Sub-Tasks
#-------------------------------------
lint-go:
desc: "Run Go static analysis using golangci-lint"
cmds:
- "{{.GOLANGCILINT}} run --build-tags all --timeout=30m ./..."
lint-test:
desc: "Check HCL formatting using terrafmt"
cmds:
- "{{.TERRAFMT}} diff ./internal -cfq"
lint-docs:
desc: "Validate provider documentation consistency"
cmds:
- "{{.TFPLUGINDOCS}} generate --rendered-website-dir tmp"
- mkdir -p docs/data-sources docs/resources
- |
for resource in {{.DEPRECATED_RESOURCES}}; do
mv tmp/data-sources/${resource}*.md docs/data-sources/ || true
mv -f tmp/resources/${resource}*.md docs/resources/ || true
done
- rm -rf tmp
- "{{.TFPLUGINDOCS}} validate --provider-name aiven"
- |
for resource in {{.DEPRECATED_RESOURCES}}; do
rm -f docs/data-sources/${resource}*.md
rm -f docs/resources/${resource}*.md
done
semgrep:
desc: "Run Semgrep static analysis security scan"
preconditions:
- sh: test -f .semgrep.yml
msg: ".semgrep.yml configuration file not found."
- sh: "{{.CONTAINER_TOOL}} info >/dev/null 2>&1"
msg: "Container engine (Docker/Podman) is not running. Please start the service."
cmds:
- "{{.CONTAINER_TOOL}} run --rm -v \"${PWD}:/src\" semgrep/semgrep semgrep --config=\"p/auto\" --config=\".semgrep.yml\" --include=\"**\" --metrics=off --error"
#-------------------------------------
# Format Sub-Tasks
#-------------------------------------
fmt-go:
desc: "Format go code using golangci-lint"
cmds:
- "{{.GOLANGCILINT}} fmt"
fmt-test:
desc: "Format HCL code using terrafmt"
cmds:
- "{{.TERRAFMT}} fmt ./internal -fq --fix-finish-lines"
fmt-imports:
desc: "Remove blank lines in Go import blocks and run goimports"
cmds:
- find . -type f -name '*.go' -exec sed -i'' -e '/^import ($/,/^)$/{/^[[:space:]]*$/d;}' {} +
- goimports -local "github.com/aiven/terraform-provider-aiven" -w .
fmt-precommit:
desc: "Run pre-commit hooks using Docker"
preconditions:
- sh: "test -f {{.PRECOMMIT_CONFIG}}"
msg: "Pre-commit configuration file '{{.PRECOMMIT_CONFIG}}' not found."
- sh: "{{.CONTAINER_TOOL}} info >/dev/null 2>&1"
msg: "Container engine (Docker/Podman) is not running. Please start the service."
cmds:
- "{{.CONTAINER_TOOL}} run --rm -v \"{{.ROOT_DIR}}:/lint\" -w /lint {{.PRECOMMIT_IMAGE}} run -a"
fmt-fast:
desc: "Fast formatting for docs/ after generation, removes trailing whitespace and empty lines from markdown files"
cmds:
- find docs -name "*.md" -type f -exec sed -i'' -e 's/[[:space:]]*$//' {} +
- find docs -name "*.md" -type f -exec sed -i'' -e '${/^$/d}' {} +
fmt-changelog:
desc: "Format CHANGELOG.md using changelog generator"
cmds:
- "{{.CHANGELOG_CMD}} -format -changelog={{.CHANGELOG_FILE}}"
#-------------------------------------
# Generate Sub-Tasks
#-------------------------------------
get-spec:
desc: "Download/Update the Aiven OpenAPI spec"
aliases:
- spec
preconditions:
- sh: command -v curl
msg: "'curl' command not found. Please install curl to download the OpenAPI spec."
cmds:
- "curl -sL -o {{.OPENAPI_FILE}} {{.OPENAPI_URL}}"
generates:
- "{{.OPENAPI_FILE}}"
gen-go:
desc: "Run Go code generation (`go generate ./...`)"
cmds:
- "{{.GO_CMD}} generate ./..."
gen-plugin:
desc: "Generate Terraform Plugin Framework resources"
vars:
no_spec: '{{.no_spec | default "false"}}'
cmds:
- task: '{{if eq .no_spec "true"}}nothing{{else}}get-spec{{end}}'
- task: gen-plugin-generator
gen-plugin-generator:
desc: "Run the plugin generator (requires openapi.json to exist)"
preconditions:
- sh: test -f {{.OPENAPI_FILE}}
msg: "{{.OPENAPI_FILE}} not found. Run 'task get-spec' to download it."
cmds:
- "{{.GO_CMD}} run ./generators/plugin/..."
gen-plugin-report:
desc: "Generate plugin migration report"
cmds:
- "{{.GO_CMD}} run ./generators/pluginreport/..."
gen-docs:
desc: "Generate Terraform provider documentation"
cmds:
- rm -f docs/.DS_Store
- "{{.TFPLUGINDOCS}} generate --provider-name terraform-provider-aiven"
- |
for resource in {{.DEPRECATED_RESOURCES}}; do
rm -f docs/data-sources/${resource}*.md
rm -f docs/resources/${resource}*.md
done
- find docs/resources -name "*.md" -type f -exec sed -i'' -e 's/^- `default` (String)/- `default` (String, Deprecated) Use specific CRUD timeouts instead./' {} +
generate:
desc: "Run all code generation tasks"
vars:
no_spec: '{{.no_spec | default "false"}}'
cmds:
- task: gen-go
- task: gen-plugin
vars:
no_spec: '{{.no_spec}}'
- task: gen-plugin-report
- task: gen-docs
- task: mockery
#-------------------------------------
# Schema Sub-Tasks
#-------------------------------------
dump-schemas:
desc: "Save current provider schemas to {{.OLD_SCHEMA}} for later diffing"
cmds:
- "{{.CHANGELOG_CMD}} -save -schema={{.OLD_SCHEMA}}"
generates: ["{{.OLD_SCHEMA}}"]
diff-schemas:
desc: "Compare current schemas against {{.OLD_SCHEMA}} and update CHANGELOG.md"
cmds:
- "{{.CHANGELOG_CMD}} -diff -schema={{.OLD_SCHEMA}} -changelog={{.CHANGELOG_FILE}}"
- rm {{.OLD_SCHEMA}}
sources: ["**/*.go"]
generates: ["{{.CHANGELOG_FILE}}"]
load-codegen:
desc: "Update go-client-codegen module dependency"
cmds:
- "{{.GO_CMD}} get github.com/aiven/go-client-codegen@latest"
- "{{.GO_CMD}} mod tidy"
load-schemas:
desc: "Update Go client codegen and API schema module dependencies"
cmds:
- task: load-codegen
- "{{.GO_CMD}} get github.com/aiven/go-api-schemas@latest"
- "{{.GO_CMD}} mod tidy"
dump-mockery:
desc: "Generate mocks after client updates"
cmds:
- task: mockery
mockery:
desc: "Generate mocks for interfaces"
preconditions:
- sh: test -f .mockery.yml
msg: ".mockery.yml configuration file not found."
cmds:
- "{{.MOCKERY}} --config=./.mockery.yml"
#-------------------------------------
# CI/Utility Tasks
#-------------------------------------
sweep-check:
desc: "Run sweeper test checks (TestCheckSweepers) without deleting resources"
cmds:
- "{{.GO_CMD}} test ./internal/sweep -v -run TestCheckSweepers"
clean-examples:
internal: true
desc: "Remove Terraform state files (*.tfstate*) from ./examples directory"
cmds:
- find ./examples -type f \( -name '*.tfstate' -o -name '*.tfstate.backup' \) -delete
discover-test-matrix:
desc: "Finds Go tests, partitions them into normal/slow via SLOW_TESTS_CSV, optionally filters by FILTER_SERVICES, and generates a JSON matrix for CI. Usage: task ci:discover-test-matrix SLOW_TESTS_CSV=slow_test1,slow_test2 FILTER_SERVICES='kafka,pg'"
vars:
SLOW_TESTS_CSV: '{{.SLOW_TESTS_CSV}}'
FILTER_SERVICES: '{{.FILTER_SERVICES | default ""}}'
cmds:
- "{{.GO_CMD}} run ./tools/main.go tests matrix --slow-tests-csv {{.SLOW_TESTS_CSV}}{{if .FILTER_SERVICES}} --filter {{.FILTER_SERVICES}}{{end}}"
silent: true
verify-version:
desc: "Verifies the new version doesn't exist and is a sequential semantic version bump."
vars:
VERSION: '{{.VERSION}}'
preconditions:
- sh: 'test -n "{{.VERSION}}"'
msg: |
Error: VERSION must be provided as an argument.
Usage: task verify-version VERSION=x.y.z
cmds:
- "{{.GO_CMD}} run ./tools/main.go version verify {{.VERSION}}"
silent: true
nothing:
silent: true
cmds:
- true
#-------------------------------------
# OPA Tasks
#-------------------------------------
opa:verify:
desc: Verify OPA installed
preconditions:
- sh: command -v "{{.OPA}}"
msg: "OPA is not installed. Please install it manually."