Repository navigation
Take Source/SqlClient out of the build: the System.Data.SqlClient package has no version 11 #571
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 (one target framework at a time). | |
| # 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. | |
| # It is built once, then each target framework runs on its own, one after the other: `dotnet test` with no -f starts a test host for every | |
| # target at once, and the three that are not net11.0 twice failed to connect within 90 seconds on this runner. | |
| # Every target runs even when one fails, so the step reports them all, and then fails if any did. | |
| - name: Run the LegacyCompiler tests | |
| run: | | |
| $project = 'Tests/Open.Database.Extensions.LegacyCompiler.Tests' | |
| $frameworks = (dotnet msbuild $project -getProperty:TargetFrameworks) -split ';' | ForEach-Object { $_.Trim() } | Where-Object { $_ } | |
| if ($LASTEXITCODE -ne 0 -or -not $frameworks) { throw "The target frameworks of $project could not be read." } | |
| dotnet build $project -c Release | |
| if ($LASTEXITCODE -ne 0) { throw "dotnet build $project failed with exit code $LASTEXITCODE" } | |
| $failed = @() | |
| $started = Get-Date | |
| foreach ($framework in $frameworks) { | |
| dotnet test $project -c Release --no-build -f $framework --logger "trx;LogFilePrefix=legacy-compiler-$framework" --results-directory TestResults/legacy-compiler | |
| $exitCode = $LASTEXITCODE | |
| # `dotnet test --no-build -f` exits 0 without running anything for a target framework that was not built, so a missing TRX file is a failure too, | |
| # and so is a TRX file that counts no tests. | |
| $results = @(Get-ChildItem TestResults/legacy-compiler -Filter "legacy-compiler-${framework}_*.trx" -ErrorAction SilentlyContinue | Where-Object LastWriteTime -ge $started) | |
| $total = 0 | |
| foreach ($result in $results) { $total += [int]([xml](Get-Content -Raw $result.FullName)).TestRun.ResultSummary.Counters.total } | |
| if ($exitCode -ne 0 -or -not $results -or $total -eq 0) { | |
| $failed += $framework | |
| Write-Host "::error::The LegacyCompiler tests failed on $framework (exit code $exitCode, $($results.Count) result file(s), $total test(s))." | |
| } | |
| } | |
| if ($failed) { throw "The LegacyCompiler tests failed on: $($failed -join ', ')." } | |
| - 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\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)." |