From 7eb421a6718b1b55f826df0d84fd29fe3d858b09 Mon Sep 17 00:00:00 2001 From: "Wenzel, Toni" Date: Tue, 1 Oct 2024 15:15:39 +0200 Subject: [PATCH 1/4] Update project --- ...sions.Security.Txt.IntegrationTests.csproj | 24 +- .../DemoWebApplicationTests.cs | 14 +- build.cake | 215 ++++++++++-------- .../DemoWebApplication.csproj | 2 +- src/CHG.Extensions.Security.Txt.csproj | 19 +- src/InvalidSecurityInformationException.cs | 9 +- .../CHG.Extensions.Security.Txt.Tests.csproj | 18 +- 7 files changed, 160 insertions(+), 141 deletions(-) diff --git a/CHG.Extensions.Security.Txt.IntegrationTests/CHG.Extensions.Security.Txt.IntegrationTests.csproj b/CHG.Extensions.Security.Txt.IntegrationTests/CHG.Extensions.Security.Txt.IntegrationTests.csproj index e71b3bb..83b4e4b 100644 --- a/CHG.Extensions.Security.Txt.IntegrationTests/CHG.Extensions.Security.Txt.IntegrationTests.csproj +++ b/CHG.Extensions.Security.Txt.IntegrationTests/CHG.Extensions.Security.Txt.IntegrationTests.csproj @@ -1,7 +1,7 @@ - + - net7.0 + net8.0 enable enable @@ -10,13 +10,19 @@ - - - - - - - + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/CHG.Extensions.Security.Txt.IntegrationTests/DemoWebApplicationTests.cs b/CHG.Extensions.Security.Txt.IntegrationTests/DemoWebApplicationTests.cs index c94a4a4..89af99c 100644 --- a/CHG.Extensions.Security.Txt.IntegrationTests/DemoWebApplicationTests.cs +++ b/CHG.Extensions.Security.Txt.IntegrationTests/DemoWebApplicationTests.cs @@ -1,5 +1,5 @@ -using NUnit.Framework; using FluentAssertions; +using NUnit.Framework; namespace CHG.Extensions.Security.Txt.IntegrationTests; @@ -20,6 +20,18 @@ public void Setup() _httpClient = _webApplicationFactory.CreateClient(); } + [OneTimeTearDown] + public void ClassTearDown() + { + _webApplicationFactory?.Dispose(); + } + + [TearDown] + public void TearDown() + { + _httpClient?.Dispose(); + } + [Test] public async Task Check_WellKnown_Path_Redirect() { diff --git a/build.cake b/build.cake index 52b16c7..2988f46 100644 --- a/build.cake +++ b/build.cake @@ -1,8 +1,8 @@ -#tool "dotnet:?package=GitVersion.Tool&version=5.12.0" -#tool "nuget:?package=NuGet.CommandLine&version=6.4.0" -#tool "nuget:?package=dotnet-sonarscanner&version=5.11.0" +#tool "dotnet:?package=GitVersion.Tool&version=6.0.2" +#tool "nuget:?package=NuGet.CommandLine&version=6.11.0" +#tool "nuget:?package=dotnet-sonarscanner&version=9.0.0" -#addin "nuget:?package=Cake.Sonar&version=1.1.31" +#addin "nuget:?package=Cake.Sonar&version=1.1.33" var target = Argument("target", "Default"); var sonarLogin = Argument("sonarLogin", EnvironmentVariable("SONAR_LOGIN") ?? ""); @@ -38,117 +38,130 @@ var runSonar = !string.IsNullOrWhiteSpace(sonarLogin); Setup(context => { - Information($"Local build: {isLocalBuild}"); - Information($"Master branch: {isMasterBranch}"); - Information($"Pull request: {isPullRequest}"); - Information($"Run sonar: {runSonar}"); - Information($"ref: {BuildSystem.GitHubActions.Environment.Workflow.Ref}"); + Information($"Local build: {isLocalBuild}"); + Information($"Master branch: {isMasterBranch}"); + Information($"Pull request: {isPullRequest}"); + Information($"Run sonar: {runSonar}"); + Information($"ref: {BuildSystem.GitHubActions.Environment.Workflow.Ref}"); }); Task("Clean") - .Description("Removes the output directory") - .Does(() => { - - EnsureDirectoryDoesNotExist(outputDir, new DeleteDirectorySettings { - Recursive = true, - Force = true - }); - CreateDirectory(outputDir); -}); + .Description("Removes the output directory") + .Does(() => + { + + EnsureDirectoryDoesNotExist(outputDir, new DeleteDirectorySettings + { + Recursive = true, + Force = true + }); + CreateDirectory(outputDir); + }); GitVersion versionInfo = null; Task("Version") - .Description("Retrieves the current version from the git repository") - .Does(() => { - - versionInfo = GitVersion(new GitVersionSettings { - UpdateAssemblyInfo = false - }); - - Information("Version: "+ versionInfo.FullSemVer); - }); + .Description("Retrieves the current version from the git repository") + .Does(() => + { + + versionInfo = GitVersion(new GitVersionSettings + { + UpdateAssemblyInfo = false + }); + + Information("Version: " + versionInfo.FullSemVer); + }); Task("Build") - .IsDependentOn("Clean") - .IsDependentOn("Version") - .Does(() => { - - var msBuildSettings = new DotNetMSBuildSettings() - { - Version = versionInfo.AssemblySemVer, - InformationalVersion = versionInfo.InformationalVersion, - PackageVersion = versionInfo.NuGetVersionV2 - }.WithProperty("PackageOutputPath", outputDirNuget.FullPath); - - var settings = new DotNetBuildSettings { - Configuration = "Release", - MSBuildSettings = msBuildSettings - }; - - DotNetBuild(solution, settings); - }); + .IsDependentOn("Clean") + .IsDependentOn("Version") + .Does(() => + { + + var msBuildSettings = new DotNetMSBuildSettings() + { + Version = versionInfo.AssemblySemVer, + InformationalVersion = versionInfo.InformationalVersion, + PackageVersion = versionInfo.NuGetVersionV2 + }.WithProperty("PackageOutputPath", outputDirNuget.FullPath); + + var settings = new DotNetBuildSettings + { + Configuration = "Release", + MSBuildSettings = msBuildSettings + }; + + DotNetBuild(solution, settings); + }); Task("Test") - .IsDependentOn("Build") - .Does(() => - { - - var settings = new DotNetTestSettings { - Configuration = "Release", - Loggers = new[]{"trx;"}, - ResultsDirectory = outputDirTests, - Collectors = new[] {"XPlat Code Coverage"}, - ArgumentCustomization = a => a.Append("-- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover"), - NoBuild = true - }; - - DotNetTest(solution, settings); - }); - + .IsDependentOn("Build") + .Does(() => + { + + var settings = new DotNetTestSettings + { + Configuration = "Release", + Loggers = new[] { "trx;" }, + ResultsDirectory = outputDirTests, + Collectors = new[] { "XPlat Code Coverage" }, + ArgumentCustomization = a => a.Append("-- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover"), + NoBuild = true + }; + + DotNetTest(solution, settings); + }); + Task("SonarBegin") - .WithCriteria(runSonar) - .Does(() => { - SonarBegin(new SonarBeginSettings { - Key = sonarProjectKey, - Url = sonarUrl, - Organization = sonarOrganization, - Login = sonarLogin, - UseCoreClr = true, - VsTestReportsPath = testResultsPath.ToString(), - OpenCoverReportsPath = codeCoverageResultFilePath.ToString() - }); - }); + .WithCriteria(runSonar) + .Does(() => + { + SonarBegin(new SonarBeginSettings + { + Key = sonarProjectKey, + Url = sonarUrl, + Organization = sonarOrganization, + Login = sonarLogin, + UseCoreClr = true, + VsTestReportsPath = testResultsPath.ToString(), + OpenCoverReportsPath = codeCoverageResultFilePath.ToString() + }); + }); Task("SonarEnd") - .WithCriteria(runSonar) - .Does(() => { - SonarEnd(new SonarEndSettings { - Login = sonarLogin - }); - }); - + .WithCriteria(runSonar) + .Does(() => + { + SonarEnd(new SonarEndSettings + { + Login = sonarLogin + }); + }); + Task("Publish") - .WithCriteria(!isPullRequest && isMasterBranch) - .IsDependentOn("Test") - .IsDependentOn("Version") - .Description("Pushes the created NuGet packages to nuget.org") - .Does(() => { - - // Get the paths to the packages. - var packages = GetFiles(outputDirNuget + "*.nupkg"); - - // Push the package and symbols - NuGetPush(packages, new NuGetPushSettings { - Source = nugetPublishFeed, - ApiKey = nugetApiKey, - SkipDuplicate = true - }); - }); - + .WithCriteria(!isPullRequest && isMasterBranch) + .IsDependentOn("Test") + .IsDependentOn("Version") + .Description("Pushes the created NuGet packages to nuget.org") + .Does(() => + { + + // Get the paths to the packages. + var packages = GetFiles(outputDirNuget + "*.nupkg"); + + // Push the package and symbols + NuGetPush(packages, new NuGetPushSettings + { + Source = nugetPublishFeed, + ApiKey = nugetApiKey, + SkipDuplicate = true + }); + }); + Task("Default") - .IsDependentOn("SonarBegin") - .IsDependentOn("Test") - .IsDependentOn("SonarEnd") - .IsDependentOn("Publish"); + .IsDependentOn("SonarBegin") + .IsDependentOn("Test") + .IsDependentOn("SonarEnd") + .IsDependentOn("Publish"); RunTarget(target); diff --git a/samples/DemoWebApplication/DemoWebApplication.csproj b/samples/DemoWebApplication/DemoWebApplication.csproj index 47bbdc9..84c14d4 100644 --- a/samples/DemoWebApplication/DemoWebApplication.csproj +++ b/samples/DemoWebApplication/DemoWebApplication.csproj @@ -1,7 +1,7 @@  - net7.0 + net8.0 {3FEF71C2-52D6-46D4-AC08-9752D8BD3B12} diff --git a/src/CHG.Extensions.Security.Txt.csproj b/src/CHG.Extensions.Security.Txt.csproj index 56b4d39..e40fa1f 100644 --- a/src/CHG.Extensions.Security.Txt.csproj +++ b/src/CHG.Extensions.Security.Txt.csproj @@ -1,7 +1,7 @@  - netstandard2.0;net6.0;net7.0 + net8.0 true CHG-MERIDIAN AG Toni Wenzel @@ -20,31 +20,26 @@ {84FEB7F6-A851-4AB6-AA0C-010F23BC6804} true snupkg + README.md - + - - - - - - - - + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers - + + diff --git a/src/InvalidSecurityInformationException.cs b/src/InvalidSecurityInformationException.cs index 7013f2e..f6a9ce5 100644 --- a/src/InvalidSecurityInformationException.cs +++ b/src/InvalidSecurityInformationException.cs @@ -1,8 +1,5 @@ -using System.Runtime.Serialization; +namespace CHG.Extensions.Security.Txt; -namespace CHG.Extensions.Security.Txt; - -[Serializable] public class InvalidSecurityInformationException : Exception { public InvalidSecurityInformationException() @@ -19,8 +16,4 @@ public InvalidSecurityInformationException(string message, Exception inner) { } - protected InvalidSecurityInformationException(SerializationInfo info, StreamingContext context) - : base(info, context) - { - } } diff --git a/tests/CHG.Extensions.Security.Txt.Tests/CHG.Extensions.Security.Txt.Tests.csproj b/tests/CHG.Extensions.Security.Txt.Tests/CHG.Extensions.Security.Txt.Tests.csproj index dc9de69..7b5237d 100644 --- a/tests/CHG.Extensions.Security.Txt.Tests/CHG.Extensions.Security.Txt.Tests.csproj +++ b/tests/CHG.Extensions.Security.Txt.Tests/CHG.Extensions.Security.Txt.Tests.csproj @@ -1,23 +1,23 @@  - net471;net6.0;net7.0 + net8.0 false - {7BDE54F8-FC28-484D-811C-E559E92F7976} + {7BDE54F8-FC28-484D-811C-E559E92F7976} - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - + + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive From 034fb8bbec9a2f31dd750f49f697b4c254eb0540 Mon Sep 17 00:00:00 2001 From: "Wenzel, Toni" Date: Tue, 1 Oct 2024 15:26:30 +0200 Subject: [PATCH 2/4] Publish on release creation only --- build.cake | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/build.cake b/build.cake index 2988f46..4636808 100644 --- a/build.cake +++ b/build.cake @@ -30,6 +30,8 @@ var nugetPublishFeed = "https://api.nuget.org/v3/index.json"; var isLocalBuild = BuildSystem.IsLocalBuild; var isMasterBranch = StringComparer.OrdinalIgnoreCase.Equals("refs/heads/master", BuildSystem.GitHubActions.Environment.Workflow.Ref); var isPullRequest = BuildSystem.GitHubActions.Environment.PullRequest.IsPullRequest; +var gitHubEvent = EnvironmentVariable("GITHUB_EVENT_NAME"); +var isReleaseCreation = string.Equals(gitHubEvent, "release"); var runSonar = !string.IsNullOrWhiteSpace(sonarLogin); ////////////////////////////////////////////////////////////////////// @@ -43,6 +45,7 @@ Setup(context => Information($"Pull request: {isPullRequest}"); Information($"Run sonar: {runSonar}"); Information($"ref: {BuildSystem.GitHubActions.Environment.Workflow.Ref}"); + Information($"Is release creation: {isReleaseCreation}"); }); Task("Clean") @@ -69,7 +72,23 @@ Task("Version") UpdateAssemblyInfo = false }); - Information("Version: " + versionInfo.FullSemVer); + Information("Major:\t\t\t\t\t" + versionInfo.Major); + Information("Minor:\t\t\t\t\t" + versionInfo.Minor); + Information("Patch:\t\t\t\t\t" + versionInfo.Patch); + Information("MajorMinorPatch:\t\t\t" + versionInfo.MajorMinorPatch); + Information("SemVer:\t\t\t\t\t" + versionInfo.SemVer); + Information("LegacySemVer:\t\t\t\t" + versionInfo.LegacySemVer); + Information("LegacySemVerPadded:\t\t\t" + versionInfo.LegacySemVerPadded); + Information("AssemblySemVer:\t\t\t\t" + versionInfo.AssemblySemVer); + Information("FullSemVer:\t\t\t\t" + versionInfo.FullSemVer); + Information("InformationalVersion:\t\t\t" + versionInfo.InformationalVersion); + Information("BranchName:\t\t\t\t" + versionInfo.BranchName); + Information("Sha:\t\t\t\t\t" + versionInfo.Sha); + Information("NuGetVersionV2:\t\t\t\t" + versionInfo.NuGetVersionV2); + Information("NuGetVersion:\t\t\t\t" + versionInfo.NuGetVersion); + Information("CommitsSinceVersionSource:\t\t" + versionInfo.CommitsSinceVersionSource); + Information("CommitsSinceVersionSourcePadded:\t" + versionInfo.CommitsSinceVersionSourcePadded); + Information("CommitDate:\t\t\t\t" + versionInfo.CommitDate); }); Task("Build") @@ -139,8 +158,8 @@ Task("SonarEnd") }); Task("Publish") - .WithCriteria(!isPullRequest && isMasterBranch) - .IsDependentOn("Test") + .WithCriteria(isReleaseCreation) + .IsDependentOn("Test") .IsDependentOn("Version") .Description("Pushes the created NuGet packages to nuget.org") .Does(() => From 9da8eefdd76e90e2443ccafbe6b52362bd0a2e54 Mon Sep 17 00:00:00 2001 From: "Wenzel, Toni" Date: Tue, 1 Oct 2024 15:31:08 +0200 Subject: [PATCH 3/4] Update Cake --- .config/dotnet-tools.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 831d039..da200cd 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -3,7 +3,7 @@ "isRoot": true, "tools": { "cake.tool": { - "version": "3.0.0", + "version": "4.0.0", "commands": [ "dotnet-cake" ] From 3b25cf312a8c076ab9607af408ab2bb65a8ca77c Mon Sep 17 00:00:00 2001 From: "Wenzel, Toni" Date: Tue, 1 Oct 2024 15:36:53 +0200 Subject: [PATCH 4/4] Use correct version info --- build.cake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.cake b/build.cake index 4636808..469932b 100644 --- a/build.cake +++ b/build.cake @@ -101,7 +101,7 @@ Task("Build") { Version = versionInfo.AssemblySemVer, InformationalVersion = versionInfo.InformationalVersion, - PackageVersion = versionInfo.NuGetVersionV2 + PackageVersion = versionInfo.SemVer }.WithProperty("PackageOutputPath", outputDirNuget.FullPath); var settings = new DotNetBuildSettings