Skip to content

Commit 7e94310

Browse files
committed
ci(vcpkg): Simplify cache fix - only essential changes
1 parent 86cb2f1 commit 7e94310

File tree

1 file changed

+4
-67
lines changed

1 file changed

+4
-67
lines changed

.github/workflows/build-toolchain.yml

Lines changed: 4 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -103,75 +103,27 @@ jobs:
103103
with:
104104
arch: x86
105105

106-
- name: Compute vcpkg cache key parts
107-
if: startsWith(inputs.preset, 'win32')
108-
id: vcpkg_key
109-
shell: pwsh
110-
run: |
111-
$baseline = (Get-Content vcpkg.json | ConvertFrom-Json)."builtin-baseline"
112-
$msvc = $env:VCToolsVersion
113-
if (-not $msvc) { $msvc = "unknown" }
114-
115-
$triplet = "x86-windows"
116-
if ("${{ inputs.preset }}" -like "x64*") { $triplet = "x64-windows" }
117-
118-
"baseline=$baseline" >> $env:GITHUB_OUTPUT
119-
"msvc=$msvc" >> $env:GITHUB_OUTPUT
120-
"triplet=$triplet" >> $env:GITHUB_OUTPUT
121-
Write-Host "vcpkg cache key parts: baseline=$baseline, msvc=$msvc, triplet=$triplet"
122-
123106
- name: Restore vcpkg binary cache
124107
if: startsWith(inputs.preset, 'win32')
125108
id: vcpkg_cache
126109
uses: actions/cache/restore@v4
127110
with:
128111
path: ${{ github.workspace }}\vcpkg-bincache
129-
key: vcpkg-bincache-v2-${{ runner.os }}-msvc${{ steps.vcpkg_key.outputs.msvc }}-baseline${{ steps.vcpkg_key.outputs.baseline }}-${{ steps.vcpkg_key.outputs.triplet }}
130-
restore-keys: |
131-
vcpkg-bincache-v2-${{ runner.os }}-msvc${{ steps.vcpkg_key.outputs.msvc }}-baseline${{ steps.vcpkg_key.outputs.baseline }}-
132-
vcpkg-bincache-v2-${{ runner.os }}-
112+
key: vcpkg-bincache-${{ runner.os }}-${{ hashFiles('vcpkg.json') }}-${{ inputs.preset }}
133113

134114
- name: Setup vcpkg
135115
uses: lukka/run-vcpkg@v11
136116

137-
- name: Validate vcpkg cache not empty
117+
- name: Configure vcpkg to use cached directory
138118
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-
160-
- name: Force vcpkg binary cache directory
161119
shell: pwsh
162120
run: |
163-
# Override VCPKG_DEFAULT_BINARY_CACHE that lukka/run-vcpkg sets to its own temp dir
164-
# This ensures vcpkg uses our cached directory instead
165121
$cacheDir = "${{ github.workspace }}\vcpkg-bincache"
166-
# Ensure the cache directory exists (cache restore may not create it on miss)
167122
New-Item -ItemType Directory -Force -Path $cacheDir | Out-Null
168123
$env:VCPKG_DEFAULT_BINARY_CACHE = $cacheDir
169124
$env:VCPKG_BINARY_SOURCES = "clear;files,$cacheDir,readwrite"
170125
"VCPKG_DEFAULT_BINARY_CACHE=$cacheDir" >> $env:GITHUB_ENV
171126
"VCPKG_BINARY_SOURCES=$env:VCPKG_BINARY_SOURCES" >> $env:GITHUB_ENV
172-
Write-Host "Forced vcpkg binary cache to: $cacheDir" -ForegroundColor Cyan
173-
Write-Host "VCPKG_DEFAULT_BINARY_CACHE=$env:VCPKG_DEFAULT_BINARY_CACHE" -ForegroundColor Gray
174-
Write-Host "VCPKG_BINARY_SOURCES=$env:VCPKG_BINARY_SOURCES" -ForegroundColor Gray
175127
176128
- name: Configure ${{ inputs.game }} with CMake Using ${{ inputs.preset }}${{ inputs.tools && '+t' || '' }}${{ inputs.extras && '+e' || '' }} Preset
177129
shell: pwsh
@@ -219,24 +171,9 @@ jobs:
219171
retention-days: 30
220172
if-no-files-found: error
221173

222-
- name: Debug vcpkg cache state
223-
if: ${{ always() && startsWith(inputs.preset, 'win32') }}
224-
shell: pwsh
225-
run: |
226-
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
228-
Write-Host "vcpkg_key.msvc='${{ steps.vcpkg_key.outputs.msvc }}'" -ForegroundColor Cyan
229-
Write-Host "vcpkg_key.baseline='${{ steps.vcpkg_key.outputs.baseline }}'" -ForegroundColor Cyan
230-
Write-Host "vcpkg_key.triplet='${{ steps.vcpkg_key.outputs.triplet }}'" -ForegroundColor Cyan
231-
Write-Host "github.ref='${{ github.ref }}'" -ForegroundColor Cyan
232-
233174
- name: Save vcpkg binary cache
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
237-
# All other jobs will benefit from the cache once it's saved by this job
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' }}
175+
if: ${{ always() && startsWith(inputs.preset, 'win32') && steps.vcpkg_cache.outputs.cache-hit != 'true' && inputs.game == 'Generals' && inputs.preset == 'win32-vcpkg-debug' }}
239176
uses: actions/cache/save@v4
240177
with:
241178
path: ${{ github.workspace }}\vcpkg-bincache
242-
key: vcpkg-bincache-v2-${{ runner.os }}-msvc${{ steps.vcpkg_key.outputs.msvc }}-baseline${{ steps.vcpkg_key.outputs.baseline }}-${{ steps.vcpkg_key.outputs.triplet }}
179+
key: vcpkg-bincache-${{ runner.os }}-${{ hashFiles('vcpkg.json') }}-${{ inputs.preset }}

0 commit comments

Comments
 (0)