From 31939dfd87689e689a1c894f88338c9b9eb49fd5 Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Fri, 9 Oct 2026 10:42:16 -0700 Subject: [PATCH] GHA update for in-use handling --- .github/workflows/cxx.yml | 10 +++---- build/PurgeFolder.ps1 | 59 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 build/PurgeFolder.ps1 diff --git a/.github/workflows/cxx.yml b/.github/workflows/cxx.yml index 57bd2fa..b6b639d 100644 --- a/.github/workflows/cxx.yml +++ b/.github/workflows/cxx.yml @@ -61,10 +61,10 @@ jobs: arch: amd64_arm64 steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: Clone test repository - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: repository: walbourn/directxmathtest path: Tests @@ -87,7 +87,7 @@ jobs: - name: 'Clean up' working-directory: ${{ github.workspace }} - run: Remove-Item -Path out -Recurse -Force + run: .\build\PurgeFolder.ps1 -Path out - name: 'Configure CMake (C++11)' working-directory: ${{ github.workspace }} @@ -99,7 +99,7 @@ jobs: - name: 'Clean up' working-directory: ${{ github.workspace }} - run: Remove-Item -Path out -Recurse -Force + run: .\build\PurgeFolder.ps1 -Path out - name: 'Configure CMake (C++14)' working-directory: ${{ github.workspace }} @@ -111,7 +111,7 @@ jobs: - name: 'Clean up' working-directory: ${{ github.workspace }} - run: Remove-Item -Path out -Recurse -Force + run: .\build\PurgeFolder.ps1 -Path out - name: 'Configure CMake (C++20)' working-directory: ${{ github.workspace }} diff --git a/build/PurgeFolder.ps1 b/build/PurgeFolder.ps1 new file mode 100644 index 0000000..def04b4 --- /dev/null +++ b/build/PurgeFolder.ps1 @@ -0,0 +1,59 @@ +<# +.SYNOPSIS + Purges a folder once it is no longer locked. + +.DESCRIPTION + Continuously attempts to remove the specified folder. If the folder + is locked or in use, the script waits for a configurable interval and + retries until either the folder is removed or a timeout is reached. + +.PARAMETER Path + The folder to remove. + +.PARAMETER RetrySeconds + Number of seconds to wait between retry attempts. + +.PARAMETER TimeoutSeconds + Maximum number of seconds to wait before giving up. + +.EXAMPLE + .\PurgeFolder.ps1 -Path "C:\Temp\MyFolder" -Verbose +#> + +[CmdletBinding()] +param( + [Parameter(Mandatory = $true, Position = 0)] + [ValidateNotNullOrEmpty()] + [string]$Path, + + [Parameter()] + [ValidateRange(1, 86400)] + [int]$RetrySeconds = 5, + + [Parameter()] + [ValidateRange(1, 86400)] + [int]$TimeoutSeconds = 300 +) + +if (-not (Test-Path -LiteralPath $Path -PathType Container)) { + throw "'$Path' does not exist or is not a folder." +} + +$stopTime = (Get-Date).AddSeconds($TimeoutSeconds) + +while (Test-Path -LiteralPath $Path -PathType Container) { + + if ((Get-Date) -gt $stopTime) { + throw "Timed out waiting for folder '$Path' to become available after $TimeoutSeconds seconds." + } + + try { + Remove-Item -LiteralPath $Path -Recurse -Force -ErrorAction Stop + + Write-Verbose "Successfully purged folder '$Path'." + } + catch { + Write-Verbose "Folder is locked or in use. Retrying in $RetrySeconds second(s)..." + Start-Sleep -Seconds $RetrySeconds + } +}