From a274f9e3ec42d5bb5c9d20410de23aed1cc31fbf Mon Sep 17 00:00:00 2001 From: Seweryn Presnal Date: Fri, 5 Jul 2024 09:29:39 +0200 Subject: [PATCH] Integration tests cleanup: Remove-ItemWithRetry --- .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 + } +