diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..e85194e --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,85 @@ +name: Build + +# Builds every project and target, and checks the packages for known vulnerabilities, on every pull request and every push to master. +# The library builds for netstandard2.0, netstandard2.1, net6.0, net8.0, net9.0, net10.0 and net11.0. +# The test suite does not run here. Its timing-sensitive channel tests fail on small hosted runners (they fail on master too), +# so the owner runs the full suite locally before every release. + +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: build-${{ 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: + build: + name: Build every project and target + runs-on: windows-latest + timeout-minutes: 20 + defaults: + run: + shell: pwsh + steps: + - uses: actions/checkout@v7 + + - uses: actions/setup-dotnet@v6 + with: + dotnet-version: 11.0.x + + # Builds the library for all of its target frameworks, plus the tests, the comparison app and the benchmarks. + # Only the build runs here: no benchmark is run. Any warning fails the run. + - name: Build the solution (Release, warnings as errors) + run: dotnet build Open.ChannelExtensions.sln -c Release -warnaserror + + 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. + - name: List vulnerable packages (any finding fails the run) + run: | + $projects = @(Get-ChildItem -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)." diff --git a/Open.ChannelExtensions.Benchmarks/Open.ChannelExtensions.Benchmarks.csproj b/Open.ChannelExtensions.Benchmarks/Open.ChannelExtensions.Benchmarks.csproj index 05eeb33..c6b3d4c 100644 --- a/Open.ChannelExtensions.Benchmarks/Open.ChannelExtensions.Benchmarks.csproj +++ b/Open.ChannelExtensions.Benchmarks/Open.ChannelExtensions.Benchmarks.csproj @@ -2,13 +2,13 @@ Exe - net9.0 + net11.0 enable enable - + diff --git a/Open.ChannelExtensions.ComparisonTests/Open.ChannelExtensions.ComparisonTests.csproj b/Open.ChannelExtensions.ComparisonTests/Open.ChannelExtensions.ComparisonTests.csproj index ff4eac7..9679ad8 100644 --- a/Open.ChannelExtensions.ComparisonTests/Open.ChannelExtensions.ComparisonTests.csproj +++ b/Open.ChannelExtensions.ComparisonTests/Open.ChannelExtensions.ComparisonTests.csproj @@ -2,7 +2,9 @@ Exe - net9.0 + net11.0 + + false diff --git a/Open.ChannelExtensions.Tests/BasicTests.cs b/Open.ChannelExtensions.Tests/BasicTests.cs index cda4eb0..9c5717d 100644 --- a/Open.ChannelExtensions.Tests/BasicTests.cs +++ b/Open.ChannelExtensions.Tests/BasicTests.cs @@ -482,10 +482,10 @@ public static async Task PipeFilterTest() List even = await evenFilter; List odd = await oddFilter; - even.Count.Should().Be(each); - odd.Count.Should().Be(each); - even.Should().OnlyContain(e => e % 2 == 0); - odd.Should().OnlyContain(e => e % 2 != 0); + Assert.Equal(each, even.Count); + Assert.Equal(each, odd.Count); + Assert.All(even, e => Assert.True(e % 2 == 0)); + Assert.All(odd, e => Assert.True(e % 2 != 0)); } [Fact] @@ -510,10 +510,10 @@ public static async Task PipeFilterAsyncTest() List even = await evenFilter; List odd = await oddFilter; - even.Count.Should().Be(each); - odd.Count.Should().Be(each); - even.Should().OnlyContain(e => e % 2 == 0); - odd.Should().OnlyContain(e => e % 2 != 0); + Assert.Equal(each, even.Count); + Assert.Equal(each, odd.Count); + Assert.All(even, e => Assert.True(e % 2 == 0)); + Assert.All(odd, e => Assert.True(e % 2 != 0)); } [Fact] diff --git a/Open.ChannelExtensions.Tests/BatchTests.cs b/Open.ChannelExtensions.Tests/BatchTests.cs index 68505c8..e051c7c 100644 --- a/Open.ChannelExtensions.Tests/BatchTests.cs +++ b/Open.ChannelExtensions.Tests/BatchTests.cs @@ -476,8 +476,8 @@ public static async Task AnotherComplexBatchJoinScenario() }, cancellationToken); - remaining.Should().Be(0); - channel.Reader.TryRead(out _).Should().BeFalse(); - count.Should().Be(SIZE); + Assert.Equal(0, remaining); + Assert.False(channel.Reader.TryRead(out _)); + Assert.Equal(SIZE, count); } } diff --git a/Open.ChannelExtensions.Tests/CancellationTests.cs b/Open.ChannelExtensions.Tests/CancellationTests.cs index 976ad1f..91977ab 100644 --- a/Open.ChannelExtensions.Tests/CancellationTests.cs +++ b/Open.ChannelExtensions.Tests/CancellationTests.cs @@ -91,7 +91,8 @@ await range } catch (Exception ex) { - Assert.IsType(ex); + // Cancellation can surface as OperationCanceledException or its subclass TaskCanceledException, depending on timing. + Assert.IsAssignableFrom(ex); } Assert.Equal(1, count); diff --git a/Open.ChannelExtensions.Tests/Open.ChannelExtensions.Tests.csproj b/Open.ChannelExtensions.Tests/Open.ChannelExtensions.Tests.csproj index 2ba2be2..331905a 100644 --- a/Open.ChannelExtensions.Tests/Open.ChannelExtensions.Tests.csproj +++ b/Open.ChannelExtensions.Tests/Open.ChannelExtensions.Tests.csproj @@ -1,10 +1,12 @@ - + Exe - net9.0 + net11.0 latest false + + $(NoWarn);xUnit1051 @@ -12,14 +14,13 @@ - - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/Open.ChannelExtensions.Tests/_Global.cs b/Open.ChannelExtensions.Tests/_Global.cs index 168d673..6765a80 100644 --- a/Open.ChannelExtensions.Tests/_Global.cs +++ b/Open.ChannelExtensions.Tests/_Global.cs @@ -1,4 +1,3 @@ -global using FluentAssertions; global using System; global using System.Collections.Generic; global using System.Diagnostics; diff --git a/Open.ChannelExtensions/CompatibilitySuppressions.xml b/Open.ChannelExtensions/CompatibilitySuppressions.xml new file mode 100644 index 0000000..7c92979 --- /dev/null +++ b/Open.ChannelExtensions/CompatibilitySuppressions.xml @@ -0,0 +1,16 @@ + + + + + CP0002 + F:Open.ChannelExtensions.BufferingChannelReader`2.SyncLock + lib/net8.0/Open.ChannelExtensions.dll + lib/net9.0/Open.ChannelExtensions.dll + + + CP0002 + M:Open.ChannelExtensions.Extensions.ReadAllAsync``1(System.Threading.Channels.ChannelReader{``0},System.Threading.CancellationToken) + lib/netstandard2.0/Open.ChannelExtensions.dll + lib/netstandard2.1/Open.ChannelExtensions.dll + + \ No newline at end of file diff --git a/Open.ChannelExtensions/Open.ChannelExtensions.csproj b/Open.ChannelExtensions/Open.ChannelExtensions.csproj index 3eb145e..bc4afa8 100644 --- a/Open.ChannelExtensions/Open.ChannelExtensions.csproj +++ b/Open.ChannelExtensions/Open.ChannelExtensions.csproj @@ -1,7 +1,7 @@ - netstandard2.0; netstandard2.1; net6.0; net8.0; net9.0; net10.0; + netstandard2.0; netstandard2.1; net6.0; net8.0; net9.0; net10.0; net11.0; latest true AllEnabledByDefault @@ -22,8 +22,8 @@ git true true - 10.0.0 - Lowered .NET Standard 2.0/2.1 dependency versions to 6.0.0 to reduce minimum requirements for consumers. + 11.0.0 + Adds a .NET 11 target. Updates every dependency to its newest version; .NET Standard consumers (including .NET Framework) now get the 11.0.0 System packages. No API or behavior changes. MIT true true @@ -32,12 +32,14 @@ README.md IDE0130;IDE0301;IDE0303;IDE0304;IDE0079; + + $(NoWarn);CA1724 + + true + 10.0.0 + true - - - - True @@ -49,14 +51,14 @@ - + - - + + - + diff --git a/global.json b/global.json new file mode 100644 index 0000000..7850a46 --- /dev/null +++ b/global.json @@ -0,0 +1,9 @@ +{ + "sdk": { + "version": "11.0.100", + "rollForward": "latestFeature" + }, + "test": { + "runner": "Microsoft.Testing.Platform" + } +}