From f8e4b73ffbc647f1abfa8f863f725cb312d9f888 Mon Sep 17 00:00:00 2001 From: Mark Ridgwell Date: Tue, 17 Dec 2024 12:43:19 +0000 Subject: [PATCH] Check for GenerateSBOM setting --- CHANGELOG.md | 1 + .../Settings/GenerateSbomPolicy.cs | 18 ++++++++++++++++++ src/FunFair.BuildCheck.Runner/Setup.cs | 3 ++- 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 src/FunFair.BuildCheck.ProjectChecks/Settings/GenerateSbomPolicy.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index 87f02276..65f1b0d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ Please ADD ALL Changes to the UNRELEASED SECTION and not a specific release ## [Unreleased] ### Added - Check for projects having the Microsoft SBOM tool +- Check for GenerateSBOM setting on packable projects ### Fixed ### Changed - Dependencies - Updated ThisAssembly.AssemblyInfo to 1.5.0 diff --git a/src/FunFair.BuildCheck.ProjectChecks/Settings/GenerateSbomPolicy.cs b/src/FunFair.BuildCheck.ProjectChecks/Settings/GenerateSbomPolicy.cs new file mode 100644 index 00000000..e4397b56 --- /dev/null +++ b/src/FunFair.BuildCheck.ProjectChecks/Settings/GenerateSbomPolicy.cs @@ -0,0 +1,18 @@ +using System.Xml; +using FunFair.BuildCheck.ProjectChecks.Helpers; +using Microsoft.Extensions.Logging; + +namespace FunFair.BuildCheck.ProjectChecks.Settings; + +public sealed class GenerateSbomPolicy : SimplePropertyProjectCheckBase +{ + public GenerateSbomPolicy(ILogger logger) + : base(propertyName: "GenerateSBOM", requiredValue: "true", logger: logger) + { + } + + protected override bool CanCheck(string projectName, string projectFolder, XmlDocument project) + { + return project.IsPackable(); + } +} \ No newline at end of file diff --git a/src/FunFair.BuildCheck.Runner/Setup.cs b/src/FunFair.BuildCheck.Runner/Setup.cs index 9636ebcc..b8be8f43 100644 --- a/src/FunFair.BuildCheck.Runner/Setup.cs +++ b/src/FunFair.BuildCheck.Runner/Setup.cs @@ -85,7 +85,8 @@ private static IServiceCollection GeneralProjectSettings(this IServiceCollection .AddProjectCheck() .AddProjectCheck() .AddProjectCheck() - .AddProjectCheck(); + .AddProjectCheck() + .AddProjectCheck(); } private static IServiceCollection PublishingSettings(this IServiceCollection services)