Skip to content

Commit b17e4fd

Browse files
committed
fix: sign nugets
1 parent 0f6b66c commit b17e4fd

File tree

1 file changed

+69
-32
lines changed

1 file changed

+69
-32
lines changed

build.cake

+69-32
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,12 @@ void SignNuGet(string publishDir)
234234
return;
235235
}
236236

237+
var vctid = EnvironmentVariable("azure-key-vault-tenant-id");
238+
if(string.IsNullOrWhiteSpace(vctid)) {
239+
Error("Could not resolve signing client tenant id.");
240+
return;
241+
}
242+
237243
var vcs = EnvironmentVariable("azure-key-vault-client-secret");
238244
if(string.IsNullOrWhiteSpace(vcs)) {
239245
Error("Could not resolve signing client secret.");
@@ -247,42 +253,26 @@ void SignNuGet(string publishDir)
247253
}
248254

249255
var nugetFiles = GetFiles(publishDir + "/*.nupkg");
256+
var signTool = Context.Tools.Resolve("NuGetKeyVaultSignTool.exe");
257+
250258
foreach(var file in nugetFiles)
251259
{
252260
Information($"Sign file: {file}");
253-
var processSettings = new ProcessSettings {
254-
RedirectStandardOutput = true,
255-
RedirectStandardError = true,
256-
Arguments = new ProcessArgumentBuilder()
257-
.Append("sign")
258-
.Append(MakeAbsolute(file).FullPath)
259-
.Append("--force")
260-
.AppendSwitchQuoted("--file-digest", "sha256")
261-
.AppendSwitchQuoted("--timestamp-rfc3161", "http://timestamp.digicert.com")
262-
.AppendSwitchQuoted("--timestamp-digest", "sha256")
263-
.AppendSwitchQuoted("--azure-key-vault-url", vurl)
264-
.AppendSwitchQuotedSecret("--azure-key-vault-client-id", vcid)
265-
.AppendSwitchQuotedSecret("--azure-key-vault-client-secret", vcs)
266-
.AppendSwitchQuotedSecret("--azure-key-vault-certificate", vc)
267-
};
268-
269-
using(var process = StartAndReturnProcess("tools/NuGetKeyVaultSignTool", processSettings))
270-
{
271-
process.WaitForExit();
272-
273-
if (process.GetStandardOutput().Any())
274-
{
275-
Information($"Output:{Environment.NewLine}{string.Join(Environment.NewLine, process.GetStandardOutput())}");
276-
}
277261

278-
if (process.GetStandardError().Any())
279-
{
280-
Information($"Errors occurred:{Environment.NewLine}{string.Join(Environment.NewLine, process.GetStandardError())}");
281-
}
282-
283-
// This should output 0 as valid arguments supplied
284-
Information("Exit code: {0}", process.GetExitCode());
285-
}
262+
ExecuteProcess(signTool,
263+
new ProcessArgumentBuilder()
264+
.Append("sign")
265+
.Append(MakeAbsolute(file).FullPath)
266+
.Append("--force")
267+
.AppendSwitchQuoted("--file-digest", "sha256")
268+
.AppendSwitchQuoted("--timestamp-rfc3161", "http://timestamp.digicert.com")
269+
.AppendSwitchQuoted("--timestamp-digest", "sha256")
270+
.AppendSwitchQuoted("--azure-key-vault-url", vurl)
271+
.AppendSwitchQuotedSecret("--azure-key-vault-client-id", vcid)
272+
.AppendSwitchQuotedSecret("--azure-key-vault-tenant-id", vctid)
273+
.AppendSwitchQuotedSecret("--azure-key-vault-client-secret", vcs)
274+
.AppendSwitchQuotedSecret("--azure-key-vault-certificate", vc)
275+
);
286276
}
287277
}
288278

@@ -325,6 +315,53 @@ Task("CreateRelease")
325315
});
326316
});
327317

318+
void ExecuteProcess(FilePath fileName, ProcessArgumentBuilder arguments, string workingDirectory = null)
319+
{
320+
if (!FileExists(fileName))
321+
{
322+
throw new Exception($"File not found: {fileName}");
323+
}
324+
325+
var processSettings = new ProcessSettings
326+
{
327+
RedirectStandardOutput = true,
328+
RedirectStandardError = true,
329+
Arguments = arguments
330+
};
331+
332+
if (!string.IsNullOrEmpty(workingDirectory))
333+
{
334+
processSettings.WorkingDirectory = workingDirectory;
335+
}
336+
337+
Information($"Arguments: {arguments.RenderSafe()}");
338+
339+
using(var process = StartAndReturnProcess(fileName, processSettings))
340+
{
341+
process.WaitForExit();
342+
343+
if (process.GetStandardOutput().Any())
344+
{
345+
Information($"Output:{Environment.NewLine} {string.Join(Environment.NewLine, process.GetStandardOutput())}");
346+
}
347+
348+
if (process.GetStandardError().Any())
349+
{
350+
// Information($"Errors occurred:{Environment.NewLine} {string.Join(Environment.NewLine, process.GetStandardError())}");
351+
throw new Exception($"Errors occurred:{Environment.NewLine} {string.Join(Environment.NewLine, process.GetStandardError())}");
352+
}
353+
354+
// This should output 0 as valid arguments supplied
355+
var exitCode = process.GetExitCode();
356+
Information($"Exit code: {exitCode}");
357+
358+
if (exitCode > 0)
359+
{
360+
throw new Exception($"Exit code: {exitCode}");
361+
}
362+
}
363+
}
364+
328365
///////////////////////////////////////////////////////////////////////////////
329366
// TASK TARGETS
330367
///////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)