Skip to content

Commit ee760c4

Browse files
[release/10.0.1xx] Create binlogs and use ProcessService (#2404)
Co-authored-by: Ella Hathaway <[email protected]>
1 parent 63fff00 commit ee760c4

File tree

2 files changed

+37
-52
lines changed

2 files changed

+37
-52
lines changed

eng/pipelines/templates/steps/vmr-validate-signing.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ steps:
6767
/p:ArtifactDownloadDirectory=${{ parameters.signCheckFilesDirectory }} `
6868
/p:SourceBranch='$(Build.SourceBranch)' `
6969
/p:DotNetRootDirectory=$(Build.SourcesDirectory) `
70-
/p:OutputLogsDirectory=${{ parameters.outputDirectory }}
70+
/p:OutputLogsDirectory=${{ parameters.outputDirectory }} `
71+
/bl:${{ parameters.outputDirectory }}/outer-signing-validation.binlog
7172
7273
displayName: Validate Signing
7374
continueOnError: ${{ parameters.continueOnError }}
@@ -84,7 +85,8 @@ steps:
8485
/p:ArtifactDownloadDirectory=${{ parameters.signCheckFilesDirectory }} \
8586
/p:SourceBranch='$(Build.SourceBranch)' \
8687
/p:DotNetRootDirectory=$(Build.SourcesDirectory) \
87-
/p:OutputLogsDirectory=${{ parameters.outputDirectory }}
88+
/p:OutputLogsDirectory=${{ parameters.outputDirectory }} \
89+
/bl:${{ parameters.outputDirectory }}/outer-signing-validation.binlog
8890
8991
displayName: Validate Signing
9092
continueOnError: ${{ parameters.continueOnError }}

eng/tools/tasks/Microsoft.DotNet.UnifiedBuild.Tasks/SigningValidation.cs

Lines changed: 33 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212
using System.Runtime.InteropServices;
1313
using System.Text.RegularExpressions;
1414
using System.Threading;
15+
using System.Threading.Tasks;
1516
using System.Xml.Linq;
16-
using Task = System.Threading.Tasks.Task;
17+
using Microsoft.DotNet.UnifiedBuild.Tasks.Services;
18+
using BuildTask = Microsoft.Build.Utilities.Task;
1719

1820
namespace Microsoft.DotNet.UnifiedBuild.Tasks;
1921

20-
public class SigningValidation : Microsoft.Build.Utilities.Task
22+
public class SigningValidation : BuildTask
2123
{
2224
/// <summary>
2325
/// Directory where the blobs and packages were downloaded to
@@ -58,21 +60,24 @@ public class SigningValidation : Microsoft.Build.Utilities.Task
5860
/// </summary>
5961
private static readonly string _signCheckFilesDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName(), "SignCheckFiles");
6062

63+
private const string _signCheckBinLogFileName = "signing-validation.binlog";
6164
private const string _signCheckExclusionsFileName = "SignCheckExclusionsFile.txt";
6265
private const string _signCheckStdoutLogFileName = "signcheck.log";
6366
private const string _signCheckStderrLogFileName = "signcheck.error.log";
6467
private const string _signCheckResultsXmlFileName = "signcheck.xml";
6568
private const int _signCheckTimeout = 60 * 60 * 1000 * 2; // 2 hours
6669

67-
public override bool Execute()
70+
public override bool Execute() => ExecuteAsync().GetAwaiter().GetResult();
71+
72+
private async Task<bool> ExecuteAsync()
6873
{
6974
try
7075
{
7176
ForceDirectory(OutputLogsDirectory);
7277

7378
PrepareFilesToSignCheck();
7479

75-
RunSignCheck();
80+
await RunSignCheckAsync();
7681

7782
ProcessSignCheckResults();
7883

@@ -184,56 +189,33 @@ private void PrepareFilesToSignCheck()
184189
/// <summary>
185190
/// Runs the signcheck task on the specified package base path
186191
/// </summary>
187-
private void RunSignCheck()
192+
private async Task RunSignCheckAsync()
188193
{
189-
using (var process = new Process())
194+
(string command, string arguments) = GetSignCheckCommandAndArguments();
195+
Log.LogMessage(MessageImportance.High, $"Running SignCheck...");
196+
197+
var processService = new ProcessService(Log, timeout: _signCheckTimeout);
198+
ProcessResult result = await processService.RunProcessAsync(
199+
command,
200+
arguments,
201+
printOutput: false);
202+
203+
string errorLog = GetLogPath(_signCheckStderrLogFileName);
204+
string errorLogContent = File.Exists(errorLog) ? File.ReadAllText(errorLog).Trim() : string.Empty;
205+
if (result.ExitCode != 0 || !string.IsNullOrWhiteSpace(errorLogContent))
190206
{
191-
(string command, string arguments) = GetSignCheckCommandAndArguments();
192-
193-
process.StartInfo = new ProcessStartInfo()
194-
{
195-
FileName = command,
196-
Arguments = arguments,
197-
UseShellExecute = false,
198-
RedirectStandardOutput = true,
199-
RedirectStandardError = true,
200-
};
201-
202-
// SignCheck writes console output to log files and the output stream.
203-
// To avoid cluttering the console, redirect the output to empty handlers.
204-
process.OutputDataReceived += (sender, args) => { };
205-
process.ErrorDataReceived += (sender, args) => { };
206-
207-
Log.LogMessage(MessageImportance.High, $"Running SignCheck...");
208-
209-
process.Start();
210-
211-
process.BeginOutputReadLine();
212-
process.BeginErrorReadLine();
213-
214-
bool hasExited = process.WaitForExit(_signCheckTimeout);
215-
if (!hasExited)
216-
{
217-
throw new TimeoutException($"SignCheck timed out after {_signCheckTimeout / 1000} seconds.");
218-
}
219-
220-
string errorLog = GetLogPath(_signCheckStderrLogFileName);
221-
string errorLogContent = File.Exists(errorLog) ? File.ReadAllText(errorLog).Trim() : string.Empty;
222-
if (process.ExitCode != 0 || !string.IsNullOrWhiteSpace(errorLogContent))
223-
{
224-
// We don't want to throw here because SignCheck will fail for unsigned files
225-
Log.LogError($"SignCheck failed with exit code {process.ExitCode}: {errorLogContent}");
226-
}
227-
228-
string stdoutLog = GetLogPath(_signCheckStdoutLogFileName);
229-
string stdoutLogContent = File.Exists(stdoutLog) ? File.ReadAllText(stdoutLog).Trim() : string.Empty;
230-
if (!string.IsNullOrWhiteSpace(stdoutLogContent) && stdoutLogContent.Contains("No files were processed"))
231-
{
232-
Log.LogError("SignCheck did not process any files.");
233-
}
207+
// We don't want to throw here because SignCheck will fail for unsigned files
208+
Log.LogError($"SignCheck failed with exit code {result.ExitCode}: {errorLogContent}");
209+
}
234210

235-
Log.LogMessage(MessageImportance.High, $"SignCheck completed.");
211+
string stdoutLog = GetLogPath(_signCheckStdoutLogFileName);
212+
string stdoutLogContent = File.Exists(stdoutLog) ? File.ReadAllText(stdoutLog).Trim() : string.Empty;
213+
if (!string.IsNullOrWhiteSpace(stdoutLogContent) && stdoutLogContent.Contains("No files were processed"))
214+
{
215+
Log.LogError("SignCheck did not process any files.");
236216
}
217+
218+
Log.LogMessage(MessageImportance.High, $"SignCheck completed.");
237219
}
238220

239221
private void ProcessSignCheckResults()
@@ -322,6 +304,7 @@ private bool LogAndCheckResults(IEnumerable<string> results, string issueType)
322304
$"/p:SignCheckErrorLog='{GetLogPath(_signCheckStderrLogFileName)}' " +
323305
$"/p:SignCheckResultsXmlFile='{GetLogPath(_signCheckResultsXmlFileName)}' " +
324306
$"/p:SignCheckExclusionsFile='{GetSignCheckExclusionsFile()}' " +
307+
$"/bl:{GetLogPath(_signCheckBinLogFileName)} " +
325308
$"$additionalArgs$";
326309

327310
string command = string.Empty;

0 commit comments

Comments
 (0)