-
Notifications
You must be signed in to change notification settings - Fork 8
/
Taskfile.yml
519 lines (462 loc) · 14.4 KB
/
Taskfile.yml
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
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
# yaml-language-server: $schema=https://taskfile.dev/schema.json
# docs: https://taskfile.dev
#
# Windows:
# winget install Task.Task
#
# Linux:
# sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b ~/.local/bin
# echo 'command -v task >/dev/null || export PATH="$PATH:$HOME/.local/bin"' >> ~/.profile
# source ~/.profile
#
# macOS:
# brew install go-task/tap/go-task
---
version: "3"
vars:
PROJECT_NAME: terraform-provider-fabric
PWSH: pwsh -NonInteractive -NoProfile -NoLogo -Command
PWSH_SCRIPT: pwsh -NonInteractive -NoProfile -NoLogo -File
BUILD_DEV_OUTPUT_DIR: "bin/{{OS}}-{{ARCH}}"
BUILD_DEV_ARTIFACT: "{{.BUILD_DEV_OUTPUT_DIR}}/{{.PROJECT_NAME}}{{exeExt}}"
tasks:
# ----------------------
# Development
# ----------------------
dev-overrides:
desc: Set up the environment to point to the right directories
vars:
BUILD_DEV_ARTIFACT_PATH: "{{.ROOT_DIR}}/{{.BUILD_DEV_ARTIFACT}}"
cmds:
- cmd: cp .github/dev/dev.tfrc.template dev.tfrc
platforms: [linux, darwin]
- cmd: sed -i '' 's|<output_dir>|{{.BUILD_DEV_ARTIFACT_PATH}}|g' dev.tfrc
platforms: [darwin]
- cmd: sed -i 's|<output_dir>|{{.BUILD_DEV_ARTIFACT_PATH}}|g' dev.tfrc
platforms: [linux]
- cmd: if [ -z $TF_CLI_CONFIG_FILE ]; then echo -e "### Run the following command:\nexport TF_CLI_CONFIG_FILE={{.ROOT_DIR}}/dev.tfrc\n###"; fi
platforms: [linux, darwin]
deps:
desc: Check if dependencies are up to date
cmds:
- go mod tidy
deps:verify:
desc: Verify dependencies
cmds:
- go mod verify
deps:download:
desc: Download dependencies
cmds:
- go mod download
deps:up:
desc: Update dependencies
deps: [deps]
cmds:
- go get -u ./...
- defer:
task: deps
lint:
desc: Run linters
cmds:
- task: lint:files
- task: lint:go
- task: lint:tf
- task: lint:md
lint:files:
desc: Run linters for various file types
cmds:
- copywrite headers
- copywrite license
lint:go:
desc: Run Go linters
cmds:
- task: govulncheck
- task: golangci-lint
- task: tfproviderlintx
govulncheck:
desc: Run govulncheck
cmds:
- govulncheck ./...
golangci-lint:
desc: Run golangci-lint
cmds:
- golangci-lint run --fix ./...
tfproviderlintx:
desc: Run tfproviderlintx
cmds:
- tfproviderlintx -fix ./...
lint:tf:
desc: Run Terraform linters
cmds:
- terraform fmt -recursive
- tflint --recursive
- tfsec .
- checkov --directory .
lint:md:
desc: Run Markdown linters
cmds:
- markdownlint-cli2 "./**/*.md" --config "./.github/linters/.markdownlint-cli2.yaml" --fix
lint:links:
desc: Run link checkers
cmds:
- lychee --config ./.github/linters/.lychee.toml --format markdown .
tools:
desc: Install required tools
cmds:
- for:
[
semver,
copywrite,
changie,
tfplugindocs,
dlv,
goimports,
golangci-lint,
gofumpt,
goreleaser,
govulncheck,
tfproviderlintx,
mkdocs,
yamllint,
markdownlint,
]
task: install:{{.ITEM}}
- task: test:tools
- task: lint:tf-tools
lint:tf-tools:
desc: Install Terraform lint tools
cmds:
- for: [tflint, tfsec, checkov]
task: install:{{.ITEM}}
tfp:
desc: Run Terraform plan
dir: "{{.USER_WORKING_DIR}}"
env:
TF_LOG: error
cmds:
- terraform plan
tfa:
desc: Run Terraform apply
dir: "{{.USER_WORKING_DIR}}"
env:
TF_LOG: error
cmds:
- terraform apply -auto-approve
otp:
desc: Run OpenTofu plan
dir: "{{.USER_WORKING_DIR}}"
env:
TF_LOG: error
TERRAFORM_CLI: tofu
TERRAFORM_PROVIDER_HOST: registry.opentofu.org
TF_ACC_TERRAFORM_PATH: tofu
TF_ACC_PROVIDER_HOST: registry.opentofu.org
cmds:
- tofu plan
ota:
desc: Run OpenTofu apply
dir: "{{.USER_WORKING_DIR}}"
env:
TF_LOG: error
TERRAFORM_CLI: tofu
TERRAFORM_PROVIDER_HOST: registry.opentofu.org
TF_ACC_TERRAFORM_PATH: tofu
TF_ACC_PROVIDER_HOST: registry.opentofu.org
cmds:
- tofu apply -auto-approve
# ----------------------
# Build
# ----------------------
build:
desc: Build development Provider binary with GoReleaser
deps: [build:clean]
cmds:
- goreleaser build --snapshot --single-target --clean --output {{.BUILD_DEV_ARTIFACT}}
sources:
- "**/*.go"
- go.mod
- go.sum
generates:
- "{{.BUILD_DEV_ARTIFACT}}"
build:all:
desc: Build snapshot Provider binaries with GoReleaser
cmds:
- goreleaser build --snapshot --clean
sources:
- "**/*.go"
- go.mod
- go.sum
build:clean:
desc: Cleanup build workspace
cmds:
- cmd: |
{{.PWSH}} 'Remove-Item -Path {{.BUILD_DEV_OUTPUT_DIR}} -Recurse -Force -ErrorAction SilentlyContinue; exit 0'
platforms: [windows]
- cmd: rm -rf {{.BUILD_DEV_OUTPUT_DIR}}
platforms: [linux, darwin]
- defer:
task: build:output
silent: true
internal: true
build:output:
desc: Create build output directories
cmds:
- cmd: |
{{.PWSH}} 'New-Item -ItemType Directory -Force -Path {{.BUILD_DEV_OUTPUT_DIR}} -ErrorAction SilentlyContinue > $null'
platforms: [windows]
- cmd: mkdir -p {{.BUILD_DEV_OUTPUT_DIR}}
platforms: [linux, darwin]
silent: true
internal: true
docs:
desc: Auto generate documentation
cmds:
- tfplugindocs generate --provider-name {{.PROJECT_NAME}}
- task: lint:md
site:build:
desc: Build docs site
deps: [docs]
cmds:
- cmd: |
{{.PWSH}} 'Remove-Item -Path .\site -Recurse -Force -ErrorAction SilentlyContinue; exit 0'
platforms: [windows]
- cmd: rm -rf ./site
platforms: [linux, darwin]
- mkdocs build --verbose --clean
env:
TZ: UTC
site:preview:
desc: Preview a docs site locally
cmds:
- mkdocs serve --verbose --clean --strict
env:
TZ: UTC
# ----------------------
# Test
# ----------------------
testunit:
desc: Run unit tests
cmds:
- 'gotestsum --format-hivis --format {{.FORMAT}} --junitfile "testresults.xml" -- {{.TEST_PATH}} -run "^TestUnit_{{.TEST_NAME}}" -p {{numCPU}} -timeout 5m -ldflags="{{.LDFLAGS}}" -coverprofile="coverage.out" -covermode atomic'
- task: test:getcover
vars:
TEST_NAME: "{{if gt (len (splitArgs .CLI_ARGS)) 0}}{{index (splitArgs .CLI_ARGS) 0}}{{end}}"
TEST_PATH: "{{if gt (len (splitArgs .CLI_ARGS)) 1}}{{index (splitArgs .CLI_ARGS) 1}}{{else}}./...{{end}}"
FORMAT: '{{if eq .GITHUB_ACTIONS "true"}}github-actions{{else}}pkgname-and-test-fails{{end}}'
LDFLAGS: "-s -w -X main.version=testUnit"
env:
TF_LOG: error
TF_ACC: 0
testacc:
desc: Run acceptance tests
cmds:
- go clean -testcache
- 'gotestsum --format-hivis --format {{.FORMAT}} --junitfile "testresults.xml" -- {{.TEST_PATH}} -run "^TestAcc_{{.TEST_NAME}}" -p {{numCPU}} -timeout 30m -ldflags="{{.LDFLAGS}}" -coverprofile="coverage.out" -covermode atomic'
- task: test:getcover
vars:
TEST_NAME: "{{if gt (len (splitArgs .CLI_ARGS)) 0}}{{index (splitArgs .CLI_ARGS) 0}}{{end}}"
TEST_PATH: "{{if gt (len (splitArgs .CLI_ARGS)) 1}}{{index (splitArgs .CLI_ARGS) 1}}{{else}}./...{{end}}"
FORMAT: '{{if eq .GITHUB_ACTIONS "true"}}github-actions{{else}}pkgname-and-test-fails{{end}}'
LDFLAGS: "-s -w -X main.version=testAcc"
env:
TF_LOG: error
TF_ACC: 1
test:
desc: Run tests
cmds:
- go clean -testcache
- go test -failfast -run ^TestDevEnv_WellKnown$ ./internal/testhelp
- 'gotestsum --format-hivis --format {{.FORMAT}} --junitfile "testresults.xml" -- {{.TEST_PATH}} -run "^Test(Acc|Unit)_{{.TEST_NAME}}" -p {{numCPU}} -timeout 30m -ldflags="{{.LDFLAGS}}" -coverprofile="coverage.out" -covermode atomic -coverpkg={{.GO_PKGS}}'
- task: test:getcover
vars:
TEST_NAME: "{{if gt (len (splitArgs .CLI_ARGS)) 0}}{{index (splitArgs .CLI_ARGS) 0}}{{end}}"
TEST_PATH: "{{if gt (len (splitArgs .CLI_ARGS)) 1}}{{index (splitArgs .CLI_ARGS) 1}}{{else}}./...{{end}}"
FORMAT: '{{if eq .GITHUB_ACTIONS "true"}}github-actions{{else}}pkgname-and-test-fails{{end}}'
LDFLAGS: "-s -w -X main.version=testAcc"
GO_PKGS_EXCLUDE: "/testhelp|/fakes|/terraform-provider-fabric"
GO_PKGS:
sh: |
{{if eq OS "windows"}}
{{.PWSH}} "(go list ./... | Select-String -NotMatch '({{ .GO_PKGS_EXCLUDE }})$') -join ','"
{{else}}
go list ./... | grep -Ev '({{ .GO_PKGS_EXCLUDE }})$' | tr '\n' ','
{{end}}
env:
TF_LOG: error
TF_ACC: 1
testacc:setup:
desc: Setup acceptence/development test environment
dotenv: ["wellknown.env"]
preconditions:
- sh: |
{{if ne OS "windows"}}
command -v pwsh &>/dev/null || exit 1
{{end}}
msg: "First install PowerShell: https://learn.microsoft.com/powershell/scripting/install/installing-powershell"
cmds:
- cmd: |
{{.PWSH_SCRIPT}} ./tools/scripts/Set-WellKnown.ps1
test:tools:
desc: Install test tools
cmds:
- for: [gotestsum, gocov, gocov-xml]
task: install:{{.ITEM}}
test:getcover:
desc: Get coverage results
internal: true
cmds:
- gocov convert coverage.out > coverage.json
- gocov report coverage.json > coverage.txt
- cmd: |
{{ .PWSH }} 'Get-Content coverage.json | gocov-xml > coverage.xml'
platforms: [windows]
- cmd: gocov-xml < coverage.json > coverage.xml
platforms: [linux, darwin]
- go tool cover -html coverage.out -o coverage.html
# ----------------------
# Release
# ----------------------
release:prep:
desc: Prepare release
vars:
SEMVER:
sh: semver up beta
env:
CHANGIE_GITHUB_REPOSITORY: "microsoft/terraform-provider-fabric"
cmds:
- echo "{{.SEMVER}}"
- cmd: |
git checkout main && git fetch && git pull
git checkout -b "release/{{.SEMVER}}"
- changie batch {{.SEMVER}}
- changie merge
- task: docs
- cmd: |
git add .
git commit -a -m "feat(release): {{.SEMVER}}"
- cmd: |
gh pr create --title "feat(release): {{.SEMVER}}" --body-file ".changes/{{.SEMVER}}.md" --label "skip-changelog"
# ----------------------
# Install Helpers
# ----------------------
install:semver:
desc: Install semver
cmds:
- go install github.com/maykonlsf/semver-cli/cmd/semver@latest
install:copywrite:
desc: Install copywrite
cmds:
- go install github.com/hashicorp/copywrite@latest
install:changie:
desc: Install changie
cmds:
- go install github.com/miniscruff/changie@latest
install:gotestsum:
desc: Install gotestsum
cmds:
- go install gotest.tools/gotestsum@latest
install:dlv:
desc: Install dlv
cmds:
- go install github.com/go-delve/delve/cmd/dlv@latest
install:gocov:
desc: Install gocov
cmds:
- go install github.com/axw/gocov/gocov@latest
install:gocov-xml:
desc: Install gocov-xml
cmds:
- go install github.com/AlekSi/gocov-xml@latest
install:tfplugindocs:
desc: Install tfplugindocs
cmds:
- go install github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs@latest
install:goimports:
desc: Install goimports
cmds:
- go install golang.org/x/tools/cmd/goimports@latest
install:golangci-lint:
desc: Install golangci-lint
cmds:
- cmd: winget install GolangCI.golangci-lint
ignore_error: true
platforms: [windows]
- cmd: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "$(go env GOPATH)/bin" latest
platforms: [linux]
- cmd: brew install golangci-lint
platforms: [darwin]
install:gofumpt:
desc: Install gofumpt
cmds:
- go install mvdan.cc/gofumpt@latest
install:goreleaser:
desc: Install goreleaser
cmds:
- go install github.com/goreleaser/goreleaser/v2@latest
install:tfproviderlintx:
desc: Install tfproviderlintx
cmds:
- go install github.com/bflad/tfproviderlint/cmd/tfproviderlintx@latest
install:markdownlint:
desc: Install markdownlint
cmds:
- npm install -g markdownlint-cli2
install:tflint:
desc: Install tflint
cmds:
- go install github.com/terraform-linters/tflint@latest
install:tfsec:
desc: Install tfsec
cmds:
- go install github.com/aquasecurity/tfsec/cmd/tfsec@latest
install:govulncheck:
desc: Install govulncheck
cmds:
- go install golang.org/x/vuln/cmd/govulncheck@latest
install:checkov:
desc: Install checkov
preconditions:
- sh: |
{{if eq OS "windows"}}
{{.PWSH}} 'if (-not (Get-Command pipx -ErrorAction SilentlyContinue)) { exit 1 }'
{{else}}
command -v pipx &>/dev/null || exit 1
{{end}}
msg: "First install pipx: https://pipx.pypa.io/"
cmds:
- pipx install --force checkov
install:mkdocs:
desc: Install mkdocs
preconditions:
- sh: |
{{if eq OS "windows"}}
{{.PWSH}} 'if (-not (Get-Command pipx -ErrorAction SilentlyContinue)) { exit 1 }'
{{else}}
command -v pipx &>/dev/null || exit 1
{{end}}
msg: "First install pipx: https://pipx.pypa.io/"
cmds:
- pipx install --force mkdocs
- pipx inject --include-deps --force mkdocs $(mkdocs get-deps)
install:yamllint:
desc: Install yamllint
preconditions:
- sh: |
{{if eq OS "windows"}}
{{.PWSH}} 'if (-not (Get-Command pipx -ErrorAction SilentlyContinue)) { exit 1 }'
{{else}}
command -v pipx &>/dev/null || exit 1
{{end}}
msg: "First install pipx: https://pipx.pypa.io/"
cmds:
- pipx install --force yamllint
install:lychee:
desc: Install lychee
cmds:
- cmd: winget install lycheeverse.lychee
platforms: [windows]
- cmd: cargo install lychee
ignore_error: true
platforms: [linux]
- cmd: brew install lychee
platforms: [darwin]