Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
"isRoot": true,
"tools": {
"dotnet-stryker": {
"version": "4.8.1",
"version": "4.12.0",
"commands": [
"dotnet-stryker"
],
"rollForward": false
},
"nuke.globaltool": {
"version": "9.0.4",
"version": "10.1.0",
"commands": [
"nuke"
],
Expand Down
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ dotnet_diagnostic.SA1000.severity = suggestion # Need to configure formatting in
dotnet_diagnostic.SA1313.severity = suggestion # Rider disagrees?

[**/*.{Tests,E2ETests,ArchTests}*/**.cs]
dotnet_diagnostic.CA1515.severity = none
dotnet_diagnostic.CA1852.severity = warning
dotnet_diagnostic.CA1816.severity = warning
dotnet_diagnostic.CA2007.severity = none
Expand All @@ -242,3 +243,10 @@ dotnet_diagnostic.SA1600.severity = none
dotnet_diagnostic.SA1118.severity = none
# Await *Async instead.
dotnet_diagnostic.S6966.severity = none
# * creates a new instance of * which is never used
dotnet_diagnostic.CA1806.severity = suggestion
# A property should not follow a method
dotnet_diagnostic.SA1201.severity = none
# Instance of NullForgiving operator without justification detected
dotnet_diagnostic.NX0001.severity = suggestion
dotnet_diagnostic.NX0002.severity = suggestion
1 change: 1 addition & 0 deletions .github/copilot-instructions.md
2 changes: 2 additions & 0 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
"type": "string",
"enum": [
"Build",
"CheckBuildWarnings",
"CheckWarnings",
"Clean",
"CleanProjects",
"Pack",
Expand Down
12 changes: 12 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# AGENTS.md

## Project structure

- `dotnet/ImageReferences/` - Strongly-typed container image references for .NET.
- `dotnet/ImageReferences.Extensions.Nuke/` - NUKE build extensions

Each project may have:

- its own AGENTS.md file with more detailed guidance
- related test projects, whose name will follow the pattern `<ProjectName>.Tests`
- its own README.md file used for the NuGet package
5 changes: 3 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<PackageVersion>1.0.0-preview.2.local</PackageVersion>
<PackageVersion>0.0.0-local</PackageVersion>
<Authors>hojmark</Authors>
<Copyright>Copyright (c) hojmark</Copyright>
<PackageProjectUrl>https://github.com/hojmark/labs</PackageProjectUrl>
Expand All @@ -15,11 +15,12 @@
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<AnalysisMode>All</AnalysisMode>
<TreatWarningsAsErrors Condition="'$(Configuration)'=='Release'">true</TreatWarningsAsErrors>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" PrivateAssets="all" />
<PackageReference Include="SonarAnalyzer.CSharp" PrivateAssets="all" />
<PackageReference Include="Nullable.Extended.Analyzer" PrivateAssets="all" />
</ItemGroup>
</Project>
7 changes: 4 additions & 3 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
<PackageVersion Include="Microsoft.Build.Utilities.Core" Version="18.0.2" />
</ItemGroup>
<ItemGroup>
<PackageVersion Include="Nuke.Common" Version="9.0.4" />
<PackageVersion Include="Nuke.Common" Version="10.1.0" />
<PackageVersion Include="Nullable.Extended.Analyzer" Version="1.15.6581" />
<PackageVersion Include="Semver" Version="3.0.0" />
<PackageVersion Include="SonarAnalyzer.CSharp" Version="10.15.0.120848" />
<PackageVersion Include="SonarAnalyzer.CSharp" Version="10.19.0.132793" />
<PackageVersion Include="StyleCop.Analyzers" Version="1.1.118" />
<PackageVersion Include="TUnit" Version="1.2.11" />
<PackageVersion Include="TUnit" Version="1.15.0" />
</ItemGroup>
</Project>
12 changes: 12 additions & 0 deletions HLabs.Build.slnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Solution>
<Folder Name="/Workflows/">
<File Path=".github\workflows\ci.yaml" />
<File Path=".github\workflows\prerelease.yaml" />
<File Path=".github\workflows\release.yaml" />
</Folder>
<Folder Name="/Workflows/Actions/" />
<Folder Name="/Workflows/Actions/runner-setup/">
<File Path=".github\actions\setup-runner\action.yml" />
</Folder>
<Project Path="build\_build.csproj" />
</Solution>
13 changes: 10 additions & 3 deletions HLabs.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@
<Build Project="false" />
</Project>
</Folder>
<Folder Name="/Build/Workflows/">
<File Path=".github/workflows/ci.yaml" />
<File Path=".github/workflows/codeql.yml" />
<File Path=".github/workflows/prerelease.yaml" />
<File Path=".github/workflows/release.yaml" />
</Folder>
<Folder Name="/Common/">
<File Path=".editorconfig" />
<File Path="Directory.Build.props" />
<File Path="Directory.Packages.props" />
</Folder>
<Folder Name="/Workflows/" />
<Project Path="dotnet/Containers.Tests/Containers.Tests.csproj" />
<Project Path="dotnet/Containers/Containers.csproj" />
<Project Path="dotnet/ImageReferences.Extensions.Nuke/ImageReferences.Extensions.Nuke.csproj" />
<Project Path="dotnet/ImageReferences.Tests/ImageReferences.Tests.csproj" />
<Project Path="dotnet/ImageReferences/ImageReferences.csproj" />
</Solution>
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# HLabs

A collection of .NET libraries.

## NuGet packages

| Name | Version | Description |
|-------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------|
| [HLabs.ImageReferences](dotnet/ImageReferences/README.md) | [![NuGet](https://img.shields.io/nuget/vpre/HLabs.ImageReferences.svg)](https://www.nuget.org/packages/HLabs.ImageReferences/) | Strongly-typed container image references |
| [HLabs.ImageReferences.Extensions.Nuke](dotnet/ImageReferences.Extensions.Nuke/README.md) | [![NuGet](https://img.shields.io/nuget/vpre/HLabs.ImageReferences.Extensions.Nuke.svg)](https://www.nuget.org/packages/HLabs.ImageReferences.Extensions.Nuke/) | NUKE build extension methods |
3 changes: 2 additions & 1 deletion build/NukeBuild.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ sealed partial class NukeBuild {

Target Build => _ => _
.DependsOn( Restore )
.Triggers( CheckWarnings )
.Executes( () => {
//using var _ = new OperationTimer( nameof(Build) );

Expand All @@ -24,7 +25,7 @@ sealed partial class NukeBuild {
.SetProjectFile( Solution )
.SetConfiguration( Configuration )
//TODO.SetVersionProperties( version )
//.SetBinaryLog( BinaryBuildLogName )
.SetBinaryLog( BinaryBuildLogName )
.EnableNoLogo()
.EnableNoRestore()
);
Expand Down
34 changes: 34 additions & 0 deletions build/NukeBuild.CheckWarnings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Nuke.Common;
using Serilog;
using Utils;

// ReSharper disable VariableHidesOuterVariable
// ReSharper disable AllUnderscoreLocalParameterName
// ReSharper disable UnusedMember.Local

sealed partial class NukeBuild {
private const string BinaryBuildLogName = "build.binlog";

Target CheckWarnings => _ => _
.DependsOn( CheckBuildWarnings );

Target CheckBuildWarnings => _ => _
.After( Build )
.Executes( () => {
var warnings = BinaryLogReader.GetWarnings( BinaryBuildLogName );

foreach ( var warning in warnings ) {
Log.Information( warning );
}

var hasWarnings = warnings.Length != 0;

if ( hasWarnings ) {
Log.Error( "Found {Count} build warnings", warnings.Length );
throw new Exception( $"Found {warnings.Length} build warnings" );
}

Log.Information( "🟢 No build warnings found" );
}
);
}
1 change: 0 additions & 1 deletion build/NukeBuild.Clean.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Linq;
using Nuke.Common;
using Nuke.Common.IO;
using Nuke.Common.ProjectModel;
Expand Down
67 changes: 66 additions & 1 deletion build/NukeBuild.Pack.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO;
using System.IO.Compression;
using System.Xml.Linq;
using Nuke.Common;
using Nuke.Common.IO;
using Nuke.Common.Tools.DotNet;
Expand Down Expand Up @@ -35,11 +36,75 @@ internal partial class NukeBuild {
Log.Information( "Publishing to local registry {Path}", Paths.NuGetLocalRegistry );

foreach ( var nupkg in Directory.GetFiles( Paths.NuGetArtifacts, "*.nupkg" ) ) {
ClearNuGetCacheFor( nupkg );
var fileName = Path.GetFileName( nupkg );
var path = Path.Combine( Paths.NuGetLocalRegistry, fileName );
File.Copy( nupkg, path, overwrite: true );
Log.Information( "Copied {Nupkg} to {Path}", fileName, path );
}
}
);

void ClearNuGetCacheFor( string nupkgPath ) {
var (packageId, version) = ReadPackageIdentity( nupkgPath );

if ( packageId is null || version is null )
return;

var globalPackages = Path.Combine(
Environment.GetFolderPath( Environment.SpecialFolder.UserProfile ),
".nuget",
"packages" );

var cachedPath = Path.Combine(
globalPackages,
packageId.ToLowerInvariant(),
version );

if ( !Directory.Exists( cachedPath ) )
return;

Log.Information(
"Clearing NuGet cache for {Id} {Version} at {Path}",
packageId,
version,
cachedPath );

Directory.Delete( cachedPath, recursive: true );
}

private (string? Id, string? Version) ReadPackageIdentity( string nupkgPath ) {
using var archive = ZipFile.OpenRead( nupkgPath );

var nuspecEntry = archive.Entries
.FirstOrDefault( e => e.FullName.EndsWith( ".nuspec", StringComparison.OrdinalIgnoreCase ) );

if ( nuspecEntry is null ) {
Log.Warning( "No .nuspec found in {Nupkg}", nupkgPath );
return ( null, null );
}

using var stream = nuspecEntry.Open();
var document = XDocument.Load( stream );

var metadata = document
.Descendants()
.FirstOrDefault( e => e.Name.LocalName == "metadata" );

var id = metadata?
.Elements()
.FirstOrDefault( e => e.Name.LocalName == "id" )
?.Value;

var version = metadata?
.Elements()
.FirstOrDefault( e => e.Name.LocalName == "version" )
?.Value;

if ( id is null || version is null ) {
Log.Warning( "Could not read id/version from nuspec in {Nupkg}", nupkgPath );
}

return ( id, version );
}
}
25 changes: 25 additions & 0 deletions build/Utils/BinaryLogReader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Text.RegularExpressions;
using Nuke.Common.Tooling;
using Nuke.Common.Tools.DotNet;
using static Nuke.Common.Tools.DotNet.DotNetTasks;

namespace Utils;

internal static class BinaryLogReader {
public static string[] GetWarnings( string binaryLogName ) {
string warningsLogName = $"{binaryLogName}-warnings-only.log";

DotNetMSBuild( s => s
.SetTargetPath( binaryLogName )
.SetNoConsoleLogger( true )
.AddProcessAdditionalArguments( "-fl", $"-flp:logfile={warningsLogName};warningsonly" )
);

return File.ReadAllLines( warningsLogName )
.Select(
// Remove the leading " 4>" part
line => Regex.Replace( line, @"^\s*\d+>", string.Empty )
)
.ToArray();
}
}
2 changes: 2 additions & 0 deletions build/_build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<NukeScriptDirectory>..\dotnet</NukeScriptDirectory>
<NukeTelemetryVersion>1</NukeTelemetryVersion>
<IsPackable>false</IsPackable>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
Expand Down
52 changes: 0 additions & 52 deletions dotnet/Containers.Tests/ImageReferenceTests.cs

This file was deleted.

Loading
Loading