-
Notifications
You must be signed in to change notification settings - Fork 386
438 lines (396 loc) · 19.8 KB
/
build.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
name: Build
on:
push:
branches:
- '**'
paths-ignore:
- '**.md'
pull_request:
branches:
- '**'
paths-ignore:
- '**.md'
release:
types:
- published
env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
DOTNET_CLI_TELEMETRY_OPTOUT: true
mysqlCurrentSqlMode: ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
mysqlLegacySqlMode: ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
# Currently no ONLY_FULL_GROUP_BY, see #1167:
mariadbSqlMode: STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
maxConnections: 512
skipAllTests: false
skipWindowsTests: false
jobs:
BuildAndTest:
strategy:
fail-fast: false
matrix:
dbVersion:
- 8.4.3-mysql
- 8.0.40-mysql
- 11.6.2-mariadb
- 11.5.2-mariadb
- 11.4.4-mariadb
- 11.3.2-mariadb
- 10.11.10-mariadb
- 10.6.20-mariadb
- 10.5.27-mariadb
os:
- ubuntu-latest
- windows-latest
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set additional variables
shell: pwsh
run: |
$os = '${{ matrix.os }}'.Split('-')[0] -eq 'windows' ? 'windows' : 'linux'
echo "os=$os" >> $env:GITHUB_ENV
$dbVersionParts = '${{ matrix.dbVersion }}'.Split('-')
$databaseServerType = $dbVersionParts[1]
echo "databaseServerType=$databaseServerType" >> $env:GITHUB_ENV
$databaseServerVersion = $dbVersionParts[0]
echo "databaseServerVersion=$databaseServerVersion" >> $env:GITHUB_ENV
# The parenthesis around the right OR argument are mandatory for the expression to work correctly, because in PowerShell, AND and OR
# operators have the SAME precedence.
$skipTests = '${{ env.skipAllTests }}' -eq 'true' -or ($os -eq 'windows' -and '${{ env.skipWindowsTests }}' -eq 'true')
echo "skipTests=$skipTests" >> $env:GITHUB_ENV
$sqlMode = $databaseServerType -eq 'mariadb' ? '${{ env.mariadbSqlMode }}' : $databaseServerType -eq 'mysql' -and $databaseServerVersion.Split('.')[0] -lt 8 ? '${{ env.mysqlLegacySqlMode }}' : '${{ env.mysqlCurrentSqlMode }}'
echo "sqlMode=$sqlMode" >> $env:GITHUB_ENV
$serverExecutable = $databaseServerType -eq 'mariadb' -and $databaseServerVersion.Split('.')[0] -ge 11 ? 'mariadbd' : 'mysqld'
echo "serverExecutable=$serverExecutable" >> $env:GITHUB_ENV
$clientExecutable = $databaseServerType -eq 'mariadb' -and $databaseServerVersion.Split('.')[0] -ge 11 ? 'mariadb' : 'mysql'
echo "clientExecutable=$clientExecutable" >> $env:GITHUB_ENV
$clientCommandPrefix = $os -eq 'windows' ? $clientExecutable : "docker exec '$databaseServerType' $clientExecutable"
echo "clientCommandPrefix=$clientCommandPrefix" >> $env:GITHUB_ENV
$windowsUserTempLocation = $os -eq 'windows' ? (Get-Item $env:Temp).FullName : ''
echo "windowsUserTempLocation=$windowsUserTempLocation" >> $env:GITHUB_ENV
- name: Output Variables
shell: pwsh
run: |
echo "os: ${{ env.os }}"
echo "databaseServerType: ${{ env.databaseServerType }}"
echo "databaseServerVersion: ${{ env.databaseServerVersion }}"
echo "sqlMode: ${{ env.sqlMode }}"
echo "skipTests: ${{ env.skipTests }}"
echo "skipAllTests: ${{ env.skipAllTests }}"
echo "skipWindowsTests: ${{ env.skipWindowsTests }}"
echo "serverExecutable: ${{ env.serverExecutable }}"
echo "clientExecutable: ${{ env.clientExecutable }}"
echo "clientCommandPrefix: ${{ env.clientCommandPrefix }}"
echo "windowsUserTempLocation: ${{ env.windowsUserTempLocation }}"
echo "github.event_name: ${{ github.event_name }}"
echo "github.repository: ${{ github.repository }}"
- name: Cache - Database Image - Linux
id: cache-databaseImage-linux
uses: actions/cache@v4
if: ${{ env.os == 'linux' }}
with:
path: cache/database
key: database-linux-${{ env.databaseServerType }}-${{ env.databaseServerVersion }}-v2
- name: Cache - Database Image - Windows
id: cache-databaseImage-windows
uses: actions/cache@v4
if: ${{ env.os == 'windows' }}
with:
path: ${{ env.windowsUserTempLocation }}\Pomelo.Chocolatey.${{ env.databaseServerType }}.Server
key: database-windows-${{ env.databaseServerType }}-${{ env.databaseServerVersion }}-v3
- name: Install Database Server - Linux
if: ${{ env.os == 'linux' }}
shell: pwsh
run: |
sudo systemctl stop mysql
$waitMinutes = 5
$pollingIntervalSeconds = 1
$started = $false
dir './cache/database' -ErrorAction SilentlyContinue | Select-Object -ExpandProperty FullName
if (Test-Path -PathType Leaf './cache/database/${{ env.databaseServerType }}_${{ env.databaseServerVersion }}.tar')
{
docker load --input './cache/database/${{ env.databaseServerType }}_${{ env.databaseServerVersion }}.tar'
}
else
{
if (-not (Test-Path -PathType Container './cache/database'))
{
New-Item -ItemType Directory './cache/database'
}
docker pull '${{ env.databaseServerType }}:${{ env.databaseServerVersion }}'
docker save -o './cache/database/${{ env.databaseServerType }}_${{ env.databaseServerVersion }}.tar' '${{ env.databaseServerType }}:${{ env.databaseServerVersion }}'
dir './cache/database' -ErrorAction SilentlyContinue | Select-Object -ExpandProperty FullName
}
docker run --name '${{ env.databaseServerType }}' -e MYSQL_ROOT_PASSWORD=Password12! -p 127.0.0.1:3306:3306 -d '${{ env.databaseServerType }}:${{ env.databaseServerVersion }}'
$startTime = Get-Date
while (!($started = ${{ env.clientCommandPrefix }} --protocol=tcp -h localhost -P 3306 -u root -pPassword12! -e 'select 1;') -and ((Get-Date) - $startTime).TotalMinutes -lt $waitMinutes)
{
Start-Sleep -Seconds $pollingIntervalSeconds
}
if (!$started)
{
throw "${{ env.databaseServerType }}:${{ env.databaseServerVersion }} docker container failed to start in ${waitMinutes} minutes"
exit 1
}
- name: Install Database Server - Windows
if: ${{ env.os == 'windows' }}
shell: pwsh
run: |
$mySqlServiceName = '${{ env.databaseServerType }}_${{ env.databaseServerVersion }}'
$lowerCaseTableNames = 2
$packageName = 'Pomelo.Chocolatey.${{ env.databaseServerType }}.Server'
$mySqlBinPath = "C:\tools\${packageName}\current\bin"
$mySqlIniPath = "C:\tools\${packageName}\current\my.ini"
$mySqlDataPath = 'C:\ProgramData\${{ env.databaseServerType }}\data'
dir "$env:Temp\${{ env.databaseServerType }}\${{ env.databaseServerVersion }}" -ErrorAction SilentlyContinue | Select-Object -ExpandProperty FullName
$service = Get-Service '*${{ env.databaseServerType }}*' -ErrorAction SilentlyContinue
if ($service -ne $null)
{
throw "A service for ${{ env.databaseServerType }} appears to already exist."
exit 1
}
# choco config set cacheLocation '$(Pipeline.Workspace)/cache/database'
choco install $packageName '--version=${{ env.databaseServerVersion }}' --ignore-dependencies --source 'https://www.myget.org/F/pomelo/api/v2;https://community.chocolatey.org/api/v2' --params "/serviceName:$mySqlServiceName"
Get-Service '*${{ env.databaseServerType }}*' -ErrorAction SilentlyContinue
Stop-Service $mySqlServiceName -Verbose
echo "Update PATH environment variable"
$env:PATH = "$mySqlBinPath;$env:PATH"
echo "PATH=$env:PATH" >> $env:GITHUB_ENV
echo "Update configuration file"
"lower_case_table_names=$lowerCaseTableNames" >> $mySqlIniPath
Remove-Item $mySqlDataPath/* -Recurse -Force -Verbose
echo "Reinitialize database server"
if ('${{ env.databaseServerType }}' -eq 'mysql')
{
${{ env.serverExecutable }} --defaults-file="$mySqlIniPath" --initialize-insecure
}
else
{
mysql_install_db --datadir="$mySqlDataPath"
}
Start-Service $mySqlServiceName -Verbose
echo "Setup credentials"
${{ env.clientCommandPrefix }} -h localhost -u root -e "ALTER USER 'root'@'localhost' IDENTIFIED BY 'Password12!';"
${{ env.clientCommandPrefix }} -h localhost -u root -pPassword12! -e "SELECT @@version;"
dir "$env:Temp\${packageName}\${{ env.databaseServerVersion }}" -ErrorAction SilentlyContinue | Select-Object -ExpandProperty FullName
- name: Setup Database
shell: pwsh
run: ${{ env.clientCommandPrefix }} -u root -pPassword12! -e "SET GLOBAL sql_mode = '${{ env.sqlMode }}'; SET GLOBAL max_connections = ${{ env.maxConnections }};"
- name: Database Information
shell: pwsh
run: ${{ env.clientCommandPrefix }} -u root -pPassword12! -e 'SHOW VARIABLES;'
- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json
- name: .NET Information
shell: pwsh
run: |
dotnet --info
- name: Install EF Core Tools
shell: pwsh
run: |
dotnet tool restore
dotnet ef --version
- name: Restore dependencies
shell: pwsh
run: dotnet restore
- name: Setup Solution
shell: pwsh
run: |
Copy-Item test/EFCore.MySql.FunctionalTests/config.json.example test/EFCore.MySql.FunctionalTests/config.json
Copy-Item test/EFCore.MySql.IntegrationTests/appsettings.ci.json test/EFCore.MySql.IntegrationTests/appsettings.json
Copy-Item test/EFCore.MySql.IntegrationTests/config.json.example test/EFCore.MySql.IntegrationTests/config.json
- name: Setup Integration Tests
shell: pwsh
run: |
./test/EFCore.MySql.IntegrationTests/scripts/rebuild.ps1
- name: Build Solution
shell: pwsh
run: |
dotnet build -c Debug
dotnet build -c Release
- name: Functional Tests
if: ${{ env.skipTests != 'true' }}
shell: pwsh
run: dotnet test test/EFCore.MySql.FunctionalTests -c Debug --no-build --logger "GitHubActions;report-warnings=false" --verbosity detailed
- name: Tests
if: ${{ env.skipTests != 'true' }}
shell: pwsh
run: dotnet test --logger "GitHubActions;report-warnings=false" test/EFCore.MySql.Tests
- name: Integration Tests - Applying migrations
if: ${{ env.skipTests != 'true' }}
shell: pwsh
run: dotnet run --project test/EFCore.MySql.IntegrationTests -c Release testMigrate
- name: Integration Tests - Scaffolding
if: ${{ env.skipTests != 'true' }}
shell: pwsh
run: ./test/EFCore.MySql.IntegrationTests/scripts/scaffold.ps1
- name: Integration Tests - With EF_BATCH_SIZE = 1
if: ${{ env.skipTests != 'true' }}
shell: pwsh
run: |
$env:EF_BATCH_SIZE = "1"
dotnet test -c Release --no-build --logger "GitHubActions;report-warnings=false" test/EFCore.MySql.IntegrationTests
- name: Integration Tests - With EF_BATCH_SIZE = 10
if: ${{ env.skipTests != 'true' }}
shell: pwsh
run: |
$env:EF_BATCH_SIZE = "10"
dotnet test -c Release --no-build --logger "GitHubActions;report-warnings=false" test/EFCore.MySql.IntegrationTests
- name: Integration Tests - With EF_BATCH_SIZE = 1
if: ${{ env.skipTests != 'true' }}
shell: pwsh
run: |
$env:EF_RETRY_ON_FAILURE = "3"
dotnet test -c Release --no-build --logger "GitHubActions;report-warnings=false" test/EFCore.MySql.IntegrationTests
- name: Integration Tests - Legacy migrations
if: ${{ env.skipTests != 'true' }}
shell: pwsh
run: ./test/EFCore.MySql.IntegrationTests/scripts/legacy.ps1
- name: Integration Tests - Building migrations with EF_DATABASE = pomelo_test2
if: ${{ env.skipTests != 'true' }}
shell: pwsh
run: |
$env:EF_DATABASE = "pomelo_test2"
dotnet build ./test/EFCore.MySql.IntegrationTests -c Release
- name: Integration Tests - Setup migrations with EF_DATABASE = pomelo_test2
if: ${{ env.skipTests != 'true' }}
shell: pwsh
run: |
$env:EF_DATABASE = "pomelo_test2"
./test/EFCore.MySql.IntegrationTests/scripts/rebuild.ps1
- name: Integration Tests - With EF_DATABASE = pomelo_test2
if: ${{ env.skipTests != 'true' }}
shell: pwsh
run: |
$env:EF_DATABASE = "pomelo_test2"
dotnet test -c Release --no-build --logger "GitHubActions;report-warnings=false" test/EFCore.MySql.IntegrationTests
NuGet:
needs: BuildAndTest
if: (github.event_name == 'push' || github.event_name == 'release') && github.repository == 'PomeloFoundation/Pomelo.EntityFrameworkCore.MySql'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
global-json-file: global.json
- name: .NET Information
shell: pwsh
run: |
dotnet --info
- name: NuGet Pack
shell: pwsh
run: |
$officialBuild = '${{ github.ref }}' -match '(?<=^refs/tags/)\d+\.\d+\.\d+.*$'
$officialVersion = $Matches.0
$wipBuild = '${{ github.ref }}' -match '^refs/heads/.*-wip$'
$ciBuildOnly = $wipBuild -or ('${{ github.ref }}' -match '^refs/heads/(?:main|.+-maint|release/.+)$')
$continuousIntegrationTimestamp = Get-Date -Format yyyyMMddHHmmss
$buildSha = '${{ github.sha }}'.SubString(0, 7);
$pack = $officialBuild -or $ciBuildOnly
$pushToAzureArtifacts = $pack
$pushToMygetOrg = $pack
$pushToNugetOrg = $pack -and $officialBuild
echo "pushToAzureArtifacts: $pushToAzureArtifacts"
echo "pushToMygetOrg: $pushToMygetOrg"
echo "pushToNugetOrg: $pushToNugetOrg"
echo "officialBuild: $officialBuild"
echo "officialVersion: $officialVersion"
echo "wipBuild: $wipBuild"
echo "ciBuildOnly: $ciBuildOnly"
echo "continuousIntegrationTimestamp: $continuousIntegrationTimestamp"
echo "buildSha: $buildSha"
echo "pack: $pack"
if ($pack)
{
$projectFiles = Get-ChildItem src/*/*.csproj -Recurse | % { $_.FullName }
$combinations = @('default', @('Release')), @('withPdbs', @('Release', 'Debug')) #, @('embeddedPdbs', @('Release', 'Debug'))
foreach ($combination in $combinations)
{
$type = $combination[0]
$configurations = $combination[1]
foreach ($configuration in $configurations)
{
$arguments = 'pack', '-c', $configuration, '-o', "nupkgs/$configuration/$type", '-p:ContinuousIntegrationBuild=true'
if ($officialBuild)
{
$arguments += "-p:OfficialVersion=$officialVersion"
}
if ($ciBuildOnly)
{
$arguments += "-p:ContinuousIntegrationTimestamp=$continuousIntegrationTimestamp"
$arguments += "-p:BuildSha=$buildSha"
}
switch ($type)
{
'withPdbs' { $arguments += '-p:PackPdb=true', '-p:IncludeSymbols=false' }
'embeddedPdbs' { $arguments += '-p:DebugType=embedded', '-p:IncludeSymbols=false' }
}
foreach ($projectFile in $projectFiles)
{
echo "Type: $type, Configuration: $configuration, Project: $projectFile"
echo "Pack command: dotnet $(($arguments + $projectFile) -join ' ')"
& dotnet ($arguments + $projectFile)
}
}
}
}
echo "pushToAzureArtifacts=$pushToAzureArtifacts" >> $env:GITHUB_ENV
echo "pushToMygetOrg=$pushToMygetOrg" >> $env:GITHUB_ENV
echo "pushToNugetOrg=$pushToNugetOrg" >> $env:GITHUB_ENV
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: nupkgs
path: nupkgs
- name: "NuGet Push - AZDO Feed - Debug"
if: ${{ env.pushToAzureArtifacts == 'true' }}
working-directory: nupkgs
shell: pwsh
run: |
# https://learn.microsoft.com/en-us/azure/devops/artifacts/nuget/dotnet-exe?view=azure-devops#publish-packages-from-external-sources
dotnet new nugetconfig --output './azdo-nuget' --force
try
{
dotnet nuget add source 'https://pkgs.dev.azure.com/pomelo-efcore/Pomelo.EntityFrameworkCore.MySql/_packaging/pomelo-efcore-debug/nuget/v3/index.json' --name 'azdo-pomelo-efcore-debug' --username '${{ vars.AZUREDEVOPS_POMELO_ALLPACKAGES_PUSHNEW_USERNAME }}' --password '${{ secrets.AZUREDEVOPS_POMELO_ALLPACKAGES_PUSHNEW_PASSWORD }}' --store-password-in-clear-text --configfile './azdo-nuget/nuget.config'
dotnet nuget push './Debug/withPdbs/**/*.nupkg' --api-key 'foo' --source 'azdo-pomelo-efcore-debug' --skip-duplicate
}
finally
{
Remove-Item ./azdo-nuget -Recurse -Force
}
- name: "NuGet Push - AZDO Feed - Release"
if: ${{ env.pushToAzureArtifacts == 'true' }}
working-directory: nupkgs
shell: pwsh
run: |
# https://learn.microsoft.com/en-us/azure/devops/artifacts/nuget/dotnet-exe?view=azure-devops#publish-packages-from-external-sources
dotnet new nugetconfig --output './azdo-nuget' --force
try
{
dotnet nuget add source 'https://pkgs.dev.azure.com/pomelo-efcore/Pomelo.EntityFrameworkCore.MySql/_packaging/pomelo-efcore-public/nuget/v3/index.json' --name 'azdo-pomelo-efcore-public' --username '${{ vars.AZUREDEVOPS_POMELO_ALLPACKAGES_PUSHNEW_USERNAME }}' --password '${{ secrets.AZUREDEVOPS_POMELO_ALLPACKAGES_PUSHNEW_PASSWORD }}' --store-password-in-clear-text --configfile './azdo-nuget/nuget.config'
dotnet nuget push './Release/withPdbs/**/*.nupkg' --api-key 'foo' --source 'azdo-pomelo-efcore-public' --skip-duplicate
}
finally
{
Remove-Item ./azdo-nuget -Recurse -Force
}
- name: "NuGet Push - myget.org - Debug"
if: ${{ env.pushToMygetOrg == 'true' }}
working-directory: nupkgs
shell: pwsh
run: dotnet nuget push './Debug/withPdbs/**/*.nupkg' --api-key '${{ secrets.MYGETORG_POMELO_ALLPACKAGES_DEBUG_PUSHNEW }}' --source 'https://www.myget.org/F/pomelo-debug/api/v3/index.json' --skip-duplicate
- name: "NuGet Push - myget.org - Release"
if: ${{ env.pushToMygetOrg == 'true' }}
working-directory: nupkgs
shell: pwsh
run: dotnet nuget push './Release/default/**/*.nupkg' --api-key '${{ secrets.MYGETORG_POMELO_ALLPACKAGES_PUSHNEW }}' --source 'https://www.myget.org/F/pomelo/api/v3/index.json' --skip-duplicate
- name: "NuGet Push - nuget.org - Release"
if: ${{ env.pushToNugetOrg == 'true' }}
working-directory: nupkgs
shell: pwsh
run: dotnet nuget push './Release/default/**/*.nupkg' --api-key '${{ secrets.NUGETORG_POMELO_ALLPACKAGES_PUSHNEW }}' --source 'https://api.nuget.org/v3/index.json'