Add support to persist pip reports (#1224)

* add support to persist pip report

* pr feedback
This commit is contained in:
Paul Dorsch 2024-08-12 17:22:00 -04:00 коммит произвёл GitHub
Родитель 924c4ea498
Коммит f27fe8e98e
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
2 изменённых файлов: 8 добавлений и 4 удалений

Просмотреть файл

@ -131,7 +131,7 @@ public class PipCommandService : IPipCommandService
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;

Просмотреть файл

@ -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" };
@ -300,11 +301,14 @@ public class PipReportComponentDetector : FileComponentDetector
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();
}
}
}
}