From fb5bbe8fd3d471cdcded03754bf1a0f7fd1c5666 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Trojnara?= Date: Thu, 5 Nov 2026 11:05:09 +0100 Subject: [PATCH] Save vcpkg archives before the build and prefer matching ones The combined actions/cache step saved the vcpkg archives only when the whole job succeeded. A failed Windows build therefore discarded a freshly built OpenSSL, and the next push rebuilt it again (6-9 minutes per architecture). Restore and save in separate steps, saving straight after vcpkg install. Also restore in two steps: a pull-request run searches all of its own keys before any base-branch cache, so the broad fallback could restore a stale PR archive even when master had one matching the current runner image and vcpkg revision. Accept only matching archives first, from any scope, and fall back to older ones only if none exists. --- .github/workflows/ci.yml | 38 ++++++++++++++++++++++++++++++------- .github/workflows/ci.yml.in | 38 ++++++++++++++++++++++++++++++------- 2 files changed, 62 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0ae0a685..5e4e0a28 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -199,20 +199,36 @@ jobs: steps: - uses: actions/checkout@v5 - - name: Prepare the vcpkg cache key - id: vcpkg-cache-key + - name: Identify vcpkg build inputs + id: vcpkg-inputs shell: pwsh run: | $revision = git -C "${{matrix.vcpkg_root}}" rev-parse HEAD - "value=$env:ImageVersion-$revision" >> $env:GITHUB_OUTPUT + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + "revision=$revision" >> $env:GITHUB_OUTPUT + "image=$env:ImageVersion" >> $env:GITHUB_OUTPUT + + # A PR run searches all of its own keys before any base-branch cache, so a + # broad fallback here would let a stale PR archive win over a matching one + # from master. Match the current build inputs in every scope first. + - name: Restore the vcpkg archives + id: vcpkg-cache + uses: actions/cache/restore@v5 + with: + path: C:/Users/runneradmin/AppData/Local/vcpkg/archives + key: ${{matrix.id}}-vcpkg-${{steps.vcpkg-inputs.outputs.image}}-${{steps.vcpkg-inputs.outputs.revision}}-${{hashFiles('.github/workflows/ci.yml.in')}} + restore-keys: | + ${{matrix.id}}-vcpkg-${{steps.vcpkg-inputs.outputs.image}}-${{steps.vcpkg-inputs.outputs.revision}}- + ${{matrix.id}}-vcpkg-${{steps.vcpkg-inputs.outputs.image}}- - - name: Cache the vcpkg archives - uses: actions/cache@v5 + # Older archives remain useful: vcpkg validates each package's ABI itself. + - name: Restore older vcpkg archives + if: steps.vcpkg-cache.outputs.cache-matched-key == '' + uses: actions/cache/restore@v5 with: path: C:/Users/runneradmin/AppData/Local/vcpkg/archives - key: ${{matrix.id}}-vcpkg-${{steps.vcpkg-cache-key.outputs.value}}-${{hashFiles('.github/workflows/ci.yml.in')}} + key: ${{matrix.id}}-vcpkg- restore-keys: | - ${{matrix.id}}-vcpkg- ${{matrix.id}}- - name: Configure Visual Studio @@ -225,6 +241,14 @@ jobs: vcpkg install --triplet=${{matrix.triplet}} openssl[tools] echo "C:\vcpkg\packages\openssl_${{matrix.triplet}}\tools\openssl" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + # Persist new binaries before build failures can prevent a cache save. + - name: Save the vcpkg archives + if: steps.vcpkg-cache.outputs.cache-hit != 'true' + uses: actions/cache/save@v5 + with: + path: C:/Users/runneradmin/AppData/Local/vcpkg/archives + key: ${{steps.vcpkg-cache.outputs.cache-primary-key}} + - name: System information run: openssl version -a diff --git a/.github/workflows/ci.yml.in b/.github/workflows/ci.yml.in index d33732bf..d7813718 100644 --- a/.github/workflows/ci.yml.in +++ b/.github/workflows/ci.yml.in @@ -199,20 +199,36 @@ jobs: steps: - uses: actions/checkout@v5 - - name: Prepare the vcpkg cache key - id: vcpkg-cache-key + - name: Identify vcpkg build inputs + id: vcpkg-inputs shell: pwsh run: | $revision = git -C "${{matrix.vcpkg_root}}" rev-parse HEAD - "value=$env:ImageVersion-$revision" >> $env:GITHUB_OUTPUT + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + "revision=$revision" >> $env:GITHUB_OUTPUT + "image=$env:ImageVersion" >> $env:GITHUB_OUTPUT + + # A PR run searches all of its own keys before any base-branch cache, so a + # broad fallback here would let a stale PR archive win over a matching one + # from master. Match the current build inputs in every scope first. + - name: Restore the vcpkg archives + id: vcpkg-cache + uses: actions/cache/restore@v5 + with: + path: C:/Users/runneradmin/AppData/Local/vcpkg/archives + key: ${{matrix.id}}-vcpkg-${{steps.vcpkg-inputs.outputs.image}}-${{steps.vcpkg-inputs.outputs.revision}}-${{hashFiles('.github/workflows/ci.yml.in')}} + restore-keys: | + ${{matrix.id}}-vcpkg-${{steps.vcpkg-inputs.outputs.image}}-${{steps.vcpkg-inputs.outputs.revision}}- + ${{matrix.id}}-vcpkg-${{steps.vcpkg-inputs.outputs.image}}- - - name: Cache the vcpkg archives - uses: actions/cache@v5 + # Older archives remain useful: vcpkg validates each package's ABI itself. + - name: Restore older vcpkg archives + if: steps.vcpkg-cache.outputs.cache-matched-key == '' + uses: actions/cache/restore@v5 with: path: C:/Users/runneradmin/AppData/Local/vcpkg/archives - key: ${{matrix.id}}-vcpkg-${{steps.vcpkg-cache-key.outputs.value}}-${{hashFiles('.github/workflows/ci.yml.in')}} + key: ${{matrix.id}}-vcpkg- restore-keys: | - ${{matrix.id}}-vcpkg- ${{matrix.id}}- - name: Configure Visual Studio @@ -225,6 +241,14 @@ jobs: vcpkg install --triplet=${{matrix.triplet}} openssl[tools] echo "C:\vcpkg\packages\openssl_${{matrix.triplet}}\tools\openssl" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + # Persist new binaries before build failures can prevent a cache save. + - name: Save the vcpkg archives + if: steps.vcpkg-cache.outputs.cache-hit != 'true' + uses: actions/cache/save@v5 + with: + path: C:/Users/runneradmin/AppData/Local/vcpkg/archives + key: ${{steps.vcpkg-cache.outputs.cache-primary-key}} + - name: System information run: openssl version -a