Skip to content

Commit

Permalink
build: ⬆️ upgrade to .net 8 preview 5
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdihadeli committed Jul 13, 2023
1 parent e611026 commit 70775a6
Show file tree
Hide file tree
Showing 14 changed files with 122 additions and 141 deletions.
103 changes: 53 additions & 50 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,71 +23,74 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v3

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.x
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: "8.0.x"
dotnet-quality: "preview"

- name: Cache NuGet Packages
uses: actions/cache@v3
with:
key: vertical-template-nuget
path: ~/.nuget/packages
- name: Cache NuGet Packages
uses: actions/cache@v3
with:
key: vertical-template-nuget
path: ~/.nuget/packages

- name: Restore dependencies
run: dotnet restore Vertical.Slice.Template.sln
- name: Restore dependencies
run: dotnet restore Vertical.Slice.Template.sln

- name: Build
run: dotnet build Vertical.Slice.Template.sln -c Release --no-restore
- name: Build
run: dotnet build Vertical.Slice.Template.sln -c Release --no-restore

- name: Test
run: |
- name: Test
run: |
dotnet test Vertical.Slice.Template.sln -c Release --no-restore --no-build
# https://www.meziantou.net/publishing-a-nuget-package-following-best-practices-using-github.htm
create_nuget:
if: ${{ contains(fromJson('["main"]'), github.ref_name) || github.event_name == 'release' }}
needs: build

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.x

- name: Cache NuGet Packages
uses: actions/cache@v3
with:
key: vertical-template-nuget
path: ~/.nuget/packages

- name: Restore dependencies
run: dotnet restore Vertical.Slice.Template.sln

- name: Build
run: dotnet build Vertical.Slice.Template.sln -c Release --no-restore

# https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-pack
- name: Pack NuGet Package
run: dotnet pack Vertical.Slice.Template.sln --no-build --no-restore -c Release --output ${{ env.NuGetDirectory }}

# Publish the NuGet package as an artifact, so they can be used in the following jobs
- uses: actions/upload-artifact@v3
with:
name: nuget
if-no-files-found: error
retention-days: 7
path: ${{ env.NuGetDirectory }}/*.nupkg
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: "8.0.x"
dotnet-quality: "preview"

- name: Cache NuGet Packages
uses: actions/cache@v3
with:
key: vertical-template-nuget
path: ~/.nuget/packages

- name: Restore dependencies
run: dotnet restore Vertical.Slice.Template.sln

- name: Build
run: dotnet build Vertical.Slice.Template.sln -c Release --no-restore

# https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-pack
- name: Pack NuGet Package
run: dotnet pack Vertical.Slice.Template.sln --no-build --no-restore -c Release --output ${{ env.NuGetDirectory }}

# Publish the NuGet package as an artifact, so they can be used in the following jobs
- uses: actions/upload-artifact@v3
with:
name: nuget
if-no-files-found: error
retention-days: 7
path: ${{ env.NuGetDirectory }}/*.nupkg

validate_nuget:
if: ${{ contains(fromJson('["main"]'), github.ref_name) || github.event_name == 'release' }}

runs-on: ubuntu-latest
needs: [ create_nuget, build ]
needs: [create_nuget, build]
steps:
# Install the .NET SDK indicated in the global.json file
- name: Setup .NET
Expand Down Expand Up @@ -116,7 +119,7 @@ jobs:
# https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository
# You can update this logic if you want to manage releases differently
runs-on: ubuntu-latest
needs: [ validate_nuget, create_nuget ]
needs: [validate_nuget, create_nuget]
steps:
# Download the NuGet package created in the previous job
- uses: actions/download-artifact@v3
Expand All @@ -128,12 +131,12 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.x
dotnet-version: "8.0.x"
dotnet-quality: "preview"

# Publish all NuGet packages to NuGet.org
# Use --skip-duplicate to prevent errors if a package with the same version already exists.
# If you retry a failed workflow, already published packages will be skipped without error.
# https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-nuget-push
- name: Publish NuGet Package
run: dotnet nuget push ${{ env.NuGetDirectory }}/*.nupkg --skip-duplicate --source ${{ env.FEED_SOURCE }} --api-key ${{ env.FEED_API_KEY }}

2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sdk": {
"version": "7.0.200"
"version": "8.0.100-preview.5.23303.2"
}
}
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<PropertyGroup>
<LangVersion>latest</LangVersion>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
45 changes: 22 additions & 23 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<PackageVersion Include="CorrelationId" Version="3.0.1" />
<PackageVersion Include="MassTransit.Abstractions" Version="8.0.14" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.Google" Version="7.0.4" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.4" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.9" />
<PackageVersion Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
<PackageVersion Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="7.0.4" />
Expand All @@ -37,7 +37,7 @@
<PackageVersion Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="7.0.4" />
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Http.Polly" Version="7.0.4" />
<PackageVersion Include="Microsoft.Extensions.Http.Polly" Version="7.0.9" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
<PackageVersion Include="Microsoft.Extensions.Options" Version="7.0.1" />
Expand All @@ -48,8 +48,8 @@
<PackageVersion Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.0.64" />
<PackageVersion Include="Microsoft.DotNet.PlatformAbstractions" Version="3.1.6" />
<PackageVersion Include="Asp.Versioning.Http" Version="7.0.0" />
<PackageVersion Include="Asp.Versioning.Mvc" Version="7.0.0-preview.2" />
<PackageVersion Include="Asp.Versioning.Mvc.ApiExplorer" Version="7.0.0-preview.2" />
<PackageVersion Include="Asp.Versioning.Mvc" Version="7.0.0" />
<PackageVersion Include="Asp.Versioning.Mvc.ApiExplorer" Version="7.0.0" />
<PackageVersion Include="Asp.Versioning.Abstractions" Version="7.0.0" />
<PackageVersion Include="Microsoft.NET.Build.Containers" Version="0.2.7" />
<PackageVersion Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="7.0.4" />
Expand All @@ -76,30 +76,29 @@
<PackageVersion Include="prometheus-net.AspNetCore.HealthChecks" Version="7.0.0" />
</ItemGroup>
<ItemGroup>
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="7.0.5" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Abstractions" Version="7.0.5" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.5">
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="7.0.9" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.9">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageVersion>
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.5" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.5" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.5" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.5" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.9" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.9" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.9" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.9" />
<PackageVersion Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="7.0.4" />
<PackageVersion Include="EFCore.NamingConventions" Version="7.0.2" />
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.4" />
</ItemGroup>
<ItemGroup>
<PackageVersion Include="Serilog" Version="2.12.0" />
<PackageVersion Include="Serilog.AspNetCore" Version="6.0.1" />
<PackageVersion Include="Serilog" Version="3.0.1" />
<PackageVersion Include="Serilog.AspNetCore" Version="7.0.0" />
<PackageVersion Include="Serilog.Enrichers.CorrelationId" Version="3.0.1" />
<PackageVersion Include="Serilog.Enrichers.Environment" Version="2.2.0" />
<PackageVersion Include="Serilog.Enrichers.Span" Version="3.0.0" />
<PackageVersion Include="Serilog.Exceptions" Version="8.4.0" />
<PackageVersion Include="Serilog.Extensions.Hosting" Version="5.0.1" />
<PackageVersion Include="Serilog.Sinks.Elasticsearch" Version="8.4.1" />
<PackageVersion Include="Serilog.Formatting.Elasticsearch" Version="9.0.0" />
<PackageVersion Include="Serilog.Extensions.Hosting" Version="7.0.0" />
<PackageVersion Include="Serilog.Sinks.Elasticsearch" Version="9.0.3" />
<PackageVersion Include="Serilog.Formatting.Elasticsearch" Version="9.0.3" />
<PackageVersion Include="Serilog.Sinks.Async" Version="1.5.0" />
<PackageVersion Include="Serilog.Sinks.Console" Version="4.1.0" />
<PackageVersion Include="Serilog.Sinks.File" Version="5.0.0" />
Expand Down Expand Up @@ -150,18 +149,18 @@
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageVersion Include="Swashbuckle.AspNetCore.Swagger" Version="6.5.0" />
<PackageVersion Include="Swashbuckle.AspNetCore.Annotations" Version="6.5.0" />
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="7.0.4" />
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="7.0.9" />
<PackageVersion Include="NSwag.ApiDescription.Client" Version="13.0.5" />
</ItemGroup>
<ItemGroup>
<PackageVersion Include="AutoMapper" Version="12.0.1" />
<PackageVersion Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.0" />
<PackageVersion Include="MediatR" Version="12.0.1" />
<PackageVersion Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
<PackageVersion Include="MediatR" Version="12.1.1" />
</ItemGroup>
<ItemGroup>
<PackageVersion Include="Bogus" Version="34.0.2" />
<PackageVersion Include="AutoBogus" Version="2.13.1" />
<PackageVersion Include="Dapper" Version="2.0.123" />
<PackageVersion Include="Dapper" Version="2.0.143" />
<PackageVersion Include="DotNetEnv" Version="2.5.0" />
<PackageVersion Include="FluentMigrator.Extensions.Postgres" Version="3.3.2" />
<PackageVersion Include="FluentMigrator.Runner.Postgres" Version="3.3.2" />
Expand Down Expand Up @@ -203,9 +202,9 @@
<PackageVersion Include="Duende.IdentityServer.EntityFramework" Version="6.2.3" />
</ItemGroup>
<ItemGroup>
<PackageVersion Include="EasyCaching.Serialization.MessagePack" Version="1.8.0" />
<PackageVersion Include="EasyCaching.Serialization.Json" Version="1.8.0" />
<PackageVersion Include="EasyCaching.Redis" Version="1.8.0" />
<PackageVersion Include="EasyCaching.Serialization.MessagePack" Version="1.9.0" />
<PackageVersion Include="EasyCaching.Serialization.Json" Version="1.9.0" />
<PackageVersion Include="EasyCaching.Redis" Version="1.9.0" />
<PackageVersion Include="EasyCaching.InMemory" Version="1.8.0" />
<PackageVersion Include="EasyCaching.Core" Version="1.9.0" />
</ItemGroup>
Expand Down
28 changes: 28 additions & 0 deletions src/Vertical.Slice.Template.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
using Vertical.Slice.Template;
using Vertical.Slice.Template.Shared;
using Vertical.Slice.Template.Shared.Core.Extensions.ServiceCollectionsExtensions;
using Vertical.Slice.Template.Shared.Logging;
using Vertical.Slice.Template.Shared.Swagger;
using Vertical.Slice.Template.Shared.Web.Minimal.Extensions;
using Vertical.Slice.Template.Shared.Web.ProblemDetail.Middlewares.CaptureExceptionMiddleware;

// https://github.com/serilog/serilog-aspnetcore#two-stage-initialization
Log.Logger = new LoggerConfiguration().MinimumLevel
Expand All @@ -17,6 +19,8 @@
{
var builder = WebApplication.CreateBuilder(args);

builder.AddCustomSerilog();

builder.Host.UseDefaultServiceProvider(
(context, options) =>
{
Expand Down Expand Up @@ -52,6 +56,30 @@
);
}

// https://learn.microsoft.com/en-us/aspnet/core/fundamentals/error-handling
// Does nothing if a response body has already been provided. when our next `DeveloperExceptionMiddleware` is written response for exception (in dev mode) when we back to `ExceptionHandlerMiddlewareImpl` because `context.Response.HasStarted` it doesn't do anything
// By default `ExceptionHandlerMiddlewareImpl` middleware register original exceptions with `IExceptionHandlerFeature` feature, we don't have this in `DeveloperExceptionPageMiddleware` and we should handle it with a middleware like `CaptureExceptionMiddleware`
// Just for handling exceptions in production mode
// https://github.com/dotnet/aspnetcore/pull/26567
app.UseExceptionHandler(options: new ExceptionHandlerOptions { AllowStatusCode404Response = true });

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment() || app.Environment.IsEnvironment("test"))
{
// https://learn.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis/handle-errrors
app.UseDeveloperExceptionPage();

// https://github.com/dotnet/aspnetcore/issues/4765
// https://github.com/dotnet/aspnetcore/pull/47760
// .net 8 will add `IExceptionHandlerFeature`in `DisplayExceptionContent` and `SetExceptionHandlerFeatures` methods `DeveloperExceptionPageMiddlewareImpl` class, exact functionality of CaptureException
// bet before .net 8 preview 5 we should add `IExceptionHandlerFeature` manually with our `UseCaptureException`
// app.UseCaptureException();
}

// this middleware should be first middleware
// request logging just log in information level and above as default
app.UseSerilogRequestLogging();

await app.UseCatalogs();

app.MapCatalogsEndpoints();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.Extensions.Configuration;

namespace Vertical.Slice.Template.Shared.Web.Extensions;
namespace Vertical.Slice.Template.Shared.Core.Extensions;

/// <summary>
/// Static helper class for <see cref="IConfiguration"/>.
Expand Down
1 change: 1 addition & 0 deletions src/Vertical.Slice.Template.Shared/Logging/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Serilog.Formatting.Elasticsearch;
using Serilog.Sinks.Elasticsearch;
using Serilog.Sinks.Grafana.Loki;
using Vertical.Slice.Template.Shared.Core.Extensions;
using Vertical.Slice.Template.Shared.Web.Extensions;

namespace Vertical.Slice.Template.Shared.Logging;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ public static partial class WebApplicationBuilderExtensions
{
public static WebApplicationBuilder AddInfrastructures(this WebApplicationBuilder builder)
{
builder.AddCustomSerilog();

builder.Services.AddCore();

// https://learn.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis/security
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,6 @@ public static partial class WebApplicationExtensions
{
public static Task UseInfrastructure(this WebApplication app)
{
// https://learn.microsoft.com/en-us/aspnet/core/fundamentals/error-handling
// Does nothing if a response body has already been provided. when our next `DeveloperExceptionMiddleware` is written response for exception (in dev mode) when we back to `ExceptionHandlerMiddlewareImpl` because `context.Response.HasStarted` it doesn't do anything
// By default `ExceptionHandlerMiddlewareImpl` middleware register original exceptions with `IExceptionHandlerFeature` feature, we don't have this in `DeveloperExceptionPageMiddleware` and we should handle it with a middleware like `CaptureExceptionMiddleware`
// Just for handling exceptions in production mode
// https://github.com/dotnet/aspnetcore/pull/26567
app.UseExceptionHandler(options: new ExceptionHandlerOptions { AllowStatusCode404Response = true });

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment() || app.Environment.IsEnvironment("test"))
{
// https://learn.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis/handle-errrors
app.UseDeveloperExceptionPage();

// https://github.com/dotnet/aspnetcore/issues/4765
// https://github.com/dotnet/aspnetcore/pull/47760
// .net 8 will add `IExceptionHandlerFeature`in `DisplayExceptionContent` and `SetExceptionHandlerFeatures` methods `DeveloperExceptionPageMiddlewareImpl` class, exact functionality of CaptureException
// bet before .net 8 preview 5 we should add `IExceptionHandlerFeature` manually with our `UseCaptureException`
app.UseCaptureException();
}

// this middleware should be first middleware
// request logging just log in information level and above as default
app.UseSerilogRequestLogging();

app.UseCustomCors();

// https://learn.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis/security
Expand Down
2 changes: 1 addition & 1 deletion tests/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!-- https://docs.microsoft.com/en-us/visualstudio/msbuild/customize-your-build -->
<Project>
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
Loading

0 comments on commit 70775a6

Please sign in to comment.