fix: Hash runner base image into cache key

Hash the list of pre-installed package names (dpkg-query -W) into the
cache key. This prevents cache collisions when different runners (e.g.,
GPU runners with CUDA pre-installed vs plain Ubuntu) request the same
packages — a cache built where packages were already present won't be
restored on a runner where they're missing.

Also adds a ::notice annotation so users can see the fingerprint in
the workflow summary and understand why different runners produce
different cache keys.

Co-developed-by: Claude Code v2.1.58 (claude-opus-4-6)
This commit is contained in:
Rob Taylor 2026-03-11 02:44:36 +00:00
parent f8df4cf6bb
commit 3269da2d67

View file

@ -111,6 +111,16 @@ if [ "${cpu_arch}" != "x86_64" ]; then
log "- Architecture '${cpu_arch}' added to value."
fi
# Include a hash of pre-installed packages so runners with different base
# images (e.g., GPU runners with CUDA pre-installed vs plain Ubuntu) get
# different cache keys. This prevents a cache built on runner A (where some
# packages were already installed) from being restored on runner B (where
# those packages are missing).
base_pkgs_hash="$(dpkg-query -W -f='${binary:Package}\n' | sha1sum | cut -f1 -d' ')"
value="${value} base:${base_pkgs_hash}"
log "- Base packages hash '${base_pkgs_hash}' added to value."
echo "::notice::Runner base image fingerprint: ${base_pkgs_hash}. Runners with different pre-installed packages produce different fingerprints and cannot share caches."
log "- Value to hash is '${value}'."
key="$(echo "${value}" | md5sum | cut -f1 -d' ')"