Repository navigation
321 lines (291 loc) · 14.9 KB
/
Copy pathtests.yml
File metadata and controls
321 lines (291 loc) · 14.9 KB
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
name: Tests
# Runs the Core test suite on every pull request and every push to master, and checks the packages for known vulnerabilities.
# The suite runs on net11.0 in Release and in Debug (Debug.Assert is live there). net10.0 is still built and shipped; its tests run only where it differs (the LegacyCompiler job).
# A separate job runs the LegacyCompiler tests, which compile the public call shapes with older C# language versions.
# Another runs the source generator's tests and the package consumer tests (see its steps).
# Another job builds the Benchmarks project (it is not in the solution), so a change to the public API cannot leave its call sites behind.
# Another runs `dotnet format` style and analyzers at info severity on every project, which is what the IDE shows.
# SQL Server LocalDB is part of the runner image. ODX_REQUIRE_SQL=1 makes the tests that need it fail, instead of skip, when it is missing.
on:
push:
branches: [master]
pull_request:
workflow_dispatch:
permissions:
contents: read
# One group per ref: a pull request's ref (refs/pull/N/merge) never equals master's, so a pull request run can never cancel a master run.
# A newer push to a pull request cancels the older run; master and manual runs queue and are never cancelled.
concurrency:
group: tests-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
env:
DOTNET_NOLOGO: true
DOTNET_CLI_TELEMETRY_OPTOUT: true
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
jobs:
test:
name: Test ${{ matrix.name }}
runs-on: windows-latest
timeout-minutes: 30
defaults:
run:
shell: pwsh
strategy:
fail-fast: false
matrix:
include:
- name: net11.0-Release
tfm: net11.0
configuration: Release
- name: net11.0-Debug
tfm: net11.0
configuration: Debug
steps:
- uses: actions/checkout@v7
- uses: actions/setup-dotnet@v6
with:
dotnet-version: |
10.0.x
11.0.x
# The tests that need a real SQL Server connect to (localdb)\MSSQLLocalDB. The runner image carries the LocalDB runtime,
# but the automatic instance is created on its first start, which can outlast a connection timeout. Start it here,
# so the first test does not pay for it, and fail now, with a clear message, if the image has no LocalDB.
- name: Start SQL Server LocalDB
run: |
$exe = (Get-Command SqlLocalDB.exe -ErrorAction SilentlyContinue)?.Source
if (-not $exe) {
$exe = Get-ChildItem "$env:ProgramFiles\Microsoft SQL Server\*\Tools\Binn\SqlLocalDB.exe" -ErrorAction SilentlyContinue |
Sort-Object FullName | Select-Object -Last 1 -ExpandProperty FullName
}
if (-not $exe) { throw 'SqlLocalDB.exe was not found on this runner image, so the SQL Server tests cannot run.' }
& $exe start MSSQLLocalDB
if ($LASTEXITCODE -ne 0) { throw "SqlLocalDB start MSSQLLocalDB failed with exit code $LASTEXITCODE" }
& $exe info MSSQLLocalDB
- name: Run the tests (${{ matrix.name }})
env:
ODX_REQUIRE_SQL: 1
run: dotnet test Tests/Open.Database.Extensions.Core.Tests -c ${{ matrix.configuration }} -f ${{ matrix.tfm }} --logger "trx;LogFileName=${{ matrix.name }}.trx" --results-directory TestResults/${{ matrix.name }}
- name: Upload the TRX files
if: always()
uses: actions/upload-artifact@v7
with:
name: trx-${{ matrix.name }}
path: TestResults/${{ matrix.name }}/*.trx
legacy-compiler:
name: Test older C# language versions
runs-on: windows-latest
timeout-minutes: 30
defaults:
run:
shell: pwsh
steps:
- uses: actions/checkout@v7
# The SDK in global.json builds everything; 8.0.x adds the .NET 8 runtime that the net8.0 target of this project runs on.
# net472 runs on the Windows runner itself.
- uses: actions/setup-dotnet@v6
with:
dotnet-version: |
8.0.x
10.0.x
11.0.x
# This project compiles the public call shapes with the older C# language versions that consumers still use, one per target framework
# (see its .csproj), so a binding regression on an older compiler fails here. No -f: it runs every target framework the project has.
- name: Run the LegacyCompiler tests
run: dotnet test Tests/Open.Database.Extensions.LegacyCompiler.Tests -c Release --logger "trx;LogFilePrefix=legacy-compiler" --results-directory TestResults/legacy-compiler
- name: Upload the TRX files
if: always()
uses: actions/upload-artifact@v7
with:
name: trx-legacy-compiler
path: TestResults/legacy-compiler/*.trx
generator:
name: Test the source generator
runs-on: windows-latest
timeout-minutes: 30
defaults:
run:
shell: pwsh
steps:
- uses: actions/checkout@v7
- uses: actions/setup-dotnet@v6
with:
dotnet-version: |
10.0.x
11.0.x
# As in the test job: both steps below read from a real SQL Server.
- name: Start SQL Server LocalDB
run: |
$exe = (Get-Command SqlLocalDB.exe -ErrorAction SilentlyContinue)?.Source
if (-not $exe) {
$exe = Get-ChildItem "$env:ProgramFiles\Microsoft SQL Server\*\Tools\Binn\SqlLocalDB.exe" -ErrorAction SilentlyContinue |
Sort-Object FullName | Select-Object -Last 1 -ExpandProperty FullName
}
if (-not $exe) { throw 'SqlLocalDB.exe was not found on this runner image, so the SQL Server tests cannot run.' }
& $exe start MSSQLLocalDB
if ($LASTEXITCODE -ne 0) { throw "SqlLocalDB start MSSQLLocalDB failed with exit code $LASTEXITCODE" }
& $exe info MSSQLLocalDB
# The generator runs as an analyzer of the test project and intercepts its Map<T>() calls on the models of another assembly;
# each test compares those rows, or that exception, with the runtime map's on the same data. One target framework: net11.0.
- name: Run the generator tests
env:
ODX_REQUIRE_SQL: 1
run: dotnet test Tests/Open.Database.Extensions.Generator.Tests -c Release --logger "trx;LogFilePrefix=generator" --results-directory TestResults/generator
# What a NuGet user gets: the packages are packed, and a project that references only them is built and run with the generator on,
# arriving through MSSqlClient alone, switched off, and with C# 12. It runs on net472 and net11.0, against LocalDB and SQLite.
- name: Run the package consumer tests
env:
ODX_REQUIRE_SQL: 1
run: |
$suffix = "ci.${{ github.run_id }}.${{ github.run_attempt }}"
$feed = Join-Path $env:RUNNER_TEMP 'feed'
$siblings = 'MSSqlClient', 'Channel', 'Dataflow', 'Extensions'
foreach ($project in @('Core') + $siblings) {
# GeneratePackageOnBuild (Source/Directory.Build.props) stops `dotnet pack` building first, which a clean checkout needs.
dotnet pack "Source/$project" -c Release -o $feed -p:VersionSuffix=$suffix -p:GeneratePackageOnBuild=false
if ($LASTEXITCODE -ne 0) { throw "dotnet pack Source/$project failed" }
}
# The Core package carries the generator and its build targets, and no sibling package holds them back from its consumers.
Add-Type -AssemblyName System.IO.Compression.FileSystem
function Read-Package($id) {
$path = Join-Path $feed "$id.11.0.0-$suffix.nupkg"
[IO.Compression.ZipFile]::OpenRead($path)
}
$core = Read-Package 'Open.Database.Extensions.Core'
try {
foreach ($entry in 'analyzers/dotnet/roslyn4.14/cs/Open.Database.Extensions.Generator.dll', 'buildTransitive/Open.Database.Extensions.Core.targets') {
if (-not $core.GetEntry($entry)) { throw "The Core package has no $entry" }
}
} finally { $core.Dispose() }
foreach ($project in $siblings) {
$id = if ($project -eq 'Extensions') { 'Open.Database.Extensions' } else { "Open.Database.Extensions.$project" }
$package = Read-Package $id
try {
$reader = [IO.StreamReader]::new($package.GetEntry("$id.nuspec").Open())
[xml]$nuspec = $reader.ReadToEnd()
$reader.Dispose()
$dependencies = @($nuspec.package.metadata.dependencies.group.dependency | Where-Object id -eq 'Open.Database.Extensions.Core')
if ($dependencies.Count -eq 0) { throw "$id has no dependency on Core" }
if ($dependencies | Where-Object { $_.exclude -match 'Analyzers|Build' }) { throw "$id keeps Core's generator or build targets from its consumers" }
} finally { $package.Dispose() }
}
$variants = [ordered]@{ core = @(); mssqlclient = @('-p:OdxVia=MSSqlClient'); off = @('-p:OdxGenerateMaps=false'); csharp12 = @('-p:LangVersion=12') }
$failed = @()
foreach ($variant in $variants.Keys) {
$options = @("-p:OdxFeed=$feed", "-p:OdxPackageVersion=11.0.0-$suffix") + $variants[$variant]
$consumer = 'Tests/Open.Database.Extensions.PackageConsumer.Tests'
dotnet build $consumer -c Release --no-incremental @options
if ($LASTEXITCODE -ne 0) { $failed += "$variant (build)"; continue }
dotnet test $consumer -c Release --no-build @options --logger "trx;LogFilePrefix=$variant" --results-directory TestResults/consumer
if ($LASTEXITCODE -ne 0) { $failed += $variant }
}
if ($failed.Count -gt 0) { throw "Package consumer tests failed: $($failed -join ', ')" }
- name: Upload the TRX files
if: always()
uses: actions/upload-artifact@v7
with:
name: trx-generator
path: |
TestResults/generator/*.trx
TestResults/consumer/*.trx
benchmarks-build:
name: Build the Benchmarks project
runs-on: windows-latest
timeout-minutes: 15
defaults:
run:
shell: pwsh
steps:
- uses: actions/checkout@v7
- uses: actions/setup-dotnet@v6
with:
dotnet-version: |
10.0.x
11.0.x
# The Benchmarks project is not in the solution, so no other job compiles it. Only the build runs here: no benchmark is run.
# No -f: both target frameworks of the project build.
- name: Build the Benchmarks project (Release)
run: dotnet build Benchmarks/Open.Database.Extensions.Benchmarks -c Release
format:
name: Style and analyzers (info)
runs-on: windows-latest
timeout-minutes: 30
defaults:
run:
shell: pwsh
steps:
- uses: actions/checkout@v7
- uses: actions/setup-dotnet@v6
with:
dotnet-version: |
10.0.x
11.0.x
# dotnet format checks every target framework of each project, at info severity, and changes nothing.
# It exits non-zero when it finds something. When it cannot load a project or a framework it can print nothing and exit 0,
# so that output is a failure too: a zero that proves nothing must not pass.
- name: dotnet format style and analyzers (any finding fails the run)
run: |
$projects = @(
'Source\Core', 'Source\SqlClient', 'Source\MSSqlClient', 'Source\Channel', 'Source\Dataflow', 'Source\Extensions',
'Tests\Open.Database.Extensions.Core.Tests', 'Tests\Open.Database.Extensions.LegacyCompiler.Tests', 'docsite\samples', 'Benchmarks\Open.Database.Extensions.Benchmarks',
'Source\Generator', 'Tests\Open.Database.Extensions.Generator.Models', 'Tests\Open.Database.Extensions.Generator.Tests', 'Benchmarks\Open.Database.Extensions.Benchmarks.Generated')
$failures = @()
foreach ($project in $projects) {
# A full Windows path: with forward slashes the formatter loads nothing and reports a false zero.
$path = (Resolve-Path $project).Path
dotnet restore $path --nologo --verbosity quiet
if ($LASTEXITCODE -ne 0) { $failures += "${project}: restore failed"; continue }
foreach ($check in 'style', 'analyzers') {
$output = (dotnet format $check $path --severity info --verify-no-changes --no-restore --verbosity minimal 2>&1 | Out-String -Width 4096)
$exitCode = $LASTEXITCODE
Write-Host "== $project $check (exit code $exitCode)"
Write-Host $output
if ($output -match 'did not load|Msbuild failed|not recognized') {
$failures += "$project ${check}: the formatter could not load a project or framework, so the check proved nothing"
}
elseif ($exitCode -ne 0) {
$failures += "$project ${check}: findings at info severity (listed above)"
}
}
}
if ($failures.Count -gt 0) {
foreach ($failure in $failures) { Write-Host "::error title=dotnet format::$failure" }
exit 1
}
"No style or analyzer findings in $($projects.Count) project(s)."
vulnerable-packages:
name: Vulnerable packages
runs-on: windows-latest
timeout-minutes: 15
defaults:
run:
shell: pwsh
steps:
- uses: actions/checkout@v7
- uses: actions/setup-dotnet@v6
with:
dotnet-version: 11.0.x
# `dotnet list package --vulnerable` exits 0 even when it finds something, so read what it prints.
# Each library project, the test project and the benchmark projects are listed with their transitive packages.
- name: List vulnerable packages (any finding fails the run)
run: |
$projects = @(Get-ChildItem Source -Recurse -Filter *.csproj) + @(Get-Item Tests/Open.Database.Extensions.Core.Tests/*.csproj) + @(Get-ChildItem Benchmarks -Recurse -Filter *.csproj)
$failures = @()
foreach ($project in $projects) {
$output = (dotnet list $project.FullName package --vulnerable --include-transitive 2>&1 | Out-String)
$exitCode = $LASTEXITCODE
Write-Host $output
if ($exitCode -ne 0) {
$failures += "$($project.Name): dotnet list exited with code $exitCode"
}
elseif ($output -match 'has the following vulnerable packages') {
$failures += "$($project.Name): vulnerable packages found (listed above)"
}
elseif ($output -match 'NU1900') {
$failures += "$($project.Name): the vulnerability data could not be read, so the check proved nothing"
}
}
if ($failures.Count -gt 0) {
foreach ($failure in $failures) { Write-Host "::error title=Vulnerable packages::$failure" }
exit 1
}
"No vulnerable packages in $($projects.Count) project(s)."