Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -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)."
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net11.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" />
<PackageReference Include="BenchmarkDotNet" Version="0.15.8" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net11.0</TargetFramework>
<!-- This console app references the test project; it keeps its own Main instead of the xunit entry point that flows from there. -->
<XunitAutoGeneratedEntryPoint>false</XunitAutoGeneratedEntryPoint>
</PropertyGroup>

<ItemGroup>
Expand Down
16 changes: 8 additions & 8 deletions Open.ChannelExtensions.Tests/BasicTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -482,10 +482,10 @@ public static async Task PipeFilterTest()
List<int> even = await evenFilter;
List<int> 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]
Expand All @@ -510,10 +510,10 @@ public static async Task PipeFilterAsyncTest()
List<int> even = await evenFilter;
List<int> 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]
Expand Down
6 changes: 3 additions & 3 deletions Open.ChannelExtensions.Tests/BatchTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
3 changes: 2 additions & 1 deletion Open.ChannelExtensions.Tests/CancellationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ await range
}
catch (Exception ex)
{
Assert.IsType<OperationCanceledException>(ex);
// Cancellation can surface as OperationCanceledException or its subclass TaskCanceledException, depending on timing.
Assert.IsAssignableFrom<OperationCanceledException>(ex);
}

Assert.Equal(1, count);
Expand Down
15 changes: 8 additions & 7 deletions Open.ChannelExtensions.Tests/Open.ChannelExtensions.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net11.0</TargetFramework>
<LangVersion>latest</LangVersion>
<IsPackable>false</IsPackable>
<!-- xUnit1051: these tests call the overloads without a CancellationToken on purpose. The library takes a different path when a token can be cancelled, so passing the test token would stop them covering the default path. -->
<NoWarn>$(NoWarn);xUnit1051</NoWarn>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Open.ChannelExtensions\Open.ChannelExtensions.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.*" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.*" />
<PackageReference Include="xunit" Version="2.*" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.*">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.12.0" />
<PackageReference Include="xunit.v3" Version="4.0.4" />
<PackageReference Include="xunit.runner.visualstudio" Version="4.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.*">
<PackageReference Include="coverlet.collector" Version="10.1.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
1 change: 0 additions & 1 deletion Open.ChannelExtensions.Tests/_Global.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
global using FluentAssertions;
global using System;
global using System.Collections.Generic;
global using System.Diagnostics;
Expand Down
16 changes: 16 additions & 0 deletions Open.ChannelExtensions/CompatibilitySuppressions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- https://learn.microsoft.com/dotnet/fundamentals/package-validation/diagnostic-ids -->
<Suppressions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>F:Open.ChannelExtensions.BufferingChannelReader`2.SyncLock</Target>
<Left>lib/net8.0/Open.ChannelExtensions.dll</Left>
<Right>lib/net9.0/Open.ChannelExtensions.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Open.ChannelExtensions.Extensions.ReadAllAsync``1(System.Threading.Channels.ChannelReader{``0},System.Threading.CancellationToken)</Target>
<Left>lib/netstandard2.0/Open.ChannelExtensions.dll</Left>
<Right>lib/netstandard2.1/Open.ChannelExtensions.dll</Right>
</Suppression>
</Suppressions>
24 changes: 13 additions & 11 deletions Open.ChannelExtensions/Open.ChannelExtensions.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0; netstandard2.1; net6.0; net8.0; net9.0; net10.0;</TargetFrameworks>
<TargetFrameworks>netstandard2.0; netstandard2.1; net6.0; net8.0; net9.0; net10.0; net11.0;</TargetFrameworks>
<LangVersion>latest</LangVersion>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<AnalysisMode>AllEnabledByDefault</AnalysisMode>
Expand All @@ -22,8 +22,8 @@
<RepositoryType>git</RepositoryType>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Version>10.0.0</Version>
<PackageReleaseNotes>Lowered .NET Standard 2.0/2.1 dependency versions to 6.0.0 to reduce minimum requirements for consumers.</PackageReleaseNotes>
<Version>11.0.0</Version>
<PackageReleaseNotes>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.</PackageReleaseNotes>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<IncludeSymbols>true</IncludeSymbols>
Expand All @@ -32,12 +32,14 @@
<PackageReadmeFile>README.md</PackageReadmeFile>
<!-- Don't enforce collection expressions as they don't work in .NET 6. -->
<NoWarn>IDE0130;IDE0301;IDE0303;IDE0304;IDE0079;</NoWarn>
<!-- CA1724: the public type name Extensions has shipped for years. Renaming it would break callers; it has never caused a conflict. -->
<NoWarn>$(NoWarn);CA1724</NoWarn>
<!-- Package validation: every pack checks the public API against 10.0.0, strictly (additions count too). CompatibilitySuppressions.xml lists the two known differences between targets inside the package. -->
<EnablePackageValidation>true</EnablePackageValidation>
<PackageValidationBaselineVersion>10.0.0</PackageValidationBaselineVersion>
<ApiCompatStrictMode>true</ApiCompatStrictMode>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="10.0.300" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
<None Include="..\README.md">
<Pack>True</Pack>
Expand All @@ -49,14 +51,14 @@
</None>
</ItemGroup>

<!-- Minimum version only (not exact-pinned): keeps the floor low so netstandard consumers aren't forced to a newer minimum, while still allowing their own app's dependency graph to resolve a higher version if needed. -->
<!-- Each target gets the newest version it supports. These are built into .NET 6 and later. -->
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'netstandard2.1'">
<PackageReference Include="System.Threading.Channels" Version="6.0.0" />
<PackageReference Include="System.Collections.Immutable" Version="6.0.0" />
<PackageReference Include="System.Threading.Channels" Version="11.0.0" />
<PackageReference Include="System.Collections.Immutable" Version="11.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="6.0.0" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="11.0.0" />
</ItemGroup>

<!-- Disable the nullable warnings when compiling for .NET Standard 2.0 -->
Expand Down
9 changes: 9 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"sdk": {
"version": "11.0.100",
"rollForward": "latestFeature"
},
"test": {
"runner": "Microsoft.Testing.Platform"
}
}