actions / cache

Cache dependencies and build outputs in GitHub Actions
MIT License
4.49k stars 1.2k forks source link

`$HOME` in cache path doesn't work #1332

Open nschloe opened 7 months ago

nschloe commented 7 months ago

Using $HOME as part of the cache path doesn't work. This

      - uses: actions/cache@v4
        id: my-cache
        with:
          path: $HOME/.cache/foo

Always gives

Warning: Path Validation Error: Path(s) specified in the action for caching do(es) not exist, hence no cache is being saved.

In the Post Run step.

parsley72 commented 6 months ago

I'm also having trouble getting $HOME to work but I don't get a warning like this. I have:

    - name: Setup Yocto cache
      id: cache-yocto
      uses: actions/cache@v4
      with:
        path: $HOME/cache/
        key: ${{ runner.os }}-cache

    - name: Check cache after
      shell: bash
      continue-on-error: true
      run: |
        echo ${{ steps.cache-yocto.outputs.cache-hit }}
        ls -l $HOME

and I get:

##[debug]Evaluating condition for step: 'Setup Yocto cache'
##[debug]Evaluating: success()
##[debug]Evaluating success:
##[debug]=> true
##[debug]Result: true
##[debug]Starting: Setup Yocto cache
##[debug]Register post job cleanup for action: actions/cache@v4
##[debug]Loading inputs
##[debug]Evaluating: format('{0}-cache', runner.os)
##[debug]Evaluating format:
##[debug]..Evaluating String:
##[debug]..=> '{0}-cache'
##[debug]..Evaluating Index:
##[debug]....Evaluating runner:
##[debug]....=> Object
##[debug]....Evaluating String:
##[debug]....=> 'os'
##[debug]..=> 'Linux'
##[debug]=> 'Linux-cache'
##[debug]Result: 'Linux-cache'
##[debug]Loading env
Run actions/cache@v4
  with:
    path: ${HOME}/cache/
    key: Linux-cache
    enableCrossOsArchive: false
    fail-on-cache-miss: false
    lookup-only: false
    save-always: false
##[debug]Resolved Keys:
##[debug]["Linux-cache"]
##[debug]Checking zstd --quiet --version
##[debug]1.5.5
##[debug]zstd version: 1.5.5
##[debug]Resource Url: https://acghubeus2.actions.githubusercontent.com/****/_apis/artifactcache/cache?keys=Linux-cache&version=****
##[debug]Resource Url: https://acghubeus2.actions.githubusercontent.com/****/_apis/artifactcache/caches?key=Linux-cache
##[debug]Failed to delete archive: Error: ENOENT: no such file or directory, unlink ''
Cache not found for input keys: Linux-cache
##[debug]Node Action run completed with exit code 0
##[debug]Save intra-action state CACHE_KEY = Linux-cache
##[debug]Finishing: Setup Yocto cache

##[debug]Evaluating condition for step: 'Check cache after'
##[debug]Evaluating: success()
##[debug]Evaluating success:
##[debug]=> true
##[debug]Result: true
##[debug]Starting: Check cache after
##[debug]Loading inputs
##[debug]Evaluating: format('echo {0}
##[debug]ls -l ~
##[debug]ls -l ~/cache
##[debug]', steps.cache-yocto.outputs.cache-hit)
##[debug]Evaluating format:
##[debug]..Evaluating String:
##[debug]..=> 'echo {0}
##[debug]ls -l ~
##[debug]ls -l ~/cache
##[debug]'
##[debug]..Evaluating Index:
##[debug]....Evaluating Index:
##[debug]......Evaluating Index:
##[debug]........Evaluating steps:
##[debug]........=> Object
##[debug]........Evaluating String:
##[debug]........=> 'cache-yocto'
##[debug]......=> Object
##[debug]......Evaluating String:
##[debug]......=> 'outputs'
##[debug]....=> Object
##[debug]....Evaluating String:
##[debug]....=> 'cache-hit'
##[debug]..=> null
##[debug]=> 'echo 
##[debug]ls -l ~
##[debug]ls -l ~/cache
##[debug]'
##[debug]Result: 'echo 
##[debug]ls -l ~
##[debug]ls -l ~/cache
##[debug]'
##[debug]Loading env
Run echo 
##[debug]/usr/bin/bash --noprofile --norc -e -o pipefail /home/runner/work/_temp/1f4b8a65-3dfa-43cf-8792-fb67ebfd87ef.sh

total 8
drwxr-xr-x 5 runner runner 4096 Mar  8 01:05 actions-runner
drwxr-xr-x 6 runner runner 4096 Mar  8 01:09 work
ls: cannot access '/home/runner/cache': No such file or directory
Error: Process completed with exit code 2.
##[debug]Finishing: Check cache after

So the step completes, but I never get a cache - the directory ${HOME}/cache/ isn't created and cache-hit doesn't seem to be set.

mys1024 commented 6 months ago

Same here. In my case, I use "~/cache/deno" as the cache path, and actions/cache@v2 works well with this path. But when I upgrade actions/cache to v4, it always reports this warning in the post step:

Warning: Path Validation Error: Path(s) specified in the action for caching do(es) not exist, hence no cache is being saved.