Skip to content

Commit

Permalink
refactor(all): migrate to .net 8 (#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaume-chervet authored Jan 23, 2024
1 parent 630bd8d commit 5cc748f
Show file tree
Hide file tree
Showing 31 changed files with 196 additions and 256 deletions.
64 changes: 53 additions & 11 deletions .github/workflows/ecotag-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,70 @@ on:
branches: [ master ]
pull_request:
branches: [ master ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
types: [opened, synchronize, reopened]

jobs:

build-windows:

sonarcloud:
name: SonarCloud
environment: ml-cli
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'zulu' # Alternative distribution options are available.
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
path: ~\sonar\cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache SonarCloud scanner
id: cache-sonar-scanner
uses: actions/cache@v3
with:
path: .\.sonar\scanner
key: ${{ runner.os }}-sonar-scanner
restore-keys: ${{ runner.os }}-sonar-scanner
- uses: actions/setup-dotnet@v3
with:
fetch-depth: 0
global-json-file: global.json
- name: Install SonarCloud scanner
if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'
shell: powershell
run: |
New-Item -Path .\.sonar\scanner -ItemType Directory
dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner
- uses: actions/setup-node@v2
with:
node-version: '18'
- name: npm install
run: npm install
working-directory: src/Ecotag/ClientApp
- name: npm test
run: npm test -- --runInBand --coverage --watchAll=false
working-directory: src/Ecotag/ClientApp
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
shell: powershell
run: |
.\.sonar\scanner\dotnet-sonarscanner begin /k:"AxaGuilDEv_ml-cli" /o:"axaguildev" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.vscoveragexml.reportsPaths=coverage.xml /d:sonar.exclusions="**/*.spec.js,**/*.stories.js,**/ClientApp/src/Toolkit/**,**/ClientApp/coverage/**,Scripts/**,**/*.scss,**/__snapshots__/**,**/*Sould.cs,**/*[Tt]ests.cs,**/node_modules/**,**/ClientApp/build-local/**,**/ClientApp/build-server/**,**/ClientApp/.storybook/**,**/ClientApp/storybook-static/**,**/obj/**,**/__mocks__/**,**/ClientApp/src/serviceWorker.ts,**/ClientApp/public/**" /d:sonar.javascript.lcov.reportPaths="**/ClientApp/coverage/lcov.info"
dotnet tool install --global dotnet-coverage
dotnet-coverage collect "dotnet test" -f xml -o "coverage.xml"
.\.sonar\scanner\dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
- uses: actions/setup-dotnet@v3
- run: dotnet test

build-linux:
environment: ml-cli
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-node@v2
Expand Down
8 changes: 3 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build

ENV NODE_VERSION 18.2.0
ENV NODE_DOWNLOAD_SHA 73d3f98e96e098587c2154dcaa82a6469a510e89a4881663dc4c86985acf245e
Expand All @@ -21,11 +21,9 @@ COPY ./src/Ecotag/ClientApp/public/environment.docker.json ./src/Ecotag/ClientAp
COPY ./src/Ecotag/ClientApp/public/OidcTrustedDomains.docker.js ./src/Ecotag/ClientApp/public/OidcTrustedDomains.js
RUN dotnet publish "./src/Ecotag/Ecotag.csproj" -c Release -r linux-x64 --self-contained=true /p:PublishSingleFile=true /p:PublishTrimmed=true /p:PublishReadyToRun=true -o /publish

FROM mcr.microsoft.com/dotnet/runtime-deps:7.0 AS final

RUN apt update \
&& apt-get install -y libreoffice
FROM mcr.microsoft.com/dotnet/runtime-deps:8.0 AS final

RUN apt update && apt-get install -y libreoffice
RUN libreoffice --version
RUN sed -i 's/UserInstallation/#UserInstallation/' /usr/lib/libreoffice/program/bootstraprc

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ services:
image: "axaguildev/ecotag:latest"
#build:
# context: .
# dockerfile: ./Dockerfile
# dockerfile: ./Dockerfile
environment:
ASPNETCORE_ENVIRONMENT: Docker
ports:
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "7.0.100",
"version": "8.0.101",
"rollForward": "latestMajor",
"allowPrerelease": false
}
Expand Down
26 changes: 13 additions & 13 deletions src/Ecotag/ClientApp/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Ecotag/ClientApp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.0.0",
"private": true,
"dependencies": {
"@axa-fr/react-oidc": "7.3.4",
"@axa-fr/react-oidc": "7.9.3",
"@axa-fr/react-toolkit-all": "1.4.1",
"@microsoft/applicationinsights-web": "2.8.6",
"@monaco-editor/react": "4.2.1",
Expand Down
28 changes: 12 additions & 16 deletions src/Ecotag/Ecotag.csproj
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Version>1.0.0</Version>
<RuntimeIdentifiers>linux-x64;rhel-x64;osx-x64;win10-x64</RuntimeIdentifiers>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
<TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
<IsPackable>false</IsPackable>
<SpaRoot>ClientApp\</SpaRoot>
<DefaultItemExcludes>$(DefaultItemExcludes);$(SpaRoot)node_modules\**</DefaultItemExcludes>
<RootNamespace>AxaGuilDEv.Ecotag</RootNamespace>
<JsonSerializerIsReflectionEnabledByDefault>true</JsonSerializerIsReflectionEnabledByDefault>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.6.0" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.11.0" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="7.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.0" />
<PackageReference Include="Azure.Identity" Version="1.10.4" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.19.1" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="8.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.CommandLineUtils" Version="1.1.1" />
<PackageReference Include="swashbuckle.aspnetcore" Version="6.4.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.14.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.0" />
<PackageReference Include="Azure.Extensions.AspNetCore.Configuration.Secrets" Version="1.2.2" />
<PackageReference Include="Serilog.AspNetCore" Version="5.0.0" />
<PackageReference Include="Serilog.Sinks.ApplicationInsights" Version="3.1.0" />
<PackageReference Include="Serilog.Sinks.Async" Version="1.5.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.1" />
<PackageReference Include="swashbuckle.aspnetcore" Version="6.5.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.22.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.1" />
<PackageReference Include="Azure.Extensions.AspNetCore.Configuration.Secrets" Version="1.3.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 0 additions & 2 deletions src/Ecotag/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Serilog;

namespace AxaGuilDEv.Ecotag;

Expand Down Expand Up @@ -121,7 +120,6 @@ private static IHostBuilder CreateHostBuilderServer(string[] args)
var keyVaultConfig = keyVaultConfigBuilder.Build();
config.AddConfiguration(keyVaultConfig);
})
.UseSerilog((context, logger) => { logger.ReadFrom.Configuration(context.Configuration); })
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseContentRoot(Directory.GetCurrentDirectory());
Expand Down
6 changes: 3 additions & 3 deletions src/Ecotag/Server/Audits/Queue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ public class Subscriber

public class Queue : IQueue
{
private readonly IList<Subscriber> subscribers = new List<Subscriber>();
private readonly IList<Subscriber> _subscribers = new List<Subscriber>();

public async Task PublishAsync(string type, object message)
{
var messageJson = JsonSerializer.Serialize(message);
foreach (var subscriber in subscribers)
foreach (var subscriber in _subscribers)
if (subscriber.Type == type)
await subscriber.CallbackAsync(type, messageJson);
}
Expand All @@ -30,6 +30,6 @@ public void Subscribe(string type, Func<string, string, Task<bool>> func)
Type = type,
CallbackAsync = func
};
subscribers.Add(subscriber);
_subscribers.Add(subscriber);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ await _datasetsContext.Annotations.FirstOrDefaultAsync(a =>
}

public async Task<List<ExportAnnotation>> GetAnnotationsByProjectIdAndDatasetIdAsync(string projectId,
string datasetId)
string datasetId, JsonSerializerOptions? options = null)

Check warning on line 230 in src/Ecotag/Server/Datasets/Database/Annotations/AnnotationsRepository.cs

View workflow job for this annotation

GitHub Actions / build-linux

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 230 in src/Ecotag/Server/Datasets/Database/Annotations/AnnotationsRepository.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 230 in src/Ecotag/Server/Datasets/Database/Annotations/AnnotationsRepository.cs

View workflow job for this annotation

GitHub Actions / build-linux

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 230 in src/Ecotag/Server/Datasets/Database/Annotations/AnnotationsRepository.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
{
var result = new List<ExportAnnotation>();
var fileDataModels = await _datasetsContext.Files.AsNoTracking()
Expand All @@ -242,7 +242,7 @@ public async Task<List<ExportAnnotation>> GetAnnotationsByProjectIdAndDatasetIdA
FileName = fileDataModel.Name,
NameIdentifier = annotation.CreatorNameIdentifier,
CreateDate = annotation.TimeStamp,
Annotation = JsonSerializer.Deserialize<object>(annotation.ExpectedOutput)
Annotation = JsonSerializer.Deserialize<object>(annotation.ExpectedOutput, options)
});
result.AddRange(fileAnnotations);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Ecotag/Server/ErrorLoggingMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public async Task Invoke(HttpContext context, ILogger<ErrorLoggingMiddleware> lo
}
catch (Exception e)
{
logger.LogError(e, $"The following error happened: {e.Message}");
logger.LogError(e, "The following error happened: {EMessage}", e.Message);
if (!context.Response.HasStarted)
{
context.Response.StatusCode = 500;
Expand Down
9 changes: 7 additions & 2 deletions src/Ecotag/Server/Groups/Cmd/UpdateGroupCmd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using AxaGuilDEv.Ecotag.Server.Audits;
using AxaGuilDEv.Ecotag.Server.Groups.Database.Group;
Expand Down Expand Up @@ -72,7 +73,7 @@ public async Task<ResultWithError<string, ErrorResult>> ExecuteAsync(UpdateGroup
Id = updateGroupInput.Id,
UpdateDate = updateDate,
UserIds = updateGroupInput.UserIds
})
}, GroupUpdateAuditSerializerContext.Default.GroupUpdateAudit)
});

return commandResult;
Expand All @@ -84,4 +85,8 @@ public record GroupUpdateAudit
public string Id { get; set; }
public List<string> UserIds { get; set; }
public long UpdateDate { get; set; }
}
}

[JsonSerializable(typeof(GroupUpdateAudit))]
[JsonSourceGenerationOptions(WriteIndented = false, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)]
public partial class GroupUpdateAuditSerializerContext : JsonSerializerContext;
12 changes: 6 additions & 6 deletions src/Ecotag/Server/Groups/Oidc/OidcConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

namespace AxaGuilDEv.Ecotag.Server.Groups.Oidc;

[ExcludeFromCodeCoverage]
public class OidcConfiguration
{
[JsonPropertyName("userinfo_endpoint")]
public string UserinfoEndpoint { get; set; }
}
[method: JsonConstructorAttribute]
public record OidcConfiguration(string userinfo_endpoint);

[JsonSerializable(typeof(OidcConfiguration))]
[JsonSourceGenerationOptions(WriteIndented = false, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)]
public partial class OidcConfigurationSerializerContext : JsonSerializerContext;
10 changes: 6 additions & 4 deletions src/Ecotag/Server/Groups/Oidc/OidcUserInfo.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System.Diagnostics.CodeAnalysis;
using System.Text.Json.Serialization;

namespace AxaGuilDEv.Ecotag.Server.Groups.Oidc;

[ExcludeFromCodeCoverage]
public class OidcUserInfo
{
public string Email { get; set; }
}
public record OidcUserInfo(string Email);

[JsonSerializable(typeof(OidcUserInfo))]
[JsonSourceGenerationOptions(WriteIndented = false, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, PropertyNameCaseInsensitive = true)]
public partial class OidcUserInfoSerializerContext : JsonSerializerContext;
13 changes: 3 additions & 10 deletions src/Ecotag/Server/Groups/Oidc/OidcUserInfoService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,12 @@ public async Task<OidcUserInfo> GetUserEmailAsync(string accessToken)
{
var oidcConfiguration = await GetOidcConfigurationAsync();
var request = new HttpRequestMessage(HttpMethod.Get,
oidcConfiguration.UserinfoEndpoint);
oidcConfiguration.userinfo_endpoint);
request.Headers.Add("authorization", $"Bearer {accessToken}");
var client = _clientFactory.CreateClient(NamedHttpClients.ProxiedClient);
var response = await client.SendAsync(request);
await using var responseStream = await response.Content.ReadAsStreamAsync();
var serializeOptions = new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
WriteIndented = true
};
var userInfo = await JsonSerializer.DeserializeAsync
<OidcUserInfo>(responseStream, serializeOptions);
var userInfo = await JsonSerializer.DeserializeAsync(responseStream, OidcUserInfoSerializerContext.Default.OidcUserInfo);
return userInfo;
}

Expand All @@ -48,8 +42,7 @@ private async Task<OidcConfiguration> GetOidcConfigurationAsync()
var client = _clientFactory.CreateClient(NamedHttpClients.ProxiedClient);
var response = await client.SendAsync(request);
await using var responseStream = await response.Content.ReadAsStreamAsync();
var userInfo = await JsonSerializer.DeserializeAsync
<OidcConfiguration>(responseStream);
var userInfo = await JsonSerializer.DeserializeAsync(responseStream, OidcConfigurationSerializerContext.Default.OidcConfiguration);
return userInfo;
}
}
1 change: 1 addition & 0 deletions src/Ecotag/Server/Projects/Cmd/Annotations/ExportCmd.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using AxaGuilDEv.Ecotag.Server.Datasets.Database;
using AxaGuilDEv.Ecotag.Server.Datasets.Database.Annotations;
Expand Down
Loading

0 comments on commit 5cc748f

Please sign in to comment.