diff --git a/.github/workflows/build-and-release.yml b/.github/workflows/build-and-release.yml index 7dfc8b00..94c67b90 100644 --- a/.github/workflows/build-and-release.yml +++ b/.github/workflows/build-and-release.yml @@ -88,6 +88,12 @@ jobs: # Dry-deployment check-command: | ./gradlew check :compiler-plugin:check :gradle-plugin:check --parallel + # Stop the Gradle Daemon on windows to try to prevent + # "The process cannot access the file because it is being used by another process" + if ${{ runner.os == 'Windows' }}; then + ./gradlew --stop + # powershell kill-windows-processes.ps1 + fi deploy-command: | NEXT_VERSION="${{ needs.staging-repo.outputs.next-version }}" OVERRIDE_VERSION=$([[ "$NEXT_VERSION" != "" ]] && echo "-PforceVersion=$(echo $NEXT_VERSION)" || echo "") diff --git a/kill-windows-processes.ps1 b/kill-windows-processes.ps1 new file mode 100755 index 00000000..2547cb7e --- /dev/null +++ b/kill-windows-processes.ps1 @@ -0,0 +1,22 @@ +$buildFolderPath = "build" + +function Get-LockingProcess { param ($filePath) + $handleOutput = &handle.exe $filePath 2>&1 + return if ($handleOutput -match "pid: (\d+)\s+") { [int]$matches[1] } else { $null } +} + +function Terminate-LockingProcess { param ($processId) + try { Stop-Process -Id $processId -Force; Write-Host "Terminated process with ID $processId." } + catch { Write-Host "Unable to terminate process with ID $processId." } +} + +Get-ChildItem -Path $buildFolderPath -File | ForEach-Object { + $lockingProcessId = Get-LockingProcess $_.FullName + if ($lockingProcessId) { + Terminate-LockingProcess $lockingProcessId + } else { + Write-Host "$($_.FullName) is not locked." + } +} + +Write-Host "Completed checking for locked files in $buildFolderPath."