diff --git a/README.md b/README.md index c0d1c3b..cd879d1 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ There are three kinds of version labels you can use. ### Cache scopes -The cache is scoped to the packages given and the branch. The default branch cache is available to other branches. +The cache is scoped to the packages given and the branch. The default branch cache is available to other branches. The cache key also includes runner image metadata (`ImageOS`, `ImageVersion`) when available so caches are invalidated as runner images change. ### Example workflow diff --git a/pre_cache_action.sh b/pre_cache_action.sh index 5cb64cb..4283bae 100755 --- a/pre_cache_action.sh +++ b/pre_cache_action.sh @@ -99,6 +99,17 @@ log "- CPU architecture is '${cpu_arch}'." value="${packages} @ ${version} ${force_update_inc}" +# Include runner image metadata in cache key when available to avoid stale +# cache hits when GitHub rotates images. +if [ -n "${ImageOS}" ]; then + value="${value} image_os:${ImageOS}" + log "- Runner image OS '${ImageOS}' added to value." +fi +if [ -n "${ImageVersion}" ]; then + value="${value} image_version:${ImageVersion}" + log "- Runner image version '${ImageVersion}' added to value." +fi + # Include repositories in cache key to ensure different repos get different caches if [ -n "${add_repository}" ]; then value="${value} ${add_repository}"