Skip to content

Commit

Permalink
Add .NET 9 targets for testing
Browse files Browse the repository at this point in the history
Also:
- Use .NET 9 SDK and C# 13
- Upgrade various dependencies
- Resolve new compiler warnings
- Use GitHubActionsTestLogger
- Update GitHub Actions
  • Loading branch information
brantburnett committed Nov 30, 2024
1 parent a779178 commit 2ce8301
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 126 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Setup .NET 6.0
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v4
with:
dotnet-version: '6.0.x'
dotnet-version: 9.0.x

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -48,7 +48,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1
uses: github/codeql-action/autobuild@v2

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
Expand All @@ -62,4 +62,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
uses: github/codeql-action/analyze@v2
71 changes: 26 additions & 45 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,81 +14,60 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
framework: ["net6.0", "net8.0"]
framework: ["net6.0", "net8.0", "net9.0"]
disable: ["HWIntrinsics", "SSSE3", "BMI2", "Noop"]

steps:
- uses: actions/checkout@v4
- name: Setup .NET 8
uses: actions/setup-dotnet@v3
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- name: Setup .NET 6
if: matrix.framework == 'net6.0'
uses: actions/setup-dotnet@v3
with:
dotnet-version: '6.0.x'
dotnet-version:
6.0.x
7.0.x
8.0.x
9.0.x
# Cache packages for faster subsequent runs
- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj', '**/*.props', '**/*.targets') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Install dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --verbosity normal
run: dotnet build --no-restore --configuration Release --verbosity normal
- name: Test
run: |
export COMPlus_Enable${{ matrix.disable }}=0 && \
dotnet test --no-build -f ${{ matrix.framework }} --configuration Release --verbosity normal --logger "trx;LogFileName=results.trx"
- name: Test Report
uses: actions/upload-artifact@v3
if: success() || failure() # run this step even if previous step failed
with:
name: test-results-${{ matrix.framework }}-${{ matrix.disable }}
path: "**/results.trx"
dotnet test --no-build -f ${{ matrix.framework }} --configuration Release --verbosity normal --logger "GitHubActions;summary.includePassedTests=true;summary.includeSkippedTests=true"
test-windows:

runs-on: windows-latest

steps:
- uses: actions/checkout@v4
- name: Setup .NET 8
uses: actions/setup-dotnet@v3
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
dotnet-version: '9.0.x'
# Cache packages for faster subsequent runs
- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj', '**/*.props', '**/*.targets') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Install dependencies
run: dotnet restore
- name: Test
run: |-
dotnet test --runtime win-x64 -f net48 --configuration Release --verbosity normal --logger "trx;LogFileName=results-x64.trx"
dotnet test --runtime win-x86 -f net48 --configuration Release --verbosity normal --logger "trx;LogFileName=results-x86.trx"
- name: Test Report x64
uses: actions/upload-artifact@v3
if: success() || failure() # run this step even if previous step failed
with:
name: test-results-windows-x64
path: "**/results-x64.trx"
- name: Test Report x86
uses: actions/upload-artifact@v3
if: success() || failure() # run this step even if previous step failed
with:
name: test-results-windows-x86
path: "**/results-x86.trx"
dotnet test --runtime win-x64 -f net48 --configuration Release --verbosity normal --logger "GitHubActions;summary.includePassedTests=true;summary.includeSkippedTests=true"
dotnet test --runtime win-x86 -f net48 --configuration Release --verbosity normal --logger "GitHubActions;summary.includePassedTests=true;summary.includeSkippedTests=true"
publish:

Expand All @@ -100,16 +79,18 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Setup .NET 8
uses: actions/setup-dotnet@v3
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
dotnet-version: 9.0.x

- name: Install dependencies
run: dotnet restore
- run: echo "VERSION=${GITHUB_REF/refs\/tags\/release\//}" >> $GITHUB_ENV
- name: Get version
id: version
run: echo "version=${GITHUB_REF/refs\/tags\/release\//}" >> $GITHUB_OUTPUT
- name: Pack
run: dotnet pack --configuration Release -p:Version=${{ env.VERSION }}
run: dotnet pack --configuration Release -p:Version=${{ steps.version.outputs.version }}
- name: Push to NuGet.org
run: |
dotnet nuget push **/*.nupkg --api-key ${{ secrets.NUGET_API_KEY}} --source https://api.nuget.org/v3/index.json
40 changes: 0 additions & 40 deletions .github/workflows/test-report.yml

This file was deleted.

6 changes: 6 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Project>
<PropertyGroup>
<LangVersion>13</LangVersion>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
</PropertyGroup>
</Project>
11 changes: 8 additions & 3 deletions Snappier.Benchmarks/Snappier.Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net48;net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks>net48;net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
<PlatformTarget>AnyCPU</PlatformTarget>

<IsPackable>false</IsPackable>
Expand All @@ -21,12 +21,17 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.10" />
<PackageReference Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.13.10" />
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" />
<PackageReference Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.14.0" />
</ItemGroup>

<ItemGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net48'))">
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Collections.Immutable" Version="8.0.0" />
<PackageReference Include="System.Reflection.Metadata" Version="8.0.0" />
</ItemGroup>

<ItemGroup Condition=" '$(Configuration)' != 'Previous' ">
Expand Down
10 changes: 7 additions & 3 deletions Snappier.Tests/Snappier.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('Windows'))">$(TargetFrameworks);net48</TargetFrameworks>

<IsPackable>false</IsPackable>
Expand All @@ -19,9 +19,13 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="GitHubActionsTestLogger" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="JUnitTestLogger" Version="1.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
47 changes: 23 additions & 24 deletions Snappier.Tests/SnappyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ public void CompressAndDecompressFile(string filename)
Assert.NotNull(resource);

var input = new byte[resource.Length];
resource.Read(input, 0, input.Length);
var bytesRead = resource.Read(input, 0, input.Length);

var compressed = new byte[Snappy.GetMaxCompressedLength(input.Length)];
var compressedLength = Snappy.Compress(input, compressed);
var compressed = new byte[Snappy.GetMaxCompressedLength(bytesRead)];
var compressedLength = Snappy.Compress(input.AsSpan(0, bytesRead), compressed);

var compressedSpan = compressed.AsSpan(0, compressedLength);

Expand All @@ -41,19 +41,18 @@ public void CompressAndDecompressFile(string filename)
Assert.Equal(input, output);
}

public static IEnumerable<object[]> CompressAndDecompressStringCases()
{
yield return new object[] {""};
yield return new object[] {"a"};
yield return new object[] {"ab"};
yield return new object[] {"abc"};

yield return new object[] {"aaaaaaa" + new string('b', 16) + "aaaaaabc"};
yield return new object[] {"aaaaaaa" + new string('b', 256) + "aaaaaabc"};
yield return new object[] {"aaaaaaa" + new string('b', 2047) + "aaaaaabc"};
yield return new object[] {"aaaaaaa" + new string('b', 65536) + "aaaaaabc"};
yield return new object[] {"abcaaaaaaa" + new string('b', 65536) + "aaaaaabc"};
}
public static TheoryData<string> CompressAndDecompressStringCases() =>
[
"",
"a",
"ab",
"abc",
"aaaaaaa" + new string('b', 16) + "aaaaaabc",
"aaaaaaa" + new string('b', 256) + "aaaaaabc",
"aaaaaaa" + new string('b', 2047) + "aaaaaabc",
"aaaaaaa" + new string('b', 65536) + "aaaaaabc",
"abcaaaaaaa" + new string('b', 65536) + "aaaaaabc"
];

[Theory]
[MemberData(nameof(CompressAndDecompressStringCases))]
Expand Down Expand Up @@ -139,15 +138,15 @@ public void BadData_FromFile_ThrowsInvalidDataException(string filename)
Assert.NotNull(resource);

var input = new byte[resource.Length];
resource.Read(input, 0, input.Length);
var bytesRead = resource.Read(input, 0, input.Length);

Assert.Throws<InvalidDataException>(() =>
{
var length = Snappy.GetUncompressedLength(input);
var length = Snappy.GetUncompressedLength(input.AsSpan(0, bytesRead));
Assert.InRange(length, 0, 1 << 20);

var output = new byte[length];
Snappy.Decompress(input, output);
Snappy.Decompress(input.AsSpan(0, bytesRead), output);
});
}

Expand All @@ -159,17 +158,17 @@ public void DecompressToMemory()
Assert.NotNull(resource);

var input = new byte[resource.Length];
resource.Read(input, 0, input.Length);
var bytesRead = resource.Read(input, 0, input.Length);

var compressed = new byte[Snappy.GetMaxCompressedLength(input.Length)];
var compressedLength = Snappy.Compress(input, compressed);
var compressed = new byte[Snappy.GetMaxCompressedLength(bytesRead)];
var compressedLength = Snappy.Compress(input.AsSpan(0, bytesRead), compressed);

var compressedSpan = compressed.AsSpan(0, compressedLength);

using var output = Snappy.DecompressToMemory(compressedSpan);

Assert.Equal(input.Length, output.Memory.Length);
Assert.Equal(input, output.Memory.Span.ToArray());
Assert.Equal(bytesRead, output.Memory.Length);
Assert.True(input.AsSpan(0, bytesRead).SequenceEqual(output.Memory.Span));
}

[Fact]
Expand Down
10 changes: 8 additions & 2 deletions Snappier.sln
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30523.141
# Visual Studio Version 17
VisualStudioVersion = 17.12.35521.163 d17.12
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Snappier", "Snappier\Snappier.csproj", "{C0EC5011-2B15-40CF-B181-A54980788AAF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Snappier.Tests", "Snappier.Tests\Snappier.Tests.csproj", "{66ECAD47-69F3-4876-8FA0-58AAB36FC9F1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Snappier.Benchmarks", "Snappier.Benchmarks\Snappier.Benchmarks.csproj", "{993CDA9B-A128-4F32-A0EE-FBADC98F8C16}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{82E8B397-E514-4F81-A523-E4072A252B8E}"
ProjectSection(SolutionItems) = preProject
Directory.Build.props = Directory.Build.props
global.json = global.json
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
6 changes: 3 additions & 3 deletions Snappier/Snappier.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="System.Memory" Version="4.5.5" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
<PackageReference Include="System.Memory" Version="4.6.0" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.1.0" />
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.6.0" />
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"sdk": {
"version": "9.0.100",
"rollForward": "latestFeature"
}
}

0 comments on commit 2ce8301

Please sign in to comment.