actions / cache

Cache dependencies and build outputs in GitHub Actions
MIT License
4.55k stars 1.21k forks source link

restore-keys not being tried when another other exact key has different scope #1446

Open tcrasset opened 2 months ago

tcrasset commented 2 months ago

In the workflow below, I try to look up the exact key, and if it fails, I want it to look up the partial key as described in restore-keys.

However, it seems like if there are similar EXACT key matches, but with different version and/or scope, it doesn't even try restore-keys.

Actual result

Here below the lines that show that the partial key venv-Linux-avatar-python- wasn't being tried at all.

##[debug]No matching cache found for cache key 'venv-Linux-avatar-python-4e720f85a06c7351d9cce2fed31d87eddd0a5c4d2d1d0b905c347c3c11608bb0', version 'a06973642bf1b0b00df8a42eccd78187e15d22dc3785e3683bdf1261fb0023da and scope refs/heads/tc/api/retry-email-sending. There exist one or more cache(s) with similar key but they have different version or scope. See more info on cache matching here: https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#matching-a-cache-key 
##[debug]Other caches with similar key:
##[debug]Cache Key: venv-Linux-avatar-python-4e720f85a06c7351d9cce2fed31d87eddd0a5c4d2d1d0b905c347c3c11608bb0, Cache Version: a06973642bf1b0b00df8a42eccd78187e15d22dc3785e3683bdf1261fb0023da, Cache Scope: refs/pull/2923/merge, Cache Created: 2024-08-08T09:18:03.8933333Z
##[debug]Cache Key: venv-Linux-avatar-python-4e720f85a06c7351d9cce2fed31d87eddd0a5c4d2d1d0b905c347c3c11608bb0, Cache Version: a06973642bf1b0b00df8a42eccd78187e15d22dc3785e3683bdf1261fb0023da, Cache Scope: refs/pull/2924/merge, Cache Created: 2024-08-08T09:01:03.0433333Z
##[debug]Cache Key: venv-Linux-avatar-python-4e720f85a06c7351d9cce2fed31d87eddd0a5c4d2d1d0b905c347c3c11608bb0, Cache Version: a06973642bf1b0b00df8a42eccd78187e15d22dc3785e3683bdf1261fb0023da, Cache Scope: refs/pull/2917/merge, Cache Created: 2024-08-07T15:42:32.2633333Z

Expected result

I expected the cache to try the following caches on the default-branch (main) due to the venv-Linux-avatar-python- restore-keys :

See images below.

Workflow


- name: Load cached avatar-python dependencies
  id: cached-avatar-python-dependencies
  uses: actions/cache@v4
  with:
    path: ${{ github.workspace }}/client/build/avatar-python/.venv
    key: venv-${{ runner.os }}-avatar-python-${{ hashFiles('**/client/build/avatar-python/**/poetry.lock') }}
    restore-keys: |
      venv-${{ runner.os }}-avatar-python-

Full debug logs

##[debug]Evaluating condition for step: 'Load cached avatar-python dependencies'
##[debug]Evaluating: success()
##[debug]Evaluating success:
##[debug]=> true
##[debug]Result: true
##[debug]Starting: Load cached avatar-python dependencies
##[debug]Register post job cleanup for action: actions/cache@v4
##[debug]Loading inputs
##[debug]Evaluating: format('{0}/client/build/avatar-python/.venv', github.workspace)
##[debug]Evaluating format:
##[debug]..Evaluating String:
##[debug]..=> '{0}/client/build/avatar-python/.venv'
##[debug]..Evaluating Index:
##[debug]....Evaluating github:
##[debug]....=> Object
##[debug]....Evaluating String:
##[debug]....=> 'workspace'
##[debug]..=> '/home/runner/work/avatar/avatar'
##[debug]=> '/home/runner/work/avatar/avatar/client/build/avatar-python/.venv'
##[debug]Result: '/home/runner/work/avatar/avatar/client/build/avatar-python/.venv'
##[debug]Evaluating: format('venv-{0}-avatar-python-{1}', runner.os, hashFiles('**/client/build/avatar-python/**/poetry.lock'))
##[debug]Evaluating format:
##[debug]..Evaluating String:
##[debug]..=> 'venv-{0}-avatar-python-{1}'
##[debug]..Evaluating Index:
##[debug]....Evaluating runner:
##[debug]....=> Object
##[debug]....Evaluating String:
##[debug]....=> 'os'
##[debug]..=> 'Linux'
##[debug]..Evaluating hashFiles:
##[debug]....Evaluating String:
##[debug]....=> '**/client/build/avatar-python/**/poetry.lock'
##[debug]Search root directory: '/home/runner/work/avatar/avatar'
##[debug]Search pattern: '**/client/build/avatar-python/**/poetry.lock'
##[debug]Starting process:
##[debug]  File name: '/home/runner/runners/2.317.0/externals/node16/bin/node'
##[debug]  Arguments: '"/home/runner/runners/2.317.0/bin/hashFiles"'
##[debug]  Working directory: '/home/runner/work/avatar/avatar'
##[debug]  Require exit code zero: 'False'
##[debug]  Encoding web name:  ; code page: ''
##[debug]  Force kill process on cancellation: 'False'
##[debug]  Redirected STDIN: 'False'
##[debug]  Persist current code page: 'False'
##[debug]  Keep redirected STDIN open: 'False'
##[debug]  High priority process: 'False'
##[debug]Updated oom_score_adj to 500 for PID: 7751.
##[debug]Process started with process id 7751, waiting for process exit.
##[debug]Match Pattern: **/client/build/avatar-python/**/poetry.lock
##[debug]::debug::followSymbolicLinks 'false'
##[debug]::debug::followSymbolicLinks 'false'
##[debug]::debug::implicitDescendants 'true'
##[debug]::debug::matchDirectories 'true'
##[debug]::debug::omitBrokenSymbolicLinks 'true'
##[debug]::debug::Search path '/home/runner/work/avatar/avatar'
##[debug]/home/runner/work/avatar/avatar/client/build/avatar-python/poetry.lock
##[debug]Found 1 files to hash.
##[debug]undefined
##[debug]Hash result: '4e720f85a06c7351d9cce2fed31d87eddd0a5c4d2d1d0b905c347c3c11608bb0'
##[debug]STDOUT/STDERR stream read finished.
##[debug]STDOUT/STDERR stream read finished.
##[debug]Finished process 7751 with exit code 0, and elapsed time 00:00:05.2137956.
##[debug]..=> '4e720f85a06c7351d9cce2fed31d87eddd0a5c4d2d1d0b905c347c3c11608bb0'
##[debug]=> 'venv-Linux-avatar-python-4e720f85a06c7351d9cce2fed31d87eddd0a5c4d2d1d0b905c347c3c11608bb0'
##[debug]Result: 'venv-Linux-avatar-python-4e720f85a06c7351d9cce2fed31d87eddd0a5c4d2d1d0b905c347c3c11608bb0'
##[debug]Evaluating: format('venv-{0}-avatar-python-
##[debug]', runner.os)
##[debug]Evaluating format:
##[debug]..Evaluating String:
##[debug]..=> 'venv-{0}-avatar-python-
##[debug]'
##[debug]..Evaluating Index:
##[debug]....Evaluating runner:
##[debug]....=> Object
##[debug]....Evaluating String:
##[debug]....=> 'os'
##[debug]..=> 'Linux'
##[debug]=> 'venv-Linux-avatar-python-
##[debug]'
##[debug]Result: 'venv-Linux-avatar-python-
##[debug]'
##[debug]Loading env
Run actions/cache@v4
##[debug]Resolved Keys:
##[debug]["venv-Linux-avatar-python-4e720f85a06c7351d9cce2fed31d87eddd0a5c4d2d1d0b905c347c3c11608bb0","venv-Linux-avatar-python-"]
##[debug]Checking zstd --quiet --version
##[debug]1.5.6
##[debug]zstd version: 1.5.6
##[debug]Resource Url: https://acghubeus1.actions.githubusercontent.com/bUitQ9Jf0UgHNT3iYVD4ZwKmf3J9DOVKcZ3NeM7CroU4VrM2tP/_apis/artifactcache/cache?keys=venv-Linux-avatar-python-4e720f85a06c7351d9cce2fed31d87eddd0a5c4d2d1d0b905c347c3c11608bb0%2Cvenv-Linux-avatar-python-&version=a06973642bf1b0b00df8a42eccd78187e15d22dc3785e3683bdf1261fb0023da
##[debug]Resource Url: https://acghubeus1.actions.githubusercontent.com/bUitQ9Jf0UgHNT3iYVD4ZwKmf3J9DOVKcZ3NeM7CroU4VrM2tP/_apis/artifactcache/caches?key=venv-Linux-avatar-python-4e720f85a06c7351d9cce2fed31d87eddd0a5c4d2d1d0b905c347c3c11608bb0
##[debug]No matching cache found for cache key 'venv-Linux-avatar-python-4e720f85a06c7351d9cce2fed31d87eddd0a5c4d2d1d0b905c347c3c11608bb0', version 'a06973642bf1b0b00df8a42eccd78187e15d22dc3785e3683bdf1261fb0023da and scope refs/heads/tc/api/retry-email-sending. There exist one or more cache(s) with similar key but they have different version or scope. See more info on cache matching here: https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#matching-a-cache-key 
##[debug]Other caches with similar key:
##[debug]Cache Key: venv-Linux-avatar-python-4e720f85a06c7351d9cce2fed31d87eddd0a5c4d2d1d0b905c347c3c11608bb0, Cache Version: a06973642bf1b0b00df8a42eccd78187e15d22dc3785e3683bdf1261fb0023da, Cache Scope: refs/pull/2923/merge, Cache Created: 2024-08-08T09:18:03.8933333Z
##[debug]Cache Key: venv-Linux-avatar-python-4e720f85a06c7351d9cce2fed31d87eddd0a5c4d2d1d0b905c347c3c11608bb0, Cache Version: a06973642bf1b0b00df8a42eccd78187e15d22dc3785e3683bdf1261fb0023da, Cache Scope: refs/pull/2924/merge, Cache Created: 2024-08-08T09:01:03.0433333Z
##[debug]Cache Key: venv-Linux-avatar-python-4e720f85a06c7351d9cce2fed31d87eddd0a5c4d2d1d0b905c347c3c11608bb0, Cache Version: a06973642bf1b0b00df8a42eccd78187e15d22dc3785e3683bdf1261fb0023da, Cache Scope: refs/pull/2917/merge, Cache Created: 2024-08-07T15:42:32.2633333Z
##[debug]Failed to delete archive: Error: ENOENT: no such file or directory, unlink ''
Cache not found for input keys: venv-Linux-avatar-python-4e720f85a06c7351d9cce2fed31d87eddd0a5c4d2d1d0b905c347c3c11608bb0, venv-Linux-avatar-python-
##[debug]Node Action run completed with exit code 0
##[debug]Save intra-action state CACHE_KEY = venv-Linux-avatar-python-4e720f85a06c7351d9cce2fed31d87eddd0a5c4d2d1d0b905c347c3c11608bb0
##[debug]Finishing: Load cached avatar-python dependencies

Caches

image image image image image

tcrasset commented 2 months ago

May be a duplicate of #1361