From bd16ca8c9b05c886155c29bd957647e8b5845fbc Mon Sep 17 00:00:00 2001 From: Nicolas Schweitzer Date: Thu, 17 Oct 2024 19:39:45 +0200 Subject: [PATCH] fix(windows): Collapse junit section and prevent error (#30208) --- tasks/libs/common/utils.py | 3 ++- tasks/winbuildscripts/unittests.ps1 | 19 ++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/tasks/libs/common/utils.py b/tasks/libs/common/utils.py index 3b3afbc80c027..5fef10fd29cfc 100644 --- a/tasks/libs/common/utils.py +++ b/tasks/libs/common/utils.py @@ -532,7 +532,8 @@ def gitlab_section(section_name, collapsed=False, echo=False): """ - echo: If True, will echo the gitlab section in bold in CLI mode instead of not showing anything """ - section_id = section_name.replace(" ", "_").replace("/", "_") + # Replace with "_" every special character (" ", ":", "/", "\") which prevent the section generation + section_id = re.sub(r"[ :/\\]", "_", section_name) in_ci = running_in_gitlab_ci() try: if in_ci: diff --git a/tasks/winbuildscripts/unittests.ps1 b/tasks/winbuildscripts/unittests.ps1 index 5f4fc6a848b70..5285e6c9d86b4 100644 --- a/tasks/winbuildscripts/unittests.ps1 +++ b/tasks/winbuildscripts/unittests.ps1 @@ -55,8 +55,9 @@ if($err -ne 0){ [Environment]::Exit($err) } & inv -e test --junit-tar="$Env:JUNIT_TAR" --race --profile --rerun-fails=2 --coverage --cpus 8 --python-runtimes="$Env:PY_RUNTIMES" --python-home-2=$Env:Python2_ROOT_DIR --python-home-3=$Env:Python3_ROOT_DIR --save-result-json C:\mnt\$test_output_file $Env:EXTRA_OPTS --build-stdlib $TEST_WASHER_FLAG - -$err = $LASTEXITCODE +If ($LASTEXITCODE -ne "0") { + exit $LASTEXITCODE +} # Ignore upload failures $ErrorActionPreference = "Continue" @@ -65,10 +66,14 @@ $tmpfile = [System.IO.Path]::GetTempFileName() # 1. Upload coverage reports to Codecov & "$UT_BUILD_ROOT\tools\ci\fetch_secret.ps1" -parameterName "$Env:CODECOV_TOKEN" -tempFile "$tmpfile" If ($LASTEXITCODE -ne "0") { - exit $LASTEXITCODE + Write-Host "Failed to fetch CODECOV_TOKEN - ignoring" + exit "0" } $Env:CODECOV_TOKEN=$(cat "$tmpfile") & inv -e coverage.upload-to-codecov $Env:COVERAGE_CACHE_FLAG +if($LASTEXITCODE -ne "0"){ + Write-Host -ForegroundColor Red "coverage upload failed $err" +} # 2. Upload junit files # Copy test files to c:\mnt for further gitlab upload @@ -77,15 +82,15 @@ Get-ChildItem -Path "$UT_BUILD_ROOT" -Filter "junit-out-*.xml" -Recurse | ForEac } & "$UT_BUILD_ROOT\tools\ci\fetch_secret.ps1" -parameterName "$Env:API_KEY_ORG2" -tempFile "$tmpfile" If ($LASTEXITCODE -ne "0") { - exit $LASTEXITCODE + Write-Host "Failed to fetch API_KEY - ignoring" + exit "0" } $Env:DATADOG_API_KEY=$(cat "$tmpfile") Remove-Item "$tmpfile" & inv -e junit-upload --tgz-path $Env:JUNIT_TAR -if($err -ne 0){ - Write-Host -ForegroundColor Red "test failed $err" - [Environment]::Exit($err) +if($LASTEXITCODE -ne "0"){ + Write-Host -ForegroundColor Red "junit upload failed $err" } Write-Host Test passed \ No newline at end of file