Skip to content

Commit 1efd1ff

Browse files
committed
ci(vcpkg): Move cache key computation after VC2022 setup and only save cache on main branch
1 parent 445110a commit 1efd1ff

File tree

1 file changed

+28
-39
lines changed

1 file changed

+28
-39
lines changed

.github/workflows/build-toolchain.yml

Lines changed: 28 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -39,44 +39,6 @@ jobs:
3939
- name: Checkout Code
4040
uses: actions/checkout@v4
4141

42-
- name: Compute vcpkg cache key parts
43-
id: vcpkg_key
44-
shell: pwsh
45-
run: |
46-
$baseline = (Get-Content vcpkg.json | ConvertFrom-Json)."builtin-baseline"
47-
48-
# Try to get MSVC version - check VCToolsVersion first, then try cl.exe
49-
$msvc = $env:VCToolsVersion
50-
if (-not $msvc) {
51-
try {
52-
$clOutput = cl.exe 2>&1 | Out-String
53-
if ($clOutput -match "Version (\d+\.\d+\.\d+\.\d+)") {
54-
$msvc = $matches[1]
55-
}
56-
} catch {
57-
# Compiler not available yet, will be detected after VC2022 setup
58-
}
59-
}
60-
if (-not $msvc) { $msvc = "unknown" }
61-
62-
$triplet = "x86-windows"
63-
if ("${{ inputs.preset }}" -like "x64*") { $triplet = "x64-windows" }
64-
65-
"baseline=$baseline" >> $env:GITHUB_OUTPUT
66-
"msvc=$msvc" >> $env:GITHUB_OUTPUT
67-
"triplet=$triplet" >> $env:GITHUB_OUTPUT
68-
Write-Host "vcpkg cache key parts: baseline=$baseline, msvc=$msvc, triplet=$triplet"
69-
70-
- name: Restore vcpkg binary cache
71-
id: vcpkg_cache
72-
uses: actions/cache/restore@v4
73-
with:
74-
path: ${{ github.workspace }}\vcpkg-bincache
75-
key: vcpkg-bincache-${{ runner.os }}-msvc${{ steps.vcpkg_key.outputs.msvc }}-baseline${{ steps.vcpkg_key.outputs.baseline }}-${{ steps.vcpkg_key.outputs.triplet }}
76-
restore-keys: |
77-
vcpkg-bincache-${{ runner.os }}-msvc${{ steps.vcpkg_key.outputs.msvc }}-baseline${{ steps.vcpkg_key.outputs.baseline }}-
78-
vcpkg-bincache-${{ runner.os }}-
79-
8042
- name: Cache VC6 Installation
8143
if: startsWith(inputs.preset, 'vc6')
8244
id: cache-vc6
@@ -141,6 +103,33 @@ jobs:
141103
with:
142104
arch: x86
143105

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+
123+
- name: Restore vcpkg binary cache
124+
if: startsWith(inputs.preset, 'win32')
125+
id: vcpkg_cache
126+
uses: actions/cache/restore@v4
127+
with:
128+
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 }}
130+
restore-keys: |
131+
vcpkg-bincache-${{ runner.os }}-msvc${{ steps.vcpkg_key.outputs.msvc }}-baseline${{ steps.vcpkg_key.outputs.baseline }}-
132+
144133
- name: Setup vcpkg
145134
uses: lukka/run-vcpkg@v11
146135

@@ -182,7 +171,7 @@ jobs:
182171
cmake --build --preset ${{ inputs.preset }}
183172
184173
- name: Save vcpkg binary cache
185-
if: steps.vcpkg_cache.outputs.cache-hit != 'true'
174+
if: startsWith(inputs.preset, 'win32') && steps.vcpkg_cache.outputs.cache-hit != 'true' && github.ref == 'refs/heads/main'
186175
uses: actions/cache/save@v4
187176
with:
188177
path: ${{ github.workspace }}\vcpkg-bincache

0 commit comments

Comments
 (0)