@@ -126,13 +126,37 @@ jobs:
126126 uses : actions/cache/restore@v4
127127 with :
128128 path : ${{ github.workspace }}\vcpkg-bincache
129- key : vcpkg-bincache-${{ runner.os }}-msvc${{ steps.vcpkg_key.outputs.msvc }}-baseline${{ steps.vcpkg_key.outputs.baseline }}-${{ steps.vcpkg_key.outputs.triplet }}
129+ key : vcpkg-bincache-v2- ${{ runner.os }}-msvc${{ steps.vcpkg_key.outputs.msvc }}-baseline${{ steps.vcpkg_key.outputs.baseline }}-${{ steps.vcpkg_key.outputs.triplet }}
130130 restore-keys : |
131- vcpkg-bincache-${{ runner.os }}-msvc${{ steps.vcpkg_key.outputs.msvc }}-baseline${{ steps.vcpkg_key.outputs.baseline }}-
131+ vcpkg-bincache-v2-${{ runner.os }}-msvc${{ steps.vcpkg_key.outputs.msvc }}-baseline${{ steps.vcpkg_key.outputs.baseline }}-
132+ vcpkg-bincache-v2-${{ runner.os }}-
132133
133134 - name : Setup vcpkg
134135 uses : lukka/run-vcpkg@v11
135136
137+ - name : Validate vcpkg cache not empty
138+ if : startsWith(inputs.preset, 'win32')
139+ id : vcpkg_cache_validate
140+ shell : pwsh
141+ run : |
142+ $dir = "${{ github.workspace }}\vcpkg-bincache"
143+ if (!(Test-Path $dir)) {
144+ Write-Host "Cache directory does not exist" -ForegroundColor Yellow
145+ "valid=false" >> $env:GITHUB_OUTPUT
146+ exit 0
147+ }
148+ $files = Get-ChildItem $dir -Recurse -File -ErrorAction SilentlyContinue
149+ $bytes = ($files | Measure-Object Length -Sum).Sum
150+ Write-Host "vcpkg-bincache: $($files.Count) files, $([math]::Round($bytes / 1MB, 2)) MB" -ForegroundColor Cyan
151+ # Consider cache invalid if less than 1MB (empty or nearly empty)
152+ if ($bytes -lt 1048576) {
153+ Write-Host "Cache is too small (< 1MB), treating as invalid" -ForegroundColor Yellow
154+ "valid=false" >> $env:GITHUB_OUTPUT
155+ } else {
156+ Write-Host "Cache appears valid" -ForegroundColor Green
157+ "valid=true" >> $env:GITHUB_OUTPUT
158+ }
159+
136160 - name : Force vcpkg binary cache directory
137161 shell : pwsh
138162 run : |
@@ -200,17 +224,19 @@ jobs:
200224 shell : pwsh
201225 run : |
202226 Write-Host "vcpkg_cache.cache-hit='${{ steps.vcpkg_cache.outputs.cache-hit }}'" -ForegroundColor Cyan
227+ Write-Host "vcpkg_cache_validate.valid='${{ steps.vcpkg_cache_validate.outputs.valid }}'" -ForegroundColor Cyan
203228 Write-Host "vcpkg_key.msvc='${{ steps.vcpkg_key.outputs.msvc }}'" -ForegroundColor Cyan
204229 Write-Host "vcpkg_key.baseline='${{ steps.vcpkg_key.outputs.baseline }}'" -ForegroundColor Cyan
205230 Write-Host "vcpkg_key.triplet='${{ steps.vcpkg_key.outputs.triplet }}'" -ForegroundColor Cyan
206231 Write-Host "github.ref='${{ github.ref }}'" -ForegroundColor Cyan
207232
208233 - name : Save vcpkg binary cache
209- # Only save if cache was not hit AND this is the designated job to save (prevents all 6 jobs from racing)
210- # We use Generals + win32-vcpkg-debug as the "designated saver" since it's deterministic and always runs
234+ # Save if:
235+ # 1. Cache was not hit OR cache is invalid (empty/small)
236+ # 2. This is the designated job (Generals + win32-vcpkg-debug) to prevent all 6 jobs from racing
211237 # All other jobs will benefit from the cache once it's saved by this job
212- if : ${{ always() && startsWith(inputs.preset, 'win32') && steps.vcpkg_cache.outputs.cache-hit != 'true' && inputs.game == 'Generals' && inputs.preset == 'win32-vcpkg-debug' }}
238+ if : ${{ always() && startsWith(inputs.preset, 'win32') && ( steps.vcpkg_cache.outputs.cache-hit != 'true' || steps.vcpkg_cache_validate.outputs.valid != 'true') && inputs.game == 'Generals' && inputs.preset == 'win32-vcpkg-debug' }}
213239 uses : actions/cache/save@v4
214240 with :
215241 path : ${{ github.workspace }}\vcpkg-bincache
216- key : vcpkg-bincache-${{ runner.os }}-msvc${{ steps.vcpkg_key.outputs.msvc }}-baseline${{ steps.vcpkg_key.outputs.baseline }}-${{ steps.vcpkg_key.outputs.triplet }}
242+ key : vcpkg-bincache-v2- ${{ runner.os }}-msvc${{ steps.vcpkg_key.outputs.msvc }}-baseline${{ steps.vcpkg_key.outputs.baseline }}-${{ steps.vcpkg_key.outputs.triplet }}
0 commit comments