Skip to content

Commit

Permalink
Multi-target against .NET 6 and .NET 8
Browse files Browse the repository at this point in the history
  • Loading branch information
bkoelman committed Nov 12, 2023
1 parent 24b9546 commit 4a04823
Show file tree
Hide file tree
Showing 62 changed files with 266 additions and 107 deletions.
42 changes: 33 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
dotnet-version: |
6.0.x
8.0.x
dotnet-quality: 'preview'
- name: Setup PowerShell (Ubuntu)
if: matrix.os == 'ubuntu-latest'
run: |
Expand Down Expand Up @@ -87,8 +90,13 @@ jobs:
- name: Git checkout
uses: actions/checkout@v4
- name: Restore tools
shell: pwsh
run: |
dotnet tool restore
# Temporary workaround for bug in .NET 8 RC2 at https://github.com/dotnet/sdk/issues/35989
$tools = Get-Content ".config/dotnet-tools.json" | ConvertFrom-Json
foreach ($tool in $tools.tools.PsObject.Properties) {
& dotnet tool install $tool.Name --version $tool.Value.version
}
- name: Restore packages
run: |
dotnet restore
Expand Down Expand Up @@ -181,18 +189,26 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
dotnet-version: |
6.0.x
8.0.x
dotnet-quality: 'preview'
- name: Git checkout
uses: actions/checkout@v4
- name: Restore tools
shell: pwsh
run: |
dotnet tool restore
# Temporary workaround for bug in .NET 8 RC2 at https://github.com/dotnet/sdk/issues/35989
$tools = Get-Content ".config/dotnet-tools.json" | ConvertFrom-Json
foreach ($tool in $tools.tools.PsObject.Properties) {
& dotnet tool install $tool.Name --version $tool.Value.version
}
- name: InspectCode
shell: pwsh
run: |
$inspectCodeOutputPath = Join-Path $env:RUNNER_TEMP 'jetbrains-inspectcode-results.xml'
Write-Output "INSPECT_CODE_OUTPUT_PATH=$inspectCodeOutputPath" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
dotnet jb inspectcode JsonApiDotNetCore.sln --build --output="$inspectCodeOutputPath" --profile=WarningSeverities.DotSettings --properties:Configuration=Release --properties:ContinuousIntegrationBuild=false --severity=WARNING --verbosity=WARN -dsl=GlobalAll -dsl=GlobalPerProduct -dsl=SolutionPersonal -dsl=ProjectPersonal
dotnet jb inspectcode JsonApiDotNetCore.sln --build --dotnetcoresdk=$(dotnet --version) --output="$inspectCodeOutputPath" --profile=WarningSeverities.DotSettings --properties:Configuration=Release --properties:ContinuousIntegrationBuild=false --severity=WARNING --verbosity=WARN -dsl=GlobalAll -dsl=GlobalPerProduct -dsl=SolutionPersonal -dsl=ProjectPersonal
- name: Verify outcome
shell: pwsh
run: |
Expand Down Expand Up @@ -232,14 +248,22 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 6.0.x
dotnet-version: |
6.0.x
8.0.x
dotnet-quality: 'preview'
- name: Git checkout
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Restore tools
shell: pwsh
run: |
dotnet tool restore
# Temporary workaround for bug in .NET 8 RC2 at https://github.com/dotnet/sdk/issues/35989
$tools = Get-Content ".config/dotnet-tools.json" | ConvertFrom-Json
foreach ($tool in $tools.tools.PsObject.Properties) {
& dotnet tool install $tool.Name --version $tool.Value.version
}
- name: Restore packages
run: |
dotnet restore
Expand All @@ -253,13 +277,13 @@ jobs:
$baseCommitHash = git rev-parse HEAD~1
Write-Output "Running code cleanup on commit range $baseCommitHash..$headCommitHash in pull request."
dotnet regitlint -s JsonApiDotNetCore.sln --print-command --skip-tool-check --max-runs=5 --jb-profile="JADNC Full Cleanup" --jb --properties:Configuration=Release --jb --verbosity=WARN -f commits -a $headCommitHash -b $baseCommitHash --fail-on-diff --print-diff
dotnet regitlint -s JsonApiDotNetCore.sln --print-command --skip-tool-check --max-runs=5 --jb --dotnetcoresdk=$(dotnet --version) --jb-profile="JADNC Full Cleanup" --jb --properties:Configuration=Release --jb --verbosity=WARN -f commits -a $headCommitHash -b $baseCommitHash --fail-on-diff --print-diff
- name: CleanupCode (on branch)
if: github.event_name == 'push' || github.event_name == 'release'
shell: pwsh
run: |
Write-Output "Running code cleanup on all files."
dotnet regitlint -s JsonApiDotNetCore.sln --print-command --skip-tool-check --jb-profile="JADNC Full Cleanup" --jb --properties:Configuration=Release --jb --verbosity=WARN --fail-on-diff --print-diff
dotnet regitlint -s JsonApiDotNetCore.sln --print-command --skip-tool-check --jb --dotnetcoresdk=$(dotnet --version)--jb-profile="JADNC Full Cleanup" --jb --properties:Configuration=Release --jb --verbosity=WARN --fail-on-diff --print-diff
publish:
timeout-minutes: 60
Expand Down
34 changes: 6 additions & 28 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,21 @@
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
</PropertyGroup>

<!-- To be removed when stable .NET 8 version has been released. -->
<PropertyGroup>
<!-- Published dependencies (only update on major version change) -->
<TargetFrameworkName>net6.0</TargetFrameworkName>
<CodeAnalysisFrozenVersion>4.1.0</CodeAnalysisFrozenVersion>
<DemystifierFrozenVersion>0.4.1</DemystifierFrozenVersion>
<EntityFrameworkCoreFrozenVersion>6.0.0</EntityFrameworkCoreFrozenVersion>
<HumanizerFrozenVersion>2.14.1</HumanizerFrozenVersion>

<!-- Non-published dependencies (these are safe to update, won't cause a breaking change) -->
<AspNetCoreVersion>6.0.*</AspNetCoreVersion>
<BenchmarkDotNetVersion>0.13.*</BenchmarkDotNetVersion>
<BogusVersion>34.0.*</BogusVersion>
<CSharpGuidelinesAnalyzerVersion>3.8.*</CSharpGuidelinesAnalyzerVersion>
<CodeAnalysisVersion>4.7.*</CodeAnalysisVersion>
<CoverletVersion>6.0.*</CoverletVersion>
<DapperVersion>2.1.*</DapperVersion>
<DateOnlyTimeOnlyVersion>2.1.*</DateOnlyTimeOnlyVersion>
<EntityFrameworkCoreVersion>7.0.*</EntityFrameworkCoreVersion>
<FluentAssertionsVersion>6.12.*</FluentAssertionsVersion>
<GitHubActionsTestLoggerVersion>2.3.*</GitHubActionsTestLoggerVersion>
<InheritDocVersion>1.3.*</InheritDocVersion>
<JetBrainsAnnotationsVersion>2023.3.*</JetBrainsAnnotationsVersion>
<NpgsqlVersion>7.0.*</NpgsqlVersion>
<SourceLinkVersion>1.1.*</SourceLinkVersion>
<SystemTextJsonVersion>7.0.*</SystemTextJsonVersion>
<TestSdkVersion>17.8.*</TestSdkVersion>
<XunitVersion>2.5.*</XunitVersion>
<NoWarn>$(NoWarn);NU5104</NoWarn>
<SuppressNETCoreSdkPreviewMessage>true</SuppressNETCoreSdkPreviewMessage>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="JetBrains.Annotations" Version="$(JetBrainsAnnotationsVersion)" PrivateAssets="All" />
<PackageReference Include="CSharpGuidelinesAnalyzer" Version="$(CSharpGuidelinesAnalyzerVersion)" PrivateAssets="All" />
<PackageReference Include="JetBrains.Annotations" Version="2023.3.*" PrivateAssets="All" />
<PackageReference Include="CSharpGuidelinesAnalyzer" Version="3.8.*" PrivateAssets="All" />
<AdditionalFiles Include="$(MSBuildThisFileDirectory)CSharpGuidelinesAnalyzer.config" Visible="False" />
</ItemGroup>

<PropertyGroup>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable>
<WarnOnPackingNonPackableProject>false</WarnOnPackingNonPackableProject>
Expand Down
1 change: 1 addition & 0 deletions JsonApiDotNetCore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
CSharpGuidelinesAnalyzer.config = CSharpGuidelinesAnalyzer.config
Directory.Build.props = Directory.Build.props
tests.runsettings = tests.runsettings
package-versions.props = package-versions.props
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Examples", "Examples", "{026FBC6C-AF76-4568-9B87-EC73457899FD}"
Expand Down
13 changes: 13 additions & 0 deletions NuGet.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<!-- Temporary workaround for bug in Npgsql 8 RC2 at https://github.com/npgsql/npgsql/issues/5326 -->
<add key="Npgsql-nightly" value="https://www.myget.org/F/npgsql-vnext/api/v3/index.json" />

<!-- Temporary workaround until final 8.0 release of Pomelo.EntityFrameworkCore.MySql is available. -->
<add key="pomelo-nightly"
value="https://pkgs.dev.azure.com/pomelo-efcore/Pomelo.EntityFrameworkCore.MySql/_packaging/pomelo-efcore-public/nuget/v3/index.json" />

<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,21 @@ See also our [versioning policy](./VERSIONING_POLICY.md).
| JsonApiDotNetCore | Status | .NET | Entity Framework Core |
| ----------------- | ----------- | -------- | --------------------- |
| 3.x | Stable | Core 2.x | 2.x |
| 4.x | Stable | Core 3.1 | 3.1 |
| | | Core 3.1 | 5 |
| 4.x | Stable | Core 3.1 | 3.1, 5 |
| | | 5 | 5 |
| | | 6 | 5 |
| 5.0.0-5.0.2 | Stable | 6 | 6 |
| 5.0.3+ | Stable | 6 | 6 |
| | | 6 | 7 |
| 5.0.3-5.4.0 | Stable | 6 | 6, 7 |
| | | 7 | 7 |
| 5.5+ | Stable | 6 | 6, 7 |
| | | 7 | 7 |
| | | 8 | 8 |
| master | Preview | 6 | 6, 7 |
| | | 7 | 7 |
| | | 8 | 8 |
| openapi | Preview | 6 | 6, 7 |
| | | 7 | 7 |
| | | 8 | 8 |

## Contributing

Expand Down
4 changes: 3 additions & 1 deletion benchmarks/Benchmarks.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>$(TargetFrameworkName)</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ServerGarbageCollection>true</ServerGarbageCollection>
</PropertyGroup>

<Import Project="..\package-versions.props" />

<ItemGroup>
<ProjectReference Include="..\src\JsonApiDotNetCore\JsonApiDotNetCore.csproj" />
</ItemGroup>
Expand Down
6 changes: 3 additions & 3 deletions cleanupcode.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ if ($revision) {

if ($baseCommitHash -eq $headCommitHash) {
Write-Output "Running code cleanup on staged/unstaged files."
dotnet regitlint -s JsonApiDotNetCore.sln --print-command --skip-tool-check --max-runs=5 --jb-profile="JADNC Full Cleanup" --jb --properties:Configuration=Release --jb --verbosity=WARN -f staged,modified
dotnet regitlint -s JsonApiDotNetCore.sln --print-command --skip-tool-check --max-runs=5 --jb --dotnetcoresdk=$(dotnet --version) --jb-profile="JADNC Full Cleanup" --jb --properties:Configuration=Release --jb --verbosity=WARN -f staged,modified
VerifySuccessExitCode
}
else {
Write-Output "Running code cleanup on commit range $baseCommitHash..$headCommitHash, including staged/unstaged files."
dotnet regitlint -s JsonApiDotNetCore.sln --print-command --skip-tool-check --max-runs=5 --jb-profile="JADNC Full Cleanup" --jb --properties:Configuration=Release --jb --verbosity=WARN -f staged,modified,commits -a $headCommitHash -b $baseCommitHash
dotnet regitlint -s JsonApiDotNetCore.sln --print-command --skip-tool-check --max-runs=5 --jb --dotnetcoresdk=$(dotnet --version) --jb-profile="JADNC Full Cleanup" --jb --properties:Configuration=Release --jb --verbosity=WARN -f staged,modified,commits -a $headCommitHash -b $baseCommitHash
VerifySuccessExitCode
}
}
else {
Write-Output "Running code cleanup on all files."
dotnet regitlint -s JsonApiDotNetCore.sln --print-command --skip-tool-check --jb-profile="JADNC Full Cleanup" --jb --properties:Configuration=Release --jb --verbosity=WARN
dotnet regitlint -s JsonApiDotNetCore.sln --print-command --skip-tool-check --jb --dotnetcoresdk=$(dotnet --version) --jb-profile="JADNC Full Cleanup" --jb --properties:Configuration=Release --jb --verbosity=WARN
VerifySuccessExitCode
}
2 changes: 1 addition & 1 deletion docs/generate-examples.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function Start-WebServer {
Write-Output "Starting web server"
$startTimeUtc = Get-Date -AsUTC
$job = Start-Job -ScriptBlock {
dotnet run --project ..\src\Examples\GettingStarted\GettingStarted.csproj --configuration Debug --property:TreatWarningsAsErrors=True --urls=http://0.0.0.0:14141
dotnet run --project ..\src\Examples\GettingStarted\GettingStarted.csproj --framework net8.0 --configuration Debug --property:TreatWarningsAsErrors=True --urls=http://0.0.0.0:14141
}

$webProcessId = $null
Expand Down
2 changes: 1 addition & 1 deletion inspectcode.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if ($LastExitCode -ne 0) {

$outputPath = [System.IO.Path]::Combine([System.IO.Path]::GetTempPath(), 'jetbrains-inspectcode-results.xml')
$resultPath = [System.IO.Path]::Combine([System.IO.Path]::GetTempPath(), 'jetbrains-inspectcode-results.html')
dotnet jb inspectcode JsonApiDotNetCore.sln --build --output="$outputPath" --profile=WarningSeverities.DotSettings --properties:Configuration=Release --severity=WARNING --verbosity=WARN -dsl=GlobalAll -dsl=GlobalPerProduct -dsl=SolutionPersonal -dsl=ProjectPersonal
dotnet jb inspectcode JsonApiDotNetCore.sln --dotnetcoresdk=$(dotnet --version) --build --output="$outputPath" --profile=WarningSeverities.DotSettings --properties:Configuration=Release --severity=WARNING --verbosity=WARN -dsl=GlobalAll -dsl=GlobalPerProduct -dsl=SolutionPersonal -dsl=ProjectPersonal

if ($LastExitCode -ne 0) {
throw "Code inspection failed with exit code $LastExitCode"
Expand Down
46 changes: 46 additions & 0 deletions package-versions.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<Project>
<PropertyGroup>
<!-- Published dependencies (only update on major version change) -->
<CodeAnalysisFrozenVersion>4.1.0</CodeAnalysisFrozenVersion>
<DemystifierFrozenVersion>0.4.1</DemystifierFrozenVersion>
<HumanizerFrozenVersion>2.14.1</HumanizerFrozenVersion>

<!-- Non-published dependencies (these are safe to update, won't cause a breaking change) -->
<BenchmarkDotNetVersion>0.13.*</BenchmarkDotNetVersion>
<BogusVersion>34.0.*</BogusVersion>
<CSharpGuidelinesAnalyzerVersion>3.8.*</CSharpGuidelinesAnalyzerVersion>
<CodeAnalysisVersion>4.7.*</CodeAnalysisVersion>
<CoverletVersion>6.0.*</CoverletVersion>
<DapperVersion>2.1.*</DapperVersion>
<DateOnlyTimeOnlyVersion>2.1.*</DateOnlyTimeOnlyVersion>
<FluentAssertionsVersion>6.12.*</FluentAssertionsVersion>
<GitHubActionsTestLoggerVersion>2.3.*</GitHubActionsTestLoggerVersion>
<InheritDocVersion>1.3.*</InheritDocVersion>
<JetBrainsAnnotationsVersion>2023.2.*</JetBrainsAnnotationsVersion>
<SourceLinkVersion>1.1.*</SourceLinkVersion>
<TestSdkVersion>17.8.*</TestSdkVersion>
<XunitVersion>2.5.*</XunitVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'net8.0'">
<!-- Published dependencies (only update on major version change) -->
<EntityFrameworkCoreFrozenVersion>8.0.0-*</EntityFrameworkCoreFrozenVersion>

<!-- Non-published dependencies (these are safe to update, won't cause a breaking change) -->
<AspNetCoreVersion>8.0.0-*</AspNetCoreVersion>
<EntityFrameworkCoreVersion>8.0.0-*</EntityFrameworkCoreVersion>
<NpgsqlVersion>8.0.0-*</NpgsqlVersion>
<SystemTextJsonVersion>$(AspNetCoreVersion)</SystemTextJsonVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'net6.0'">
<!-- Published dependencies (only update on major version change) -->
<EntityFrameworkCoreFrozenVersion>6.0.0</EntityFrameworkCoreFrozenVersion>

<!-- Non-published dependencies (these are safe to update, won't cause a breaking change) -->
<AspNetCoreVersion>6.0.*</AspNetCoreVersion>
<EntityFrameworkCoreVersion>7.0.*</EntityFrameworkCoreVersion>
<NpgsqlVersion>7.0.*</NpgsqlVersion>
<SystemTextJsonVersion>7.0.*</SystemTextJsonVersion>
</PropertyGroup>
</Project>
4 changes: 3 additions & 1 deletion src/Examples/DapperExample/DapperExample.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>$(TargetFrameworkName)</TargetFramework>
<TargetFrameworks>net8.0;net6.0</TargetFrameworks>
</PropertyGroup>

<Import Project="..\..\..\package-versions.props" />

<ItemGroup>
<ProjectReference Include="..\..\JsonApiDotNetCore\JsonApiDotNetCore.csproj" />
<ProjectReference Include="..\..\JsonApiDotNetCore.SourceGenerators\JsonApiDotNetCore.SourceGenerators.csproj" OutputItemType="Analyzer"
Expand Down
13 changes: 6 additions & 7 deletions src/Examples/DapperExample/Definitions/TodoItemDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,20 @@
using JsonApiDotNetCore.Middleware;
using JsonApiDotNetCore.Queries.Expressions;
using JsonApiDotNetCore.Resources;
using Microsoft.AspNetCore.Authentication;

namespace DapperExample.Definitions;

[UsedImplicitly(ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature)]
public sealed class TodoItemDefinition : JsonApiResourceDefinition<TodoItem, long>
{
private readonly ISystemClock _systemClock;
private readonly IClock _clock;

public TodoItemDefinition(IResourceGraph resourceGraph, ISystemClock systemClock)
public TodoItemDefinition(IResourceGraph resourceGraph, IClock clock)
: base(resourceGraph)
{
ArgumentGuard.NotNull(systemClock);
ArgumentGuard.NotNull(clock);

_systemClock = systemClock;
_clock = clock;
}

public override SortExpression OnApplySort(SortExpression? existingSort)
Expand All @@ -41,11 +40,11 @@ public override Task OnWritingAsync(TodoItem resource, WriteOperationKind writeO
{
if (writeOperation == WriteOperationKind.CreateResource)
{
resource.CreatedAt = _systemClock.UtcNow;
resource.CreatedAt = _clock.UtcNow;
}
else if (writeOperation == WriteOperationKind.UpdateResource)
{
resource.LastModifiedAt = _systemClock.UtcNow;
resource.LastModifiedAt = _clock.UtcNow;
}

return Task.CompletedTask;
Expand Down
6 changes: 6 additions & 0 deletions src/Examples/DapperExample/IClock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace DapperExample;

public interface IClock
{
DateTimeOffset UtcNow { get; }
}
3 changes: 1 addition & 2 deletions src/Examples/DapperExample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using JsonApiDotNetCore.AtomicOperations;
using JsonApiDotNetCore.Configuration;
using JsonApiDotNetCore.Repositories;
using Microsoft.AspNetCore.Authentication;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.Extensions.DependencyInjection.Extensions;
Expand All @@ -18,7 +17,7 @@

// Add services to the container.

builder.Services.TryAddSingleton<ISystemClock, SystemClock>();
builder.Services.TryAddSingleton<IClock, SystemClock>();

DatabaseProvider databaseProvider = GetDatabaseProvider(builder.Configuration);
string? connectionString = builder.Configuration.GetConnectionString($"DapperExample{databaseProvider}");
Expand Down
6 changes: 6 additions & 0 deletions src/Examples/DapperExample/SystemClock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace DapperExample;

public sealed class SystemClock : IClock
{
public DateTimeOffset UtcNow => DateTimeOffset.UtcNow;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>$(TargetFrameworkName)</TargetFramework>
<TargetFrameworks>net8.0;net6.0</TargetFrameworks>
</PropertyGroup>

<Import Project="..\..\..\package-versions.props" />

<ItemGroup>
<ProjectReference Include="..\..\JsonApiDotNetCore\JsonApiDotNetCore.csproj" />
<ProjectReference Include="..\..\JsonApiDotNetCore.SourceGenerators\JsonApiDotNetCore.SourceGenerators.csproj" OutputItemType="Analyzer"
Expand Down
Loading

0 comments on commit 4a04823

Please sign in to comment.