Skip to content

Commit 4adbf76

Browse files
committed
ci(vcpkg): Add MSVC version to cache key, restore-keys fallbacks, and prevent lukka/run-vcpkg cache conflicts
1 parent 7e94310 commit 4adbf76

File tree

1 file changed

+51
-18
lines changed

1 file changed

+51
-18
lines changed

.github/workflows/build-toolchain.yml

Lines changed: 51 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ jobs:
3131
name: ${{ inputs.preset }}${{ inputs.tools && '+t' || '' }}${{ inputs.extras && '+e' || '' }}
3232
runs-on: windows-2022
3333
timeout-minutes: 30
34+
3435
env:
3536
VCPKG_FILE_CACHE: ${{ github.workspace }}\vcpkg-bincache
3637
VCPKG_BINARY_SOURCES: clear;files,${{ github.workspace }}\vcpkg-bincache,readwrite
3738
VCPKG_FEATURE_FLAGS: manifests,versions,binarycaching
39+
3840
steps:
3941
- name: Checkout Code
4042
uses: actions/checkout@v4
@@ -82,13 +84,11 @@ jobs:
8284
if: startsWith(inputs.preset, 'vc6')
8385
shell: pwsh
8486
run: |
85-
# Define the base directories as local variables first
8687
$VSCommonDir = "C:\VC6\VC6SP6\Common"
8788
$MSDevDir = "C:\VC6\VC6SP6\Common\msdev98"
8889
$MSVCDir = "C:\VC6\VC6SP6\VC98"
8990
$VcOsDir = "WINNT"
9091
91-
# Set the variables in GitHub environment
9292
"VSCommonDir=$VSCommonDir" >> $env:GITHUB_ENV
9393
"MSDevDir=$MSDevDir" >> $env:GITHUB_ENV
9494
"MSVCDir=$MSVCDir" >> $env:GITHUB_ENV
@@ -103,34 +103,65 @@ 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+
113+
$msvc = $env:VCToolsVersion
114+
if (-not $msvc) { $msvc = "unknown" }
115+
116+
# Reduce churn: keep major.minor (e.g. 14.44)
117+
$msvcMajorMinor = ($msvc -split '\.')[0..1] -join '.'
118+
119+
$triplet = "x86-windows"
120+
if ("${{ inputs.preset }}" -like "x64*") { $triplet = "x64-windows" }
121+
122+
"baseline=$baseline" >> $env:GITHUB_OUTPUT
123+
"msvc=$msvcMajorMinor" >> $env:GITHUB_OUTPUT
124+
"triplet=$triplet" >> $env:GITHUB_OUTPUT
125+
126+
Write-Host "vcpkg cache key parts: baseline=$baseline, msvc=$msvcMajorMinor, triplet=$triplet"
127+
106128
- name: Restore vcpkg binary cache
107129
if: startsWith(inputs.preset, 'win32')
108130
id: vcpkg_cache
109131
uses: actions/cache/restore@v4
110132
with:
111133
path: ${{ github.workspace }}\vcpkg-bincache
112-
key: vcpkg-bincache-${{ runner.os }}-${{ hashFiles('vcpkg.json') }}-${{ inputs.preset }}
134+
key: vcpkg-bincache-v2-${{ runner.os }}-msvc${{ steps.vcpkg_key.outputs.msvc }}-baseline${{ steps.vcpkg_key.outputs.baseline }}-${{ steps.vcpkg_key.outputs.triplet }}
135+
restore-keys: |
136+
vcpkg-bincache-v2-${{ runner.os }}-msvc${{ steps.vcpkg_key.outputs.msvc }}-baseline${{ steps.vcpkg_key.outputs.baseline }}-
137+
vcpkg-bincache-v2-${{ runner.os }}-
113138
114139
- name: Setup vcpkg
115140
uses: lukka/run-vcpkg@v11
141+
with:
142+
runVcpkgInstall: false
143+
doNotCache: true
116144

117145
- name: Configure vcpkg to use cached directory
118146
if: startsWith(inputs.preset, 'win32')
119147
shell: pwsh
120148
run: |
121149
$cacheDir = "${{ github.workspace }}\vcpkg-bincache"
122150
New-Item -ItemType Directory -Force -Path $cacheDir | Out-Null
151+
152+
# lukka/run-vcpkg sets its own temp cache dir; override to force our cached dir
123153
$env:VCPKG_DEFAULT_BINARY_CACHE = $cacheDir
124154
$env:VCPKG_BINARY_SOURCES = "clear;files,$cacheDir,readwrite"
155+
125156
"VCPKG_DEFAULT_BINARY_CACHE=$cacheDir" >> $env:GITHUB_ENV
126157
"VCPKG_BINARY_SOURCES=$env:VCPKG_BINARY_SOURCES" >> $env:GITHUB_ENV
127158
128159
- name: Configure ${{ inputs.game }} with CMake Using ${{ inputs.preset }}${{ inputs.tools && '+t' || '' }}${{ inputs.extras && '+e' || '' }} Preset
129160
shell: pwsh
130161
run: |
131162
$buildFlags = @(
132-
"-DRTS_BUILD_ZEROHOUR=${{ inputs.game == 'GeneralsMD' && 'ON' || 'OFF' }}",
133-
"-DRTS_BUILD_GENERALS=${{ inputs.game == 'Generals' && 'ON' || 'OFF' }}"
163+
"-DRTS_BUILD_ZEROHOUR=${{ inputs.game == 'GeneralsMD' && 'ON' || 'OFF' }}",
164+
"-DRTS_BUILD_GENERALS=${{ inputs.game == 'Generals' && 'ON' || 'OFF' }}"
134165
)
135166
136167
$gamePrefix = "${{ inputs.game == 'Generals' && 'GENERALS' || 'ZEROHOUR' }}"
@@ -140,27 +171,36 @@ jobs:
140171
$buildFlags += "-DRTS_BUILD_${gamePrefix}_EXTRAS=${{ inputs.extras && 'ON' || 'OFF' }}"
141172
142173
Write-Host "Build flags: $($buildFlags -join ' | ')"
143-
144174
cmake --preset ${{ inputs.preset }} $buildFlags
145175
146176
- name: Build ${{ inputs.game }} with CMake Using ${{ inputs.preset }}${{ inputs.tools && '+t' || '' }}${{ inputs.extras && '+e' || '' }} Preset
147177
shell: pwsh
148178
run: |
149179
cmake --build --preset ${{ inputs.preset }}
150180
181+
- name: Save vcpkg binary cache
182+
# Only one job should save to avoid "Unable to reserve cache" conflicts.
183+
if: ${{ startsWith(inputs.preset, 'win32') && steps.vcpkg_cache.outputs.cache-hit != 'true' && inputs.game == 'Generals' && inputs.preset == 'win32-vcpkg-debug' }}
184+
uses: actions/cache/save@v4
185+
with:
186+
path: ${{ github.workspace }}\vcpkg-bincache
187+
key: vcpkg-bincache-v2-${{ runner.os }}-msvc${{ steps.vcpkg_key.outputs.msvc }}-baseline${{ steps.vcpkg_key.outputs.baseline }}-${{ steps.vcpkg_key.outputs.triplet }}
188+
151189
- name: Collect ${{ inputs.game }} ${{ inputs.preset }}${{ inputs.tools && '+t' || '' }}${{ inputs.extras && '+e' || '' }} Artifact
152190
shell: pwsh
153191
run: |
154192
$buildDir = "build\${{ inputs.preset }}"
155193
$artifactsDir = New-Item -ItemType Directory -Force -Path "$buildDir\${{ inputs.game }}\artifacts" -Verbose
156194
157-
if ("${{ inputs.preset }}" -like "win32*") {
158-
# For win32 preset, look in config-specific subdirectories
195+
if ("${{ inputs.preset }}" -like "win32*") {
159196
$configToUse = if ("${{ inputs.preset }}" -match "debug") { "Debug" } else { "Release" }
160-
$files = Get-ChildItem -Path "$buildDir\Core\$configToUse","$buildDir\${{ inputs.game }}\$configToUse" -File | Where-Object { $_.Extension -in @(".exe", ".dll", ".pdb") } -Verbose
161-
} else {
162-
$files = Get-ChildItem -Path "$buildDir\Core","$buildDir\${{ inputs.game }}" -File | Where-Object { $_.Extension -in @(".exe", ".dll", ".pdb") } -Verbose
197+
$files = Get-ChildItem -Path "$buildDir\Core\$configToUse","$buildDir\${{ inputs.game }}\$configToUse" -File |
198+
Where-Object { $_.Extension -in @(".exe", ".dll", ".pdb") } -Verbose
199+
} else {
200+
$files = Get-ChildItem -Path "$buildDir\Core","$buildDir\${{ inputs.game }}" -File |
201+
Where-Object { $_.Extension -in @(".exe", ".dll", ".pdb") } -Verbose
163202
}
203+
164204
$files | Move-Item -Destination $artifactsDir -Verbose -Force
165205
166206
- name: Upload ${{ inputs.game }} ${{ inputs.preset }}${{ inputs.tools && '+t' || '' }}${{ inputs.extras && '+e' || '' }} Artifact
@@ -170,10 +210,3 @@ jobs:
170210
path: build\${{ inputs.preset }}\${{ inputs.game }}\artifacts
171211
retention-days: 30
172212
if-no-files-found: error
173-
174-
- name: Save vcpkg binary cache
175-
if: ${{ always() && startsWith(inputs.preset, 'win32') && steps.vcpkg_cache.outputs.cache-hit != 'true' && inputs.game == 'Generals' && inputs.preset == 'win32-vcpkg-debug' }}
176-
uses: actions/cache/save@v4
177-
with:
178-
path: ${{ github.workspace }}\vcpkg-bincache
179-
key: vcpkg-bincache-${{ runner.os }}-${{ hashFiles('vcpkg.json') }}-${{ inputs.preset }}

0 commit comments

Comments
 (0)