Skip to content
Merged
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
31 changes: 24 additions & 7 deletions build/NukeBuild.CheckWarnings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Linq;
using Drift.Build.Utilities;
using Drift.Build.Utilities.MsBuild;
using Nuke.Common;
Expand All @@ -12,6 +13,15 @@ sealed partial class NukeBuild {
private const string BinaryBuildLogName = "build.binlog";
private const string BinaryPublishLogName = "publish.binlog";

/*
* Ignore NuGet vulnerability warnings. The audit.yaml workflow will fail if any of these are detected.
* NU1901: Package with low severity detected
* NU1902: Package with moderate severity detected
* NU1903: Package with high severity detected
* NU1904: Package with critical severity detected
*/
private static readonly string[] IgnoredBuildWarnings = ["NU1901", "NU1902", "NU1903", "NU1904"];

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

Expand All @@ -20,17 +30,24 @@ sealed partial class NukeBuild {
.Executes( () => {
using var _ = new OperationTimer( nameof(CheckBuildWarnings) );

var warnings = BinaryLogReader.GetWarnings( BinaryBuildLogName );
var warnings = BinaryLogReader.GetWarnings( BinaryBuildLogName )
.Select( w => new { Warning = w, Ignored = IgnoredBuildWarnings.Any( w.Contains ) } )
.ToArray();

foreach ( var warning in warnings ) {
Log.Information( warning );
foreach ( var w in warnings ) {
if ( w.Ignored ) {
Log.Debug( "{WarningMessage} (ignored)", w.Warning );
}
else {
Log.Information( "{WarningMessage}", w.Warning );
}
}

var hasWarnings = warnings.Length != 0;
var activeWarnings = warnings.Where( w => !w.Ignored ).ToArray();

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

Log.Information( "🟢 No build warnings found" );
Expand Down
Loading