From 63b253077d084ae90eaaddea3f5b361562602460 Mon Sep 17 00:00:00 2001 From: Chuck Walbourn Date: Fri, 9 Oct 2026 10:37:08 -0700 Subject: [PATCH] GHA update for in-use handling --- .github/workflows/arm64.yml | 4 +-- .github/workflows/clangcl.yml | 10 +++--- .github/workflows/main.yml | 6 ++-- .github/workflows/test.yml | 12 +++---- .github/workflows/uwp.yml | 4 +-- .github/workflows/win10.yml | 12 +++---- build/PurgeFolder.ps1 | 59 +++++++++++++++++++++++++++++++++++ 7 files changed, 83 insertions(+), 24 deletions(-) create mode 100644 build/PurgeFolder.ps1 diff --git a/.github/workflows/arm64.yml b/.github/workflows/arm64.yml index 7ea8910c..5064f072 100644 --- a/.github/workflows/arm64.yml +++ b/.github/workflows/arm64.yml @@ -47,7 +47,7 @@ jobs: build_type: [arm64-Debug, arm64-Release, arm64-Debug-UWP, arm64-Release-UWP] steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: 'Install Ninja' run: choco install ninja @@ -66,7 +66,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 (DLL)' working-directory: ${{ github.workspace }} diff --git a/.github/workflows/clangcl.yml b/.github/workflows/clangcl.yml index b8085fb7..3ff7fa1d 100644 --- a/.github/workflows/clangcl.yml +++ b/.github/workflows/clangcl.yml @@ -57,10 +57,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/directxtktest path: Tests @@ -84,7 +84,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 (DLL)' working-directory: ${{ github.workspace }} @@ -116,7 +116,7 @@ jobs: arch: amd64_arm64 steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: 'Install Ninja' run: choco install ninja @@ -135,7 +135,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 (DLL)' working-directory: ${{ github.workspace }} diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a1dadb62..01459d82 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -80,7 +80,7 @@ jobs: arch: amd64_x86 steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: 'Install Ninja' run: choco install ninja @@ -100,7 +100,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 (Spectre)' working-directory: ${{ github.workspace }} @@ -112,7 +112,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 (DLL)' working-directory: ${{ github.workspace }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7d5ef21b..1cba6d90 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -75,10 +75,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/directxtktest path: Tests @@ -109,7 +109,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 (DLL)' working-directory: ${{ github.workspace }} @@ -146,10 +146,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/directxtktest path: Tests @@ -179,7 +179,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 (DLL)' working-directory: ${{ github.workspace }} diff --git a/.github/workflows/uwp.yml b/.github/workflows/uwp.yml index 9fc07e70..1d65a1bc 100644 --- a/.github/workflows/uwp.yml +++ b/.github/workflows/uwp.yml @@ -65,7 +65,7 @@ jobs: arch: amd64_arm64 steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: 'Install Ninja' run: choco install ninja @@ -85,7 +85,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 (DLL)' working-directory: ${{ github.workspace }} diff --git a/.github/workflows/win10.yml b/.github/workflows/win10.yml index c69d702a..8605685e 100644 --- a/.github/workflows/win10.yml +++ b/.github/workflows/win10.yml @@ -74,7 +74,7 @@ jobs: arch: amd64_arm64 steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: 'Install Ninja' run: choco install ninja @@ -94,7 +94,7 @@ jobs: - name: 'Clean up' working-directory: ${{ github.workspace }} - run: Remove-Item -Path out -Recurse -Force + run: .\build\PurgeFolder.ps1 -Path out - if: matrix.arch != 'amd64_arm64' name: 'Configure CMake (Spectre)' @@ -109,7 +109,7 @@ jobs: - if: matrix.arch != 'amd64_arm64' name: 'Clean up' working-directory: ${{ github.workspace }} - run: Remove-Item -Path out -Recurse -Force + run: .\build\PurgeFolder.ps1 -Path out - name: 'Configure CMake (DLL)' working-directory: ${{ github.workspace }} @@ -139,7 +139,7 @@ jobs: arch: amd64_arm64 steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - name: 'Install Ninja' run: choco install ninja @@ -158,7 +158,7 @@ jobs: - name: 'Clean up' working-directory: ${{ github.workspace }} - run: Remove-Item -Path out -Recurse -Force + run: .\build\PurgeFolder.ps1 -Path out - if: matrix.arch != 'amd64_arm64' name: 'Configure CMake (Spectre)' @@ -173,7 +173,7 @@ jobs: - if: matrix.arch != 'amd64_arm64' name: 'Clean up' working-directory: ${{ github.workspace }} - run: Remove-Item -Path out -Recurse -Force + run: .\build\PurgeFolder.ps1 -Path out - name: 'Configure CMake (DLL)' working-directory: ${{ github.workspace }} diff --git a/build/PurgeFolder.ps1 b/build/PurgeFolder.ps1 new file mode 100644 index 00000000..def04b40 --- /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 + } +}