ci: fix Windows workspace cleanup and fail-fast for git operations#3694
Draft
ci: fix Windows workspace cleanup and fail-fast for git operations#3694
Conversation
The cmd.exe "for /d" loop used to clean the workspace skips directory entries during deletion (enumerates and deletes in the same pass), leaving artifact output dirs from previous runs. When git clone then fails because the workspace isn't empty, $PSNativeCommandUseErrorActionPreference = $true is silently ignored on Windows PowerShell 5.1 (requires PS 7.3+), so the script continues without source code and phpize.bat fails with exit 10. Fixes: - Replace cmd.exe cleanup loop with PowerShell-native Get-ChildItem | Remove-Item which handles each entry independently and tolerates locked files - Add WARNING log line if any items could not be removed (aids debugging) - Remove $PSNativeCommandUseErrorActionPreference (no-op on PS 5.1) - Add explicit $LASTEXITCODE checks after git clone, checkout, and submodule init Applied to both generate-package.php (compile extension windows) and generate-tracer.php (windows test_c).
… cleanup PowerShell 5.1's Remove-Item -Recurse throws "mismatch between the tag specified in the request and the tag present in the reparse point" when the workspace contains Windows junction points (created by switch-php, e.g. /php <<===>> /php-nts) or NTFS symlinks (from core.symlinks=true git clone). This caused the entire cleanup to fail silently, leaving the full previous repo tree in place and making git clone fail again. Fix: navigate to the parent directory and run cmd.exe "rd /s /q" on the whole workspace directory. cmd.exe rd removes junction entries without following them into their targets, avoiding the reparse point issue entirely. The directory is then recreated empty before returning.
|
✨ Fix all issues with BitsAI or with Cursor
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3694 +/- ##
==========================================
- Coverage 62.32% 62.30% -0.02%
==========================================
Files 142 142
Lines 13586 13586
Branches 1775 1775
==========================================
- Hits 8467 8465 -2
- Misses 4311 4314 +3
+ Partials 808 807 -1 see 1 file with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Windows CI jobs (
compile extension windows,windows test_c) were intermittently failing with exit code 10 fromphpize.bat— specifically the errorMust be run from the root of the extension source.Root cause was two compounding bugs introduced in #3634 when switching to
GIT_STRATEGY: none+ manual clone:Bug 1 — Workspace cleanup fails silently, leaving leftover content
First attempt used
cmd.exe "for /d"loop which skips directory entries while iterating (deletes and enumerates in the same pass — well-known Windows antipattern). Leftover artifact dirs from prior runs (extensions_x86_64, etc.) survived.Second attempt switched to
Get-ChildItem | Remove-Item -Recurse, which throws"mismatch between the tag specified in the request and the tag present in the reparse point"on PowerShell 5.1 (Windows Server 2019 default) when the workspace contains Windows junction points (created byswitch-php, e.g./php <<===>> /php-nts) or NTFS symlinks (fromcore.symlinks=truegit clone). The entire cleanup silently fails, leaving the full previous repo tree in place.Fix: navigate to the parent directory and use
cmd.exe "rd /s /q"on the whole workspace, then recreate it empty.cmd.exe rdcorrectly removes junction entries without following them into their targets, avoiding the reparse point issue entirely.Bug 2 —
$PSNativeCommandUseErrorActionPreferenceis a no-op on PS 5.1The runner uses the
Shell (powershell)executor = Windows PowerShell 5.1 (default on Windows Server 2019).$PSNativeCommandUseErrorActionPreferencewas introduced in PowerShell 7.3 and is silently ignored on 5.1. So whengit clonefailed (non-empty workspace), the script continued without source code, started the Docker container with an empty mount, andphpize.batfailed.Fix: remove
$PSNativeCommandUseErrorActionPreference(misleading no-op) and add explicit$LASTEXITCODEchecks aftergit clone,git checkout, andgit submodule update— the only reliable fail-fast mechanism for native commands on PS 5.1.