Show-FailureLogs to include vcpkg build failure logs (#5776)

* Show-FailureLogs to include vcpkg build failure logs

* Add comment

* Add proper array syntax

* Use proper syntax to create an array even if there's only a single element

Co-authored-by: Ben Broderick Phillips <ben@benbp.net>

---------

Co-authored-by: Anton Kolesnyk <antkmsft@users.noreply.github.com>
Co-authored-by: Ben Broderick Phillips <ben@benbp.net>
This commit is contained in:
Anton Kolesnyk 2024-07-11 16:34:44 -07:00 committed by GitHub
parent 22f5135d4c
commit 69ce3d7cfa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -6,7 +6,8 @@
# sensitive information.
$logFiles = Get-ChildItem -Recurse -Filter *.log
$filteredLogs = $logFiles.Where({ $_.Name -in ('vcpkg-bootstrap.log', 'vcpkg-manifest-install.log') })
$vcpkgLogFileNames = @('vcpkg-bootstrap.log', 'vcpkg-manifest-install.log')
$filteredLogs = $logFiles.Where({ $_.Name -in $vcpkgLogFileNames })
$filteredLogs.FullName | Write-Host
@ -15,14 +16,33 @@ if (!$filteredLogs) {
exit 0
}
foreach ($logFile in $filteredLogs)
$filteredLogs = @($filteredLogs.FullName)
for ($i = 0; $i -lt $filteredLogs.Length; $i += 1)
{
$logFile = $filteredLogs[$i]
Write-Host "//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////"
Write-Host "=============================================================================================================================="
Write-Host "Log file: $logFile"
Write-Host "=============================================================================================================================="
try {
Get-Content $logFile | Write-Host
# vcpkg logs do reference build log paths after "See logs for more information:". Sometimes there are multiple files to see.
# And should there be a C++ build error, for example - that is where the error message would be.
# So, we parse known logs (contained in vcpkgLogFileNames), and see if more logs are mentioned there. If there are extra logs,
# we add them to the end of the list that we're iterating over, so that the format is the same, and this code gets reused
# (i.e. formatting, Log file name header, try-catch, and so on).
if ($i -lt $vcpkgLogFileNames.Length)
{
$rawContents = Get-Content $logFile -Raw
$regexMatches = Select-String "See logs for more information\:\s*(\r|\n|\r\n|\n\r)(\s+(?<logFilePath>\S*)\s*(\r|\n|\r\n|\n\r))+" -input $rawContents -AllMatches
foreach ($additionalLogFile in $regexMatches.matches.groups.Where({ $_.Name -eq "logFilePath" }))
{
$filteredLogs += $additionalLogFile.Value
}
}
} catch {
Write-Host "Could not locate file found using Get-ChildItem $logFile"
}