Search code examples
githubgithub-actions

GitHub actions: why 'Cache restored successfully' but 'cache-hit' got 'false' problem


I'm experiencing CI using GitHub action.

I had a problem with installing dependencies on every CI and found that I could solve this with actions/cache.

Here is my part of action.yaml

- name: Cache npm dependency
  uses: actions/cache@v3
  id: npm-cache
  with:
    path: ~/.npm
    key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
    restore-keys: |
      ${{ runner.os }}-npm-

- if: steps.npm-cache.outputs.cache-hit != true
  name: Install Dependency
  run: |
    echo 'npm cache missed'
    npm ci

And restore the cache in Cache npm dependency step.

Cache restored successfully
Cache restored from key: Linux-npm-...

But it always reinstalls dependencies in 'Install Dependency' step.

Run echo 'npm cache missed'
  echo 'npm cache missed'
  npm ci
  shell: /usr/bin/bash -e {0}
npm cache missed
> [email protected] ...
> node bin/postinstall || exit 0
added 661 packages in 19.862s

As a result, caching becomes meaningless. What am i missing or doing wrong?


Solution

  • I solved it by modifying it like this: != true -> != 'true'