Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support cache-hit state #316

Closed
pacexy opened this issue Aug 9, 2021 · 9 comments · Fixed by #327
Closed

Support cache-hit state #316

pacexy opened this issue Aug 9, 2021 · 9 comments · Fixed by #327
Labels
enhancement New feature or request

Comments

@pacexy
Copy link

pacexy commented Aug 9, 2021

I wrote a workflow like follow, but I found nothing happened. Is that wrong or just unsupported?

- uses: actions/setup-node@v2
  id: cache
  with:
    node-version: '14'
    cache: yarn
- run: yarn install --frozen-lockfile
  if: steps.cache.outputs.cache-hit != 'true'
@dmitry-shibanov
Copy link
Contributor

Hello @pacexy. The action does not provide cache-hit for output. We can track it as an enchantment to add it.

@dmitry-shibanov dmitry-shibanov added the enhancement New feature or request label Aug 19, 2021
@WtfJoke
Copy link
Contributor

WtfJoke commented Sep 3, 2021

I've opened a pull request #327

@markgoho
Copy link

@dmitry-shibanov what good is caching if we can't conditionally skip the step to install dependencies based on a cache hit?

I'm not sure why you released caching without this critical step. And now, for two weeks there's been a Pull Request open that solves this issue for the community and it's sat unreviewed/untested for days because it requires maintainer approval for GHA to run on it

@snebjorn
Copy link

@WtfJoke @dmitry-shibanov How is this supposed to work?

I have the following workflow

jobs:
  dependencies:
    name: Build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v2
        id: node
        with:
          node-version: "lts/*"
          cache: "npm"

      - run: npm ci
        if: steps.node.outputs.cache-hit != 'true'

      - run: npm run build

Output of setup-node. As you can see the cache was hit:

/home/runner/.npm
Received 0 of 47090078 (0.0%), 0.0 MBs/sec
Received 47090078 of 47090078 (100.0%), 24.0 MBs/sec
Cache Size: ~45 MB (47090078 B)
/usr/bin/tar --use-compress-program zstd -d -xf /home/runner/work/_temp/89024633-ec04-4b2c-ae8e-d204c2b8ed80/cache.tzst -P -C /home/runner/work/my-repo/my-repo
Cache restored successfully
Cache restored from key: node-cache-Linux-npm-9aab2f23ac0bec33f9fa276d338a3c3b405d6ee3a62ad183cfe376f8f52483a8

But npm run build fails with missing modules which suggests that the node_modules folder is missing.

Error: error TS2307: Cannot find module 'some package' or its corresponding type declarations.
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! my-package@1.0.0 build: tsc
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the my-package@1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?

npm ERR! A complete log of this run can be found in:
npm ERR! /home/runner/.npm/_logs/2021-10-27T09_57_50_301Z-debug.log
Error: Process completed with exit code 2.

Am I missing something?

@dmitry-shibanov
Copy link
Contributor

Hello @snebjorn. The action does not cache node_modules. It caches global cache directory. For more details please check section Caching packages dependencies in the Advanced usage guide.

@snebjorn
Copy link

I see, sorry for the confusion

@ProductOfAmerica
Copy link

@snebjorn I don't understand. Running into same problem as you. Can you explain this to me? I'm trying to do what @pacexy commented, yet I'm hitting your same error.

@snebjorn
Copy link

uff... it's been a while. But I believe what he's saying is that it caches packages in ~/.npm/node_modules instead of in your repo.

So basically you still need to run npm ci to copy the packages into your repo

@ProductOfAmerica
Copy link

uff... it's been a while. But I believe what he's saying is that it caches packages in ~/.npm/node_modules instead of in your repo.

So basically you still need to run npm ci to copy the packages into your repo

Gotcha, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants