Skip to content

fix: only write vcpkg cache on dependency and toolset changes#16

Merged
johnpatek merged 3 commits intomasterfrom
copilot/update-cache-usage-in-main-yml
Mar 24, 2026
Merged

fix: only write vcpkg cache on dependency and toolset changes#16
johnpatek merged 3 commits intomasterfrom
copilot/update-cache-usage-in-main-yml

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 24, 2026

The pipeline was keyed on github.run_id, guaranteeing a cache miss every restore and an unconditional new entry every save — even when vcpkg binaries were identical.

Changes

  • Precise dependency hash — a Compute vcpkg cache hash step uses jq to extract only features and dependencies from vcpkg.json (excluding the app version field) and combines that with vcpkg-configuration.json before hashing. This prevents a version-only bump in vcpkg.json from needlessly invalidating the cache.
  • vcpkg ref in cache keyVCPKG_REF is defined as a workflow-level env var and embedded in every cache key. Bumping the vcpkg toolset ref now correctly busts the cache, and the same value drives both the Checkout vcpkg step and the cache key, keeping them in sync.
  • Conditional save — each save step runs only when cache-hit != 'true' on its paired restore step, skipping the write entirely on an exact hit.
env:
  VCPKG_REF: '2026.01.16'

- name: Compute vcpkg cache hash
  id: vcpkg-hash
  shell: bash
  run: |
    hash=$(jq -cj '{features,dependencies}' WebFrame/vcpkg.json | cat - WebFrame/vcpkg-configuration.json | sha256sum | awk '{print $1}')
    echo "value=${hash}" >> $GITHUB_OUTPUT

- name: "Restore VCPKG cache"
  id: restore-test-cache
  uses: actions/cache/restore@v4
  with:
    path: ${{ github.workspace }}/vcpkg-test-cache
    key: vcpkg-test-cache-${{ env.VCPKG_REF }}-${{ steps.vcpkg-hash.outputs.value }}
    restore-keys: vcpkg-test-cache-${{ env.VCPKG_REF }}

- name: "Save VCPKG cache"
  if: steps.restore-test-cache.outputs.cache-hit != 'true'
  uses: actions/cache/save@v4
  with:
    path: ${{ github.workspace }}/vcpkg-test-cache
    key: vcpkg-test-cache-${{ env.VCPKG_REF }}-${{ steps.vcpkg-hash.outputs.value }}

The same pattern is applied to the matrix build job (restore-build-cache / actions/cache/restore@v5).

Original prompt

This section details on the original issue you should resolve

<issue_title>Cache Usage</issue_title>
<issue_description>The CI/CD pipeline should only save a new cache entry if the vcpkg binary contents have changed. Update the steps in main.yml to only overwrite stale caches.</issue_description>

Comments on the Issue (you are @copilot in this section)


📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

Copilot AI changed the title [WIP] Update CI/CD pipeline to manage cache usage efficiently fix: only write vcpkg cache on dependency changes Mar 24, 2026
Copilot AI requested a review from johnpatek March 24, 2026 19:53
@johnpatek johnpatek marked this pull request as ready for review March 24, 2026 19:59
Copilot AI requested a review from johnpatek March 24, 2026 20:12
Copilot stopped work on behalf of johnpatek due to an error March 24, 2026 20:12
Copilot AI changed the title fix: only write vcpkg cache on dependency changes fix: only write vcpkg cache on dependency and toolset changes Mar 24, 2026
@johnpatek johnpatek merged commit fc53190 into master Mar 24, 2026
5 checks passed
@johnpatek johnpatek deleted the copilot/update-cache-usage-in-main-yml branch March 27, 2026 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cache Usage

2 participants