Skip to content

Commit

Permalink
ci: stop the Gradle Daemon on Windows before deployment to prevent "T…
Browse files Browse the repository at this point in the history
…he process cannot access the file because it is being used by another process"
  • Loading branch information
DanySK committed Oct 19, 2024
1 parent 6a936b6 commit a9a92e6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/build-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 "")
Expand Down
22 changes: 22 additions & 0 deletions kill-windows-processes.ps1
Original file line number Diff line number Diff line change
@@ -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."

0 comments on commit a9a92e6

Please sign in to comment.