From ce4f25da23e996415113f7167243059b42d4107c Mon Sep 17 00:00:00 2001 From: Daniel Jurek Date: Tue, 6 Feb 2024 22:36:36 -0800 Subject: [PATCH] Upload logs on cmake generate/build failure (#5293) * Upload logs on cmake generate/build failure * Copy relevant files to staging location, clean up after publishing * Update cspell words * Test: break cmake generate in a way that'll produce SOME log files. * Revert "Test: break cmake generate in a way that'll produce SOME log files." This reverts commit d5a300587b3359ed3f2bf7be5abea40868f958a7. * Show failure logs instead of uploading artifacts. Only show log files for vcpkg at this time * Reapply "Test: break cmake generate in a way that'll produce SOME log files." This reverts commit 582629ad587f3c9b652ac1f8a7eda5e12d46843a. * Revert "Reapply "Test: break cmake generate in a way that'll produce SOME log files."" This reverts commit 7a35250c7e598fc6e1c060f896cbc952704e40bf. * Another type of test * Revert inadvertent whitespace changes * Revert "Another type of test" This reverts commit e38013f95b152e4e2a3b9d27ccf1eb9b63fa1817. * More logging --- .vscode/cspell.json | 2 ++ eng/pipelines/templates/jobs/ci.tests.yml | 2 ++ .../templates/jobs/cmake-generate.tests.yml | 2 ++ eng/pipelines/templates/jobs/live.tests.yml | 2 ++ .../templates/steps/cmake-generate.yml | 2 ++ .../templates/steps/show-failure-logs.yml | 6 +++++ eng/scripts/Show-FailureLogs.ps1 | 25 +++++++++++++++++++ 7 files changed, 41 insertions(+) create mode 100644 eng/pipelines/templates/steps/show-failure-logs.yml create mode 100644 eng/scripts/Show-FailureLogs.ps1 diff --git a/.vscode/cspell.json b/.vscode/cspell.json index b1fdfae93c..3447e7d91e 100644 --- a/.vscode/cspell.json +++ b/.vscode/cspell.json @@ -201,6 +201,7 @@ "rtti", "rwxrw", "sasia", + "sbom", "Schonberger", "scus", "SDDL", @@ -251,6 +252,7 @@ "Wunused", "xbox", "Xclang", + "xcode", "XSMB", "zulu" ], diff --git a/eng/pipelines/templates/jobs/ci.tests.yml b/eng/pipelines/templates/jobs/ci.tests.yml index 0edd5b26e4..74844e3820 100644 --- a/eng/pipelines/templates/jobs/ci.tests.yml +++ b/eng/pipelines/templates/jobs/ci.tests.yml @@ -184,6 +184,8 @@ jobs: VcpkgArgs: "$(VcpkgArgs)" Env: "$(CmakeEnvArg)" + - template: /eng/pipelines/templates/steps/show-failure-logs.yml + - template: /eng/common/testproxy/test-proxy-tool.yml parameters: runProxy: true diff --git a/eng/pipelines/templates/jobs/cmake-generate.tests.yml b/eng/pipelines/templates/jobs/cmake-generate.tests.yml index 46d4149343..67c0382ae8 100644 --- a/eng/pipelines/templates/jobs/cmake-generate.tests.yml +++ b/eng/pipelines/templates/jobs/cmake-generate.tests.yml @@ -92,3 +92,5 @@ jobs: GenerateArgs: ${{ cmakeOption.Value }} Env: "$(CmakeEnvArg)" PackageName: ${{ artifact.Name }} + + - template: /eng/pipelines/templates/steps/show-failure-logs.yml diff --git a/eng/pipelines/templates/jobs/live.tests.yml b/eng/pipelines/templates/jobs/live.tests.yml index f3c1479de8..01efcb2925 100644 --- a/eng/pipelines/templates/jobs/live.tests.yml +++ b/eng/pipelines/templates/jobs/live.tests.yml @@ -125,6 +125,8 @@ jobs: BuildArgs: "$(BuildArgs)" Env: "$(CmakeEnvArg)" + - template: /eng/pipelines/templates/steps/show-failure-logs.yml + - template: /eng/common/TestResources/build-test-resource-config.yml parameters: SubscriptionConfiguration: ${{ parameters.CloudConfig.SubscriptionConfiguration }} diff --git a/eng/pipelines/templates/steps/cmake-generate.yml b/eng/pipelines/templates/steps/cmake-generate.yml index 124b869fe4..1d471284f4 100644 --- a/eng/pipelines/templates/steps/cmake-generate.yml +++ b/eng/pipelines/templates/steps/cmake-generate.yml @@ -24,6 +24,8 @@ steps: env: VCPKG_BINARY_SOURCES: $(VCPKG_BINARY_SOURCES_SECRET) + # The calling job will attempt to upload logs on failure. To that end this + # step should ONLY run on success. - script: rm -rf build workingDirectory: ${{ parameters.CmakeGeneratePath }} displayName: clean build folder for ${{ parameters.PackageName }} diff --git a/eng/pipelines/templates/steps/show-failure-logs.yml b/eng/pipelines/templates/steps/show-failure-logs.yml new file mode 100644 index 0000000000..9d257a778e --- /dev/null +++ b/eng/pipelines/templates/steps/show-failure-logs.yml @@ -0,0 +1,6 @@ +steps: + - task: PowerShell@2 + condition: failed() + displayName: Show build failure logs + inputs: + filePath: eng/scripts/Show-FailureLogs.ps1 diff --git a/eng/scripts/Show-FailureLogs.ps1 b/eng/scripts/Show-FailureLogs.ps1 new file mode 100644 index 0000000000..d2ec123b0d --- /dev/null +++ b/eng/scripts/Show-FailureLogs.ps1 @@ -0,0 +1,25 @@ +# Only show contents of particular vcpkg log files whose potentially sensitive +# information will be redacted by DevOps (if it's included). + +# Before adding other expressions to output ensure that those logs will not +# contain sensitive information or that DevOps is properly configured to remove +# sensitive information. + +$logFiles = Get-ChildItem -Recurse -Filter *.log +$filteredLogs = $logFiles.Where({ $_.Name -in ('vcpkg-bootstrap.log', 'vcpkg-manifest-install.log') }) + +if (!$filteredLogs) { + Write-Host "No logs found" + exit 0 +} + +foreach ($logFile in $filteredLogs) +{ + Write-Host "//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////" + Write-Host "==============================================================================================================================" + Write-Host "Log file: $logFile" + Write-Host "==============================================================================================================================" + Get-Content $logFile | Write-Host +} + +exit 0 \ No newline at end of file