Skip to content

Commit

Permalink
Merge pull request #45 from twenzel/feature/UpdateProject
Browse files Browse the repository at this point in the history
Update project
  • Loading branch information
twenzel authored Oct 1, 2024
2 parents 3037544 + 3b25cf3 commit d3e9823
Show file tree
Hide file tree
Showing 8 changed files with 180 additions and 142 deletions.
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"cake.tool": {
"version": "3.0.0",
"version": "4.0.0",
"commands": [
"dotnet-cake"
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

Expand All @@ -10,13 +10,19 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.11.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="7.0.9" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" />
<PackageReference Include="NUnit.Analyzers" Version="3.6.1" />
<PackageReference Include="coverlet.collector" Version="3.2.0" />
<PackageReference Include="FluentAssertions" Version="6.12.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.8" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="NUnit.Analyzers" Version="4.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using NUnit.Framework;
using FluentAssertions;
using NUnit.Framework;

namespace CHG.Extensions.Security.Txt.IntegrationTests;

Expand All @@ -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()
{
Expand Down
234 changes: 133 additions & 101 deletions build.cake
Original file line number Diff line number Diff line change
@@ -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") ?? "");
Expand Down Expand Up @@ -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);

//////////////////////////////////////////////////////////////////////
Expand All @@ -38,117 +40,147 @@ 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}");
Information($"Is release creation: {isReleaseCreation}");
});

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("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")
.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.SemVer
}.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(isReleaseCreation)
.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);
2 changes: 1 addition & 1 deletion samples/DemoWebApplication/DemoWebApplication.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ProjectGuid>{3FEF71C2-52D6-46D4-AC08-9752D8BD3B12}</ProjectGuid>
</PropertyGroup>

Expand Down
19 changes: 7 additions & 12 deletions src/CHG.Extensions.Security.Txt.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net6.0;net7.0</TargetFrameworks>
<TargetFramework>net8.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Company>CHG-MERIDIAN AG</Company>
<Authors>Toni Wenzel</Authors>
Expand All @@ -20,31 +20,26 @@
<ProjectGuid>{84FEB7F6-A851-4AB6-AA0C-010F23BC6804}</ProjectGuid>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' != 'netstandard2.0'">
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Abstractions" Version="2.1.1" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1">
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.52.0.60960">
<PackageReference Include="SonarAnalyzer.CSharp" Version="9.32.0.97167">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<None Include="icon.png" Pack="true" Visible="false" PackagePath="" />
<None Include="icon.png" Pack="true" Visible="false" PackagePath="." />
<None Include="..\README.md" Pack="true" Visible="false" PackagePath="." />
</ItemGroup>
</Project>
Loading

0 comments on commit d3e9823

Please sign in to comment.