Skip to content

Commit

Permalink
Add support to persist pip reports (#1224)
Browse files Browse the repository at this point in the history
* add support to persist pip report

* pr feedback
  • Loading branch information
pauld-msft committed Aug 12, 2024
1 parent 924c4ea commit f27fe8e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private async Task<CommandLineExecutionResult> ExecuteCommandAsync(
var workingDir = new DirectoryInfo(this.pathUtilityService.GetParentDirectory(formattedPath));

CommandLineExecutionResult command;
var reportName = Path.GetRandomFileName();
var reportName = Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) + ".component-detection-pip-report.json";
var reportFile = new FileInfo(Path.Combine(workingDir.FullName, reportName));

string pipReportCommand;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class PipReportComponentDetector : FileComponentDetector
private const string PipReportOverrideBehaviorEnvVar = "PipReportOverrideBehavior";
private const string PipReportSkipFallbackOnFailureEnvVar = "PipReportSkipFallbackOnFailure";
private const string PipReportFileLevelTimeoutSecondsEnvVar = "PipReportFileLevelTimeoutSeconds";
private const string PipReportPersistReportsEnvVar = "PipReportPersistReports";

private static readonly IList<string> PipReportPreGeneratedFilePatterns = new List<string> { "*.component-detection-pip-report.json", "component-detection-pip-report.json" };

Expand Down Expand Up @@ -300,11 +301,14 @@ protected override async Task OnFileFoundAsync(ProcessRequest processRequest, ID
finally
{
// Clean up the report output JSON file so it isn't left on the machine.
foreach (var reportFile in reportFiles)
if (!this.envVarService.IsEnvironmentVariableValueTrue(PipReportPersistReportsEnvVar))
{
if (reportFile is not null && reportFile.Exists)
foreach (var reportFile in reportFiles)
{
reportFile.Delete();
if (reportFile is not null && reportFile.Exists)
{
reportFile.Delete();
}
}
}
}
Expand Down

0 comments on commit f27fe8e

Please sign in to comment.