-
Notifications
You must be signed in to change notification settings - Fork 38
368 lines (310 loc) · 11.7 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
# Heavyweight integration tests
name: Integration tests
on:
push:
branches:
- main
- chore/separate-cmdline-tests-step
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/[email protected]
with:
versionSpec: '5.x'
- name: Determine Version
id: gitversion
uses: gittools/actions/gitversion/[email protected]
build-netcore-tool:
needs: set-version-number
name: Build .NET Core (global) tool
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup .NET 8
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet pack ./src/grate/grate.csproj -p:SelfContained=false -p:PackAsTool=true -p:PackageOutputPath=/tmp/grate/nupkg
env:
VERSION: ${{ needs.set-version-number.outputs.nuGetVersion }}
- name: Upload published tool artifact
uses: actions/upload-artifact@v4
with:
name: grate-dotnet-tool-${{ needs.set-version-number.outputs.nuGetVersion }}
path: /tmp/grate/nupkg/*
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
# 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:
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/*
setup-test-environment:
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:
mariadb_connection_string: ${{ steps.show.outputs.mariadb_connection_string }}
mariadb_p: ${{ steps.show.outputs.mariadb_p }}
steps:
- uses: actions/checkout@v4
- name: Log into Azure
uses: azure/login@v1
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 -no-color
run: terraform validate
- name: Terraform plan
id: plan
#run: terraform plan -no-color -input=false
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 values
id: show
run: |
terraform show -json > state.json
HOST=$(cat state.json | jq -r '.values.outputs | ."mariadb-fqdn".value')
PW=$(cat state.json | jq -r '.values.outputs | ."mariadb-admin-password".value')
CONNSTR="Server=${HOST};Port=3306;Database=mysql;Uid=root;Pwd=${PW}"
# echo "mariadb_connection_string='Server=${HOST};Port=3306;Database=mysql;Uid=root'"
# echo "mariadb_connection_string='Server=${HOST};Port=3306;Database=mysql;Uid=root'" >> "$GITHUB_OUTPUT"
echo "mariadb_connection_string='${CONNSTR}'"
echo "mariadb_connection_string='${CONNSTR}'" >> "$GITHUB_OUTPUT"
echo "mariadb_p='${PW}'" >> "$GITHUB_OUTPUT"
# - run: echo ${{ steps.apply.outputs.stdout }}
# - run: echo ${{ steps.apply.outputs.stderr }}
# - run: echo ${{ steps.apply.outputs.exitcode }}
integration-test:
environment: integration-tests
name: Test
needs:
- set-version-number
- build-standalone
- setup-test-environment
continue-on-error: true
strategy:
fail-fast: false
matrix:
database:
# - name: SqlServer Conn1
# project: SqlServer
# connectionstring: "DbConn SqlServer Conn1"
# - name: SqlServer Conn2
# project: SqlServer
# connectionstring: "DbConn SqlServer Conn2"
# - name: "PostgreSQL Conn1"
# project: PostgreSQL
# connectionstring: "DbConn PostgreSQL Conn1"
# - name: "PostgreSQL Conn2"
# project: PostgreSQL
# connectionstring: "DbConn PostgreSQL Conn2"
- name: "MariaDB ACA"
project: MariaDB
connectionstring: "AAA: ${{ needs.setup-test-environment.outputs.mariadb_connection_string }}"
moo: "${{ needs.setup-test-environment.outputs.mariadb_p }}"
# - name: "MariaDB Conn2"
# project: MariaDB
# connectionstring: "DbConn MariaDB Conn2"
# - name: "Sqlite Conn1"
# project: Sqlite
# connectionstring: "DbConn Sqlite Conn1"
# - name: "Sqlite Conn2"
# project: Sqlite
# connectionstring: "DbConn Sqlite Conn2"
# - name: "Oracle Conn1"
# project: Oracle
# connectionstring: "DbConn Oracle Conn1"
# - name: "Oracle Conn2"
# project: Oracle
# connectionstring: "DbConn Oracle Conn2"
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
runs-on: ${{ matrix.os.name }}
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: grate-${{ matrix.os.arch }}-self-contained-${{ needs.set-version-number.outputs.nuGetVersion }}
path: executables/${{ 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@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Test
run: >
dotnet test
unittests/CommandLine/CommandLine.${{ matrix.database.project }}
--logger:"xunit;LogFilePath=/tmp/test-results/${{ matrix.os.arch }}/CommandLine.${{ matrix.database.project }}.xml" --
-MaxCpuCount 2
env:
LogLevel: Warning
GrateExecutablePath: ${{ github.workspace }}/executables/${{ matrix.os.arch }}/${{ matrix.os.executable }}
GrateTestConfig__AdminConnectionString: ${{ matrix.database.connectionstring }}
GrateTestConfig__Moo: ${{ matrix.database.moo }}
TZ: UTC
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@v1
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 -no-color
run: terraform validate
- id: plan-destroy
#run: terraform plan -destroy -no-color -input=false
run: terraform plan -destroy -input=false
- name: Terraform Plan Status
if: steps.plan.outcome == 'failure'
run: exit 1
- name: Terraform Destroy
#run: terraform apply -destroy -auto-approve
run: terraform destroy -auto-approve