Adding --signExclude parameter

This allows the caller to specify a regex pattern to exclude files. When specified the default filter no longer applies
This commit is contained in:
Kevin Bost
2025-01-13 22:19:47 -08:00
committed by Caelan
parent 9256ab38db
commit 81a44aee91
6 changed files with 13 additions and 10 deletions

View File

@@ -82,7 +82,7 @@ public class PackTask : MSBuildAsyncTask
public string? SignParameters { get; set; }
public string? AzureTrustedSignFile { get; set; }
public bool SignSkipDll { get; set; }
public string? SignExclude { get; set; }
public int SignParallel { get; set; } = 10;

View File

@@ -86,7 +86,7 @@
SplashImage="$(VelopackSplashImage)"
SkipVelopackAppCheck="$(VelopackSkipVelopackAppCheck)"
SignParameters="$(VelopackSignParameters)"
SignSkipDll="$(VelopackSignSkipDll)"
SignExclude="$(VelopackSignExclude)"
SignParallel="$(VelopackSignParallel)"
SignTemplate="$(VelopackSignTemplate)"
Categories="$(VelopackCategories)"

View File

@@ -1,4 +1,5 @@
using System.Runtime.Versioning;
using System.Text.RegularExpressions;
using Microsoft.Extensions.Logging;
using Velopack.Compression;
using Velopack.Core;
@@ -18,8 +19,9 @@ public class WindowsPackCommandRunner : PackageBuilder<WindowsPackOptions>
protected override Task CodeSign(Action<int> progress, string packDir)
{
Regex fileExcludeRegex = Options.SignExclude != null ? new Regex(Options.SignExclude) : null;
var filesToSign = new DirectoryInfo(packDir).GetAllFilesRecursively()
.Where(x => Options.SignSkipDll ? PathUtil.PathPartEndsWith(x.Name, ".exe") : PathUtil.FileIsLikelyPEImage(x.Name))
.Where(x => !fileExcludeRegex?.IsMatch(x.FullName) ?? PathUtil.FileIsLikelyPEImage(x.Name))
.Select(x => x.FullName)
.ToArray();

View File

@@ -4,7 +4,7 @@ public class WindowsSigningOptions
{
public string SignParameters { get; set; }
public bool SignSkipDll { get; set; }
public string SignExclude { get; set; }
public int SignParallel { get; set; }

View File

@@ -10,11 +10,12 @@ public class WindowsPackCommand : PackCommand
public string SignParameters { get; private set; }
public bool SignSkipDll { get; private set; }
public string SignExclude { get; private set; }
public int SignParallel { get; private set; }
public string SignTemplate { get; private set; }
public string AzureTrustedSignFile { get; private set; }
public string Shortcuts { get; private set; }
@@ -42,8 +43,8 @@ public class WindowsPackCommand : PackCommand
.SetDescription("Use a custom signing command. {{file}} will be substituted.")
.SetArgumentHelpName("COMMAND");
AddOption<bool>((v) => SignSkipDll = v, "--signSkipDll")
.SetDescription("Only signs EXE files, and skips signing DLL files.")
AddOption<string>((v) => SignExclude = v, "--signExclude")
.SetDescription("A regex which excludes matched files from signing.")
.SetHidden();
AddOption<int>((v) => SignParallel = v, "--signParallel")

View File

@@ -265,14 +265,14 @@ public class PackWindowsCommandTests : ReleaseCommandTests<WindowsPackCommand>
}
[WindowsOnlyFact]
public void SignSkipDll_BareOption_SetsFlag()
public void SignExclude_WithPattern_SetsOption()
{
var command = new WindowsPackCommand();
string cli = GetRequiredDefaultOptions() + "--signSkipDll";
string cli = GetRequiredDefaultOptions() + @"--signExclude \.dll$";
ParseResult parseResult = command.ParseAndApply(cli);
Assert.True(command.SignSkipDll);
Assert.Equal(@"\.dll$", command.SignExclude);
}
[WindowsOnlyFact]