-
Notifications
You must be signed in to change notification settings - Fork 40
638 lines (542 loc) · 20.9 KB
/
integration-tests.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
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
# Heavyweight integration tests
name: Integration tests
on:
push:
branches:
- main
paths-ignore:
- docs/
pull_request:
branches:
- main
paths-ignore:
- docs/
workflow_dispatch:
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
jobs:
set-version-number:
name: Set version number
runs-on: ubuntu-latest
outputs:
nuGetVersion: ${{ steps.gitversion.outputs.nuGetVersionV2 }}
semVer: ${{ steps.gitversion.outputs.fullSemVer }}
is-release: ${{ steps.gitversion.outputs.CommitsSinceVersionSource == 0 }}
#is-release: 'true'
steps:
- name: Setup .NET 8
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v2.0.1
with:
versionSpec: '5.x'
- name: Determine Version
id: gitversion
uses: gittools/actions/gitversion/execute@v2.0.1
build-standalone:
name: Build cli
needs: set-version-number
runs-on: ubuntu-latest
strategy:
matrix:
arch:
# - win-x64
# - win-x86
# - win-arm64
# - linux-musl-x64
# - linux-musl-arm64
- linux-x64
# - linux-arm64
# - osx-x64
steps:
- uses: actions/checkout@v4
- name: Setup .NET 8
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Publish self-contained ${{ matrix.arch }}
run: dotnet publish ./src/grate/grate.csproj -f net8.0 -r ${{ matrix.arch }} -c release --self-contained -p:SelfContained=true -o ./publish/${{ matrix.arch }}/self-contained
env:
VERSION: ${{ needs.set-version-number.outputs.nuGetVersion }}
- name: Upload self-contained ${{ matrix.arch }}
uses: actions/upload-artifact@v4
with:
name: grate-${{ matrix.arch }}-self-contained-${{ needs.set-version-number.outputs.nuGetVersion }}
path: ./publish/${{ matrix.arch }}/self-contained/*
build-standalone-mac-arm64:
if: false
name: Build cli
needs: set-version-number
# Use macos-14 to build osx-arm64, it runs on M1, see
# https://github.blog/changelog/2024-01-30-github-actions-introducing-the-new-m1-macos-runner-available-to-open-source/
#
# I've earlier had problems with that the trimmed, self-contained binary for osx-arm64 that was built on Linux
# did not work when opened on an actual mac with arm64.
runs-on: macos-14
strategy:
matrix:
arch: [ "osx-arm64" ]
steps:
- uses: actions/checkout@v4
- name: Setup .NET 8
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Publish self-contained ${{ matrix.arch }}
run: dotnet publish ./src/grate/grate.csproj -f net8.0 -r ${{ matrix.arch }} -c release --self-contained -p:SelfContained=true -o ./publish/${{ matrix.arch }}/self-contained
env:
VERSION: ${{ needs.set-version-number.outputs.nuGetVersion }}
- name: Upload self-contained ${{ matrix.arch }}
uses: actions/upload-artifact@v4
with:
name: grate-${{ matrix.arch }}-self-contained-${{ needs.set-version-number.outputs.nuGetVersion }}
path: ./publish/${{ matrix.arch }}/self-contained/*
build-tests:
name: Build tests
needs: set-version-number
runs-on: ubuntu-latest
strategy:
matrix:
arch:
#- win-x64
- linux-x64
#- osx-x64
steps:
- uses: actions/checkout@v4
- name: Setup .NET 8
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Build Test DLLs ${{ matrix.arch }}
run: |
dotnet restore -r ${{ matrix.arch }} unittests/UnitTests.slnf
dotnet publish -f net8.0 -r ${{ matrix.arch }} -c release --no-restore ./unittests/UnitTests.slnf -o ./integration-tests/${{ matrix.arch }}
env:
VERSION: ${{ needs.set-version-number.outputs.nuGetVersion }}
- name: Upload Test DLLs ${{ matrix.arch }}
uses: actions/upload-artifact@v4
with:
name: integration-tests-${{ matrix.arch }}-${{ needs.set-version-number.outputs.nuGetVersion }}
path: ./integration-tests/${{ matrix.arch }}/*
build-tests-mac-arm64:
if: false
name: Build tests
needs: set-version-number
runs-on: macos-14
strategy:
matrix:
arch: [ "osx-arm64" ]
steps:
- uses: actions/checkout@v4
- name: Setup .NET 8
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Build Test DLLs ${{ matrix.arch }}
run: |
dotnet restore -r ${{ matrix.arch }} unittests/UnitTests.slnf
dotnet publish -f net8.0 -r ${{ matrix.arch }} -c release --no-restore ./unittests/UnitTests.slnf -o ./integration-tests/${{ matrix.arch }}
env:
VERSION: ${{ needs.set-version-number.outputs.nuGetVersion }}
- name: Upload Test DLLs ${{ matrix.arch }}
uses: actions/upload-artifact@v4
with:
name: integration-tests-${{ matrix.arch }}-${{ needs.set-version-number.outputs.nuGetVersion }}
path: ./integration-tests/${{ matrix.arch }}/*
setup-test-environment:
if: false
name: Set up test enviroment
environment: integration-tests
runs-on: ubuntu-latest
env:
tf_actions_working_dir: "${{ github.workspace }}/test-infra/terraform/test-environment"
ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
defaults:
run:
working-directory: ${{ env.tf_actions_working_dir }}
outputs:
# Need to split the connection string in two, and assemble when used, as GitHub Actions refuses to
# write anything to the outputs that have what it considers sensitive values. And, 'Pwd=<password>'
# apparently is.
mariadb_connection_string: ${{ steps.show.outputs.mariadb_connection_string }}
mariadb_pw: ${{ steps.show.outputs.mariadb_pw }}
dbs: ${{ steps.show.outputs.dbs }}
#encoded_dbs: ${{ steps.show.outputs.encoded_dbs }}
steps:
- uses: actions/checkout@v4
- name: Log into Azure
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Show account info
run: >
az account show
- uses: hashicorp/setup-terraform@v3
- run: terraform init
- name: Terraform Validate
run: terraform validate
- name: Terraform plan
id: plan
run: terraform plan -input=false
# - run: echo ${{ steps.plan.outputs.stdout }}
# - run: echo ${{ steps.plan.outputs.stderr }}
# - run: echo ${{ steps.plan.outputs.exitcode }}
- name: Exit on invalid Terraform plan
if: steps.plan.outcome == 'failure'
run: exit 1
- name: Terraform Apply
id: apply
run: terraform apply -auto-approve
- name: Get terraform outputs
id: show
run: |
terraform show -json > state.json
# Have to base64 encode, to avoid github seeing a pw, and refuse to output at all
DBS=$(cat state.json | jq -c '[ .values.outputs.dbs.value[] | .connectionstring |= @base64 ] ' )
{
echo 'dbs<<EOFAAA'
echo ${DBS}
echo EOFAAA
} >> "$GITHUB_OUTPUT"
docker-integration-tests:
name: ${{ matrix.database.name }}
continue-on-error: true
timeout-minutes: 25
needs:
- set-version-number
- build-standalone
- build-tests
strategy:
fail-fast: false
matrix:
database:
# - name: "SqlServer 2022"
# type: SqlServer
# image: "mcr.microsoft.com/mssql/server:2022-latest"
- name: "SqlServer 2022 (Ubuntu 22.04)"
type: SqlServer
image: "mcr.microsoft.com/mssql/server:2022-preview-ubuntu-22.04"
- name: "SqlServer 2019"
type: SqlServer
image: "mcr.microsoft.com/mssql/server:2019-CU26-ubuntu-20.04"
- name: "SqlServer 2017"
type: SqlServer
image: "mcr.microsoft.com/mssql/server:2017-latest"
- name: "PostgreSQL 16"
type: PostgreSQL
image: "postgres:16"
- name: "PostgreSQL 15"
type: PostgreSQL
image: "postgres:15"
- name: "PostgreSQL 14"
type: PostgreSQL
image: "postgres:14"
- name: "PostgreSQL 13"
type: PostgreSQL
image: "postgres:13"
- name: "PostgreSQL 12"
type: PostgreSQL
image: "postgres:12"
- name: "MariaDB 10.10"
type: MariaDB
image: "mariadb:10.10"
- name: "Sqlite"
type: Sqlite
image: "irrelevant"
- name: "Oracle Free latest"
type: Oracle
image: "gvenzl/oracle-free:latest-faststart"
- name: "Oracle XE latest"
type: Oracle
image: "gvenzl/oracle-xe:latest-faststart"
- name: "Oracle XE 18"
type: Oracle
image: "gvenzl/oracle-xe:18-faststart"
runs-on: ubuntu-latest
steps:
- name: Test run info
shell: pwsh
run: |
echo "Test run info:"
echo "===================="
echo "Name: ${{ matrix.database.name }}"
echo "Database type: ${{ matrix.database.type }}"
echo "Image: ${{ matrix.database.image }}"
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
name: Download executables
with:
name: grate-linux-x64-self-contained-${{ needs.set-version-number.outputs.nuGetVersion }}
path: executables/linux-x64
- uses: actions/download-artifact@v4
name: Download test DLLs
with:
name: integration-tests-linux-x64-${{ needs.set-version-number.outputs.nuGetVersion }}
path: integration-tests/linux-x64
- name: Setup .NET 8
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: chmod u+x
run: chmod u+x $GrateExecutablePath
env:
GrateExecutablePath: ${{ github.workspace }}/executables/linux-x64/grate
- name: Docker Test CmdLine
if: ${{ !cancelled() }}
shell: pwsh
run: |
dotnet test integration-tests/linux-x64/CommandLine.${{ matrix.database.type }}.dll `
--logger:"xunit;Environment=${{ matrix.database.name }} (docker);LogFilePath=/tmp/test-results/docker/CommandLine.${{ matrix.database.name }}.xml"
env:
LogLevel: Information
GrateExecutablePath: ${{ github.workspace }}/executables/linux-x64/grate
TZ: UTC
GrateTestConfig__DockerImage: ${{ matrix.database.image }}
- name: Docker Test Docker
# TODO: We need to integrate build of a docker image to test into the pipeline, and push it to the local registry,
# and use that one, to run the integration tests. If not, we are testing the latest published released.
#if: ${{ !cancelled() }}
if: false
shell: pwsh
run: |
dotnet test integration-tests/linux-x64/Docker.${{ matrix.database.type }}.dll `
--logger:"xunit;Environment=${{ matrix.database.name }} (docker);LogFilePath=/tmp/test-results/docker/Docker.${{ matrix.database.name }}.xml"
env:
LogLevel: Information
TZ: UTC
GrateTestConfig__DockerImage: ${{ matrix.database.image }}
- name: Upload Unit Test Results
if: always()
uses: actions/upload-artifact@v4
with:
name: "docker ${{ matrix.database.name }} XML test results"
path: |
/tmp/test-results/docker/CommandLine.${{ matrix.database.name }}.xml
/tmp/test-results/docker/Docker.${{ matrix.database.name }}.xml
retention-days: 1
integration-test:
if: false
environment: integration-tests
name: ${{ matrix.database.name }}, ${{ matrix.os.name }}
needs:
- set-version-number
- setup-test-environment
- build-standalone
- build-standalone-mac-arm64
- build-tests
- build-tests-mac-arm64
continue-on-error: true
timeout-minutes: 25
strategy:
fail-fast: false
# Try to keep this the same as the number of databases we test
# (this will avoid many test suites against the same database server simultaneously)
max-parallel: 12
matrix:
os:
- name: windows-latest
arch: win-x64
executable: grate.exe
- name: ubuntu-latest
arch: linux-x64
executable: grate
- name: macos-latest
arch: osx-x64
executable: grate
# macos-14 is M1 (arm64)
- name: macos-14
arch: osx-arm64
executable: grate
database: ${{ fromJson(needs.setup-test-environment.outputs.dbs) }}
runs-on: ${{ matrix.os.name }}
steps:
- name: Test run info
shell: pwsh
run: |
echo "Test run info:"
echo "===================="
echo "OS: ${{ matrix.os.name }}"
echo "Arch: ${{ matrix.os.arch }}"
echo "Executable: ${{ matrix.os.executable }}"
echo "Database: ${{ matrix.database.name }}"
echo "Cleaned database name: ${{ matrix.database.cleaned_name }}"
echo "Connection string: $([System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String( "${{ matrix.database.connectionstring }}" )) )"
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
name: Download executables
with:
name: grate-${{ matrix.os.arch }}-self-contained-${{ needs.set-version-number.outputs.nuGetVersion }}
path: executables/${{ matrix.os.arch }}
- uses: actions/download-artifact@v4
name: Download test DLLs
with:
name: integration-tests-${{ matrix.os.arch }}-${{ needs.set-version-number.outputs.nuGetVersion }}
path: integration-tests/${{ matrix.os.arch }}
- name: Setup .NET 8
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: chmod u+x
run: chmod u+x $GrateExecutablePath
if: ${{ matrix.os.arch != 'win-x64' }}
env:
GrateExecutablePath: ${{ github.workspace }}/executables/${{ matrix.os.arch }}/${{ matrix.os.executable }}
- name: Log into Azure
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Test lib
shell: pwsh
# Theses are not stable enought to run against an external database. Disable for now.
if: false
run: |
$env:GrateTestConfig__AdminConnectionString="$([System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String( "${{ matrix.database.connectionstring }}" )) )";
dotnet test integration-tests/${{ matrix.os.arch }}/${{ matrix.database.type }}.dll `
--logger:"xunit;Environment=${{ matrix.os.arch }},${{ matrix.database.name }};LogFilePath=/tmp/test-results/${{ matrix.os.arch }}/${{ matrix.database.cleaned_name }}.xml" -- `
-MaxCpuCount 2
env:
LogLevel: Critical
TZ: UTC
- name: Test CmdLine
if: ${{ !cancelled() }}
shell: pwsh
run: |
$env:GrateTestConfig__AdminConnectionString="$([System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String( "${{ matrix.database.connectionstring }}" )) )";
dotnet test integration-tests/${{ matrix.os.arch }}/CommandLine.${{ matrix.database.type }}.dll `
--logger:"xunit;Environment=${{ matrix.os.arch }},${{ matrix.database.name }};LogFilePath=/tmp/test-results/${{ matrix.os.arch }}/CommandLine.${{ matrix.database.cleaned_name }}.xml" -- `
-MaxCpuCount 2
env:
LogLevel: Information
GrateExecutablePath: ${{ github.workspace }}/executables/${{ matrix.os.arch }}/${{ matrix.os.executable }}
TZ: UTC
- name: Upload Unit Test Results
if: always()
uses: actions/upload-artifact@v4
with:
name: "${{ matrix.os.arch }} ${{ matrix.database.cleaned_name }} XML test results"
path: |
/tmp/test-results/${{ matrix.os.arch }}/${{ matrix.database.cleaned_name }}.xml
/tmp/test-results/${{ matrix.os.arch }}/CommandLine.${{ matrix.database.cleaned_name }}.xml
retention-days: 1
# - name: Fail build if not successful
# id: fail-if-failed
# run: |
# [ "${FAILURE}" = "true" ] && echo "Failures found. Marking as failed" && exit 1;
# [ "${CANCELLED}" = "true" ] && echo "Job cancelled. Marking as failed" && exit 1;
# if: always()
# #if: contains(steps.*.result, 'failure') || contains(steps.*.result, 'cancelled')
# env:
# FAILURE: ${{ contains(steps.*.result, 'failure') }}
# CANCELLED: ${{ contains(steps.*.result, 'cancelled') }}
report:
runs-on: ubuntu-latest
name: Create test report
#needs: integration-test
needs: docker-integration-tests
if: always()
steps:
- name: Download XML test reports
uses: actions/download-artifact@v4
with:
path: test-results
- name: Install smink
run: |
BASEURL="https://github.com/erikbra/smink/releases/download/"
VERSION="0.4.0"
INSTALL_DIR="/tmp/smink"
SMINK="${INSTALL_DIR}/smink"
FILENAME="smink-linux-x64-${VERSION}.zip"
FULL_URL="${BASEURL}${VERSION}/${FILENAME}"
DOWNLOAD_DIR="/tmp/smink-download"
DOWNLOAD_FILE="${DOWNLOAD_DIR}/${FILENAME}"
test -f "${SMINK}" && \
echo "smink already installed - not installing" || \
echo "Installing smink v ${VERSION}" && \
(test -d "${DOWNLOAD_DIR}" || mkdir -p "${DOWNLOAD_DIR}") && \
(test -d "${INSTALL_DIR}" || mkdir -p "${INSTALL_DIR}") && \
(test -f "${DOWNLOAD_FILE}" || curl -o "${DOWNLOAD_FILE}" -sL "${FULL_URL}") && \
unzip -o "${DOWNLOAD_FILE}" -d "${INSTALL_DIR}"
chmod u+x "${SMINK}"
- name: Create HTML test report
run: |
XML_DIR='/tmp/xml'
REPORT_DIR='/tmp/test-results'
test -d $XML_DIR || mkdir $XML_DIR
find "test-results" -name '*.xml' -exec cp "{}" $XML_DIR \;
echo "Found the following test results files:"
ls -1 $XML_DIR
test -d $REPORT_DIR || mkdir $REPORT_DIR
echo "Running smink"
/tmp/smink/smink "${XML_DIR}/*.xml" "${REPORT_DIR}/grate integration tests $(date +'%Y-%m-%d %H.%M.%S %z').html" --title "grate integration tests"
- name: Upload HTML test report
uses: actions/upload-artifact@v4
with:
name: HTML test report
path: |
/tmp/test-results/*.html
retention-days: 10
teardown-test-environment:
name: Tear down test enviroment
environment: integration-tests
runs-on: ubuntu-latest
needs: integration-test
#if: always()
if: false
env:
tf_actions_working_dir: "${{ github.workspace }}/test-infra/terraform/test-environment"
ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
defaults:
run:
working-directory: ${{ env.tf_actions_working_dir }}
steps:
- uses: actions/checkout@v4
- name: Log into Azure
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Show account info
run: >
az account show
- uses: hashicorp/setup-terraform@v3
- run: terraform init
- name: Terraform Validate
run: terraform validate
- id: plan-destroy
run: terraform plan -destroy -input=false
- name: Terraform Destroy
run: terraform destroy -auto-approve
# fail-if-failed:
# name: Fail build on failure
# if: always()
# needs:
# - integration-test
# - teardown-test-environment
# runs-on: ubuntu-latest
# steps:
# - name: Fail build if not successful
# id: fail-if-failed
# run: |
# [ "${FAILURE}" = "true" ] && echo "Failures found. Marking as failed" && exit 1;
# [ "${CANCELLED}" = "true" ] && echo "Job cancelled. Marking as failed" && exit 1;
# if: always()
# #if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
# env:
# FAILURE: ${{ contains(needs.*.result, 'failure') }}
# CANCELLED: ${{ contains(needs.*.result, 'cancelled') }}