-
Notifications
You must be signed in to change notification settings - Fork 9
524 lines (455 loc) · 17 KB
/
test.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
520
521
522
523
524
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
---
# Terraform Provider testing workflow.
name: 🧪 Test
# This GitHub action runs your tests for each pull request.
# Optionally, you can turn it on using a schedule for regular testing.
on:
pull_request:
branches:
- main
types:
- opened
- synchronize
schedule:
- cron: "0 2 * * *"
workflow_dispatch:
concurrency:
group: ${{ format('{0}-{1}-{2}-{3}-{4}', github.workflow, github.event_name, github.ref, github.base_ref || null, github.head_ref || null) }}
cancel-in-progress: true
env:
FABRIC_TESTACC_SKIP_NO_SPN: true
FABRIC_TESTACC_WELLKNOWN: ${{ vars.FABRIC_TESTACC_WELLKNOWN_NEW }}
FABRIC_TIMEOUT: 20m
permissions:
id-token: write
contents: read
pull-requests: read
jobs:
changes:
name: 🔂 Check Changes
runs-on: ubuntu-24.04
outputs:
src: ${{ steps.filter.outputs.src }}
steps:
- name: ⤵️ Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: 🔂 Check for changes
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
id: filter
with:
filters: |
src:
- '**.go'
- 'go.mod'
- 'go.sum'
- '.github/workflows/test.yml'
test-auth-spn:
name: 🔐 Test Auth (SPN ${{ matrix.method }})
needs: changes
if: needs.changes.outputs.src == 'true'
environment:
name: development
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
method: [oidc, certificate, secret]
steps:
- name: ⤵️ Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: 🚧 Setup Go
uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
with:
go-version-file: go.mod
cache: true
- name: 🚧 Setup Task
uses: arduino/setup-task@b91d5d2c96a56797b48ac1e0e89220bf64044611 # v2.0.0
with:
repo-token: ${{ github.token }}
- name: ⚙️ Configure TF dev overrides
run: .devcontainer/features/tfprovider-local-dev/install.sh
env:
PROVIDERNAME: microsoft/fabric
- name: 🚧 Setup Terraform
uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
with:
terraform_wrapper: false
- name: 🔨 Setup Test tools
run: task test:tools
- name: 🧪 Run acceptance tests (OIDC)
if: matrix.method == 'oidc'
run: task testacc -- WorkspaceResource_CRUD ./internal/services/workspace
env:
FABRIC_USE_OIDC: true
FABRIC_TENANT_ID: ${{ secrets.TESTACC_TENANT_ID }}
FABRIC_CLIENT_ID: ${{ secrets.TESTACC_SPN_OIDC_CLIENT_ID }}
- name: 🧪 Run acceptance tests (Certificate)
if: matrix.method == 'certificate'
run: task testacc -- WorkspaceResource_CRUD ./internal/services/workspace
env:
FABRIC_TENANT_ID: ${{ secrets.TESTACC_TENANT_ID }}
FABRIC_CLIENT_ID: ${{ secrets.TESTACC_SPN_CERT_CLIENT_ID }}
FABRIC_CLIENT_CERTIFICATE: ${{ secrets.TESTACC_SPN_CERT_CLIENT_CERTIFICATE }}
FABRIC_CLIENT_CERTIFICATE_PASSWORD: ${{ secrets.TESTACC_SPN_CERT_CLIENT_CERTIFICATE_PASSWORD }}
- name: 🧪 Run acceptance tests (Secret)
if: matrix.method == 'secret'
run: task testacc -- WorkspaceResource_CRUD ./internal/services/workspace
env:
FABRIC_TENANT_ID: ${{ secrets.TESTACC_TENANT_ID }}
FABRIC_CLIENT_ID: ${{ secrets.TESTACC_SPN_SECRET_CLIENT_ID }}
FABRIC_CLIENT_SECRET: ${{ secrets.TESTACC_SPN_SECRET_CLIENT_SECRET }}
# test-auth-msi:
# name: 🔐 Test Auth (MSI ${{ matrix.method }})
# needs: changes
# if: needs.changes.outputs.src == 'true'
# environment:
# name: development
# runs-on: [self-hosted, containerjob]
# strategy:
# fail-fast: false
# matrix:
# method: [system, user]
# steps:
# - name: ⤵️ Checkout
# uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
# - name: ✔️ Check for changes
# uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
# id: changes_check
# with:
# filters: |
# src:
# - '**.go'
# - 'go.mod'
# - 'go.sum'
# - name: 🚧 Setup Go
# uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
# with:
# go-version-file: go.mod
# cache: true
# - name: 🚧 Setup Task
# uses: arduino/setup-task@b91d5d2c96a56797b48ac1e0e89220bf64044611 # v2.0.0
# with:
# repo-token: ${{ github.token }}
# - name: ⚙️ Configure TF dev overrides
# run: .devcontainer/features/tfprovider-local-dev/install.sh
# env:
# PROVIDERNAME: microsoft/fabric
# - name: 🚧 Setup Terraform
# uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
# with:
# terraform_wrapper: false
# - name: 🔨 Setup Test tools
# run: task test:tools
# - name: 🧪 Run acceptance tests (User Assigned)
# if: matrix.method == 'user'
# run: task testacc -- WorkspaceResource_CRUD
# env:
# FABRIC_USE_MSI: true
# FABRIC_TENANT_ID: ${{ secrets.TESTACC_TENANT_ID }}
# FABRIC_CLIENT_ID: ${{ secrets.TESTACC_MSI_CLIENT_ID }}
# - name: 🧪 Run acceptance tests (System Assigned)
# if: matrix.method == 'system'
# run: task testacc -- WorkspaceResource_CRUD
# env:
# FABRIC_USE_MSI: true
# FABRIC_TENANT_ID: ${{ secrets.TESTACC_TENANT_ID }}
checkbuild:
name: 🏗️ Check Build
needs: changes
if: needs.changes.outputs.src == 'true'
runs-on: ubuntu-24.04
timeout-minutes: 30
permissions:
contents: read
pull-requests: read
steps:
- name: ⤵️ Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: 🚧 Setup Go
uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
with:
go-version-file: go.mod
cache: true
- name: 🚧 Setup Task
uses: arduino/setup-task@b91d5d2c96a56797b48ac1e0e89220bf64044611 # v2.0.0
with:
repo-token: ${{ github.token }}
- name: 🔀 Get dependencies
run: task deps
- name: 🔀 Check for differences
run: |
git diff --exit-code -- go.mod go.sum || \
(echo; echo "Unexpected difference in go.mod/go.sum files. Run 'task deps' command or revert any go.mod/go.sum changes and commit."; git diff --exit-code)
- name: ✔️ Run GoVulnCheck
run: |
task install:govulncheck
task govulncheck
- name: ✔️ Run Go linters
uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8 # v6.1.1
with:
version: latest
only-new-issues: true
skip-cache: true
skip-save-cache: true
args: --out-format=github-actions
- name: 🚧 Setup Terraform
uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
with:
terraform_wrapper: false
- name: ✔️ Run tfproviderlintx
run: |
task install:tfproviderlintx
task tfproviderlintx
- name: ✔️ Run Terraform linters
run: |
task lint:tf-tools
task lint:tf
- name: 🔀 Check for differences
run: |
git diff --compact-summary --exit-code || \
(echo; echo "Unexpected difference in code. Run 'task lint' command and commit."; git diff --exit-code)
- name: ✔️ Validate GoReleaser config
uses: goreleaser/goreleaser-action@9ed2f89a662bf1735a48bc8557fd212fa902bebf # v6.1.0
with:
version: "~> v2"
args: check --verbose
- name: 🏗️ Build snapshot binaries
uses: goreleaser/goreleaser-action@9ed2f89a662bf1735a48bc8557fd212fa902bebf # v6.1.0
with:
version: "~> v2"
args: build --snapshot --clean --verbose
checkdocs:
name: 📃 Check Docs
runs-on: ubuntu-24.04
permissions:
contents: read
steps:
- name: ⤵️ Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: 🚧 Setup Go
uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
with:
go-version-file: go.mod
cache: true
- name: 🚧 Setup Task
uses: arduino/setup-task@b91d5d2c96a56797b48ac1e0e89220bf64044611 # v2.0.0
with:
repo-token: ${{ github.token }}
- name: 🔨 Setup tools
run: |
task install:tfplugindocs
task install:markdownlint
task install:copywrite
- name: ✔️ Run Files linters
run: task lint:files
- name: 🔀 Check for differences
run: |
git diff --compact-summary --exit-code || \
(echo; echo "Unexpected difference. Run 'task lint:files' command and commit."; git diff --exit-code)
- name: 📃 Generate docs
run: task docs
- name: 🔀 Check for differences
run: |
git diff --compact-summary --exit-code || \
(echo; echo "Unexpected difference in directories after code generation. Run 'task docs' command and commit."; git diff --exit-code)
# Run tests in a matrix with Terraform CLI versions
test:
name: 🧪 Run Tests (${{ matrix.cli }} ${{ matrix.version }})
needs: changes
if: needs.changes.outputs.src == 'true'
environment:
name: development
runs-on: ubuntu-24.04
timeout-minutes: 30
permissions:
contents: read
actions: read
checks: write
pull-requests: write
id-token: write
strategy:
fail-fast: false
matrix:
cli: [terraform, tofu]
version: ["1.7", "1.8", "1.9", "1.10"]
exclude:
- cli: terraform
version: "1.7"
- cli: tofu
version: "1.9"
- cli: tofu
version: "1.10"
steps:
- name: ⤵️ Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
- name: 🚧 Setup Go
uses: actions/setup-go@3041bf56c941b39c61721a86cd11f3bb1338122a # v5.2.0
with:
go-version-file: go.mod
cache: true
- name: 🚧 Setup Terraform
if: matrix.cli == 'terraform'
uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd # v3.1.2
with:
terraform_version: ${{ matrix.version }}
terraform_wrapper: false
- name: ⚙️ Configure Terraform
if: matrix.cli == 'terraform'
run: |
terraform -version
- name: 🚧 Setup OpenTofu
uses: opentofu/setup-opentofu@592200bd4b9bbf4772ace78f887668b1aee8f716 # v1.0.5
if: matrix.cli == 'tofu'
with:
tofu_version: ${{ matrix.version }}
tofu_wrapper: false
- name: ⚙️ Configure OpenTofu
if: matrix.cli == 'tofu'
run: |
echo "TERRAFORM_CLI=$(which tofu)" >> $GITHUB_ENV
echo "REGISTRY_HOST=registry.opentofu.org" >> $GITHUB_ENV
echo "TF_ACC_TERRAFORM_PATH=$(which tofu)" >> $GITHUB_ENV
echo "TF_ACC_PROVIDER_HOST=registry.opentofu.org" >> $GITHUB_ENV
tofu -version
- name: ⚙️ Set CLI version
run: |
version=$(echo "${{ matrix.version }}" | sed 's/\./_/g')
echo "CLI_VERSION=$version" >> $GITHUB_ENV
- name: 🚧 Setup Task
uses: arduino/setup-task@b91d5d2c96a56797b48ac1e0e89220bf64044611 # v2.0.0
with:
repo-token: ${{ github.token }}
- name: 🔀 Download Go dependencies
run: task deps:download
- name: 🔨 Setup Test tools
run: task test:tools
- name: 🧪 Run tests
if: matrix.cli == 'terraform'
run: task test
timeout-minutes: 30
env:
# TF_LOG: DEBUG
FABRIC_USE_OIDC: true
FABRIC_TENANT_ID: ${{ secrets.TESTACC_TENANT_ID }}
FABRIC_CLIENT_ID: ${{ secrets.TESTACC_SPN_TF_CLIENT_ID }}
- name: 🧪 Run tests
if: matrix.cli == 'tofu'
run: task test
timeout-minutes: 30
env:
FABRIC_USE_OIDC: true
FABRIC_TENANT_ID: ${{ secrets.TESTACC_TENANT_ID }}
FABRIC_CLIENT_ID: ${{ secrets.TESTACC_SPN_OT_CLIENT_ID }}
- name: 📤 Upload test results
if: always()
uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0
with:
name: ${{ format('{0}-{1}-test-results', matrix.cli, env.CLI_VERSION) }}
path: testresults.xml
if-no-files-found: warn
overwrite: true
- name: 📤 Upload coverage results
if: always()
uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0
with:
name: ${{ format('{0}-{1}-test-coverage-results', matrix.cli, env.CLI_VERSION) }}
path: |
coverage.html
coverage.json
coverage.out
coverage.txt
coverage.xml
if-no-files-found: warn
overwrite: true
- name: 📢 Publish test results
if: always()
uses: dorny/test-reporter@31a54ee7ebcacc03a09ea97a7e5465a47b84aea5 # v1.9.1
with:
name: 📜 Test results (${{ matrix.cli }} ${{ matrix.version }})
reporter: jest-junit
path: testresults.xml
- name: ⚙️ Get Coverage summary
if: always()
uses: irongut/CodeCoverageSummary@51cc3a756ddcd398d447c044c02cb6aa83fdae95 # v1.3.0
with:
filename: coverage.xml
badge: true
fail_below_min: true
format: markdown
hide_branch_rate: false
hide_complexity: false
indicators: true
output: both
thresholds: "40 60"
- name: 📤 Upload Coverage summary
if: always()
uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0
with:
name: ${{ format('{0}-{1}-test-coverage-summary', matrix.cli, env.CLI_VERSION) }}
path: |
code-coverage-results.md
if-no-files-found: warn
overwrite: true
coverage-summary:
name: 📔 Coverage Summary
needs:
- test
- changes
if: always() && needs.changes.outputs.src == 'true'
runs-on: ubuntu-24.04
permissions:
contents: read
issues: write
pull-requests: write
id-token: write
steps:
- name: 📥 Download
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
pattern: terraform-1_10-test-coverage*
merge-multiple: true
- name: 📝 Publish
run: cat code-coverage-results.md >> $GITHUB_STEP_SUMMARY
- name: 📤 Upload results to Codecov
uses: codecov/codecov-action@1e68e06f1dbfde0e4cefc87efeba9e4643565303 # v5.1.2
with:
use_oidc: true
files: ./coverage.out
- name: 🔎 Find comment
if: github.event_name == 'pull_request' || github.event_name == 'pull_request_target'
uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e # v3.1.0
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: github-actions[bot]
body-includes: Minimum allowed line rate is
- name: 📝 Create comment
if: steps.fc.outputs.comment-id == '' && (github.event_name == 'pull_request' || github.event_name == 'pull_request_target')
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0
with:
issue-number: ${{ github.event.pull_request.number }}
body-path: code-coverage-results.md
- name: 📝 Update comment
if: steps.fc.outputs.comment-id != '' && (github.event_name == 'pull_request' || github.event_name == 'pull_request_target')
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4.0.0
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
body-path: code-coverage-results.md
edit-mode: replace
# Returns success if all matrix jobs in test are successful - otherwise, it returns a failure.
# Use this as a PR status check for GitHub Policy Service instead of individual matrix entry checks.
check-test-matrix:
if: always()
name: 🧪 Check Tests
needs: test
runs-on: ubuntu-24.04
steps:
- name: ✅ OK
if: ${{ !(contains(needs.*.result, 'failure')) }}
run: exit 0
- name: 🛑 Failure
if: ${{ contains(needs.*.result, 'failure') }}
run: exit 1