From 158af47d96e692b00f9da6ba6132f72f39b4ec41 Mon Sep 17 00:00:00 2001 From: IhateTrains Date: Fri, 5 Jul 2024 08:31:25 +0100 Subject: [PATCH] Integration tests cleanup: Remove-ItemWithRetry (#2040) --- .github/workflows/integration_tests.yml | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/.github/workflows/integration_tests.yml b/.github/workflows/integration_tests.yml index 2aed75928..7d1c2f24d 100644 --- a/.github/workflows/integration_tests.yml +++ b/.github/workflows/integration_tests.yml @@ -58,4 +58,26 @@ jobs: - name: "Cleanup" if: always() run: | - Get-ChildItem -Path $Env:GITHUB_WORKSPACE -Recurse -Force | Remove-Item -force -recurse + function Remove-ItemWithRetry { + param ( + [string]$Path, + [int]$Retries = 5, + [int]$Delay = 2000 + ) + for ($i = 0; $i -lt $Retries; $i++) { + try { + Remove-Item -Path $Path -Force -Recurse + Write-Host "Successfully deleted $Path" + return + } catch { + Write-Host "Attempt $($i+1) failed: $_" + Start-Sleep -Milliseconds $Delay + } + } + throw "Failed to delete $Path after $Retries attempts" + } + + Get-ChildItem -Path $Env:GITHUB_WORKSPACE -Recurse -Force | ForEach-Object { + Remove-ItemWithRetry -Path $_.FullName + } +