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

Dependencies are still installed after cache flag is true #349

Closed
4 of 5 tasks
gabimoncha opened this issue Oct 19, 2021 · 11 comments
Closed
4 of 5 tasks

Dependencies are still installed after cache flag is true #349

gabimoncha opened this issue Oct 19, 2021 · 11 comments
Assignees
Labels
bug Something isn't working

Comments

@gabimoncha
Copy link

Description:
Yarn still installs dependencies even though cache flag is true.
Tested on hosted ubuntu-latest env and on self-hosted macOS env.

Action version:
Specify the action version
actions/checkout@v2

Platform:

  • Ubuntu
  • macOS
  • Windows

Runner type:

  • Hosted
  • Self-hosted

Tools version:

yarn v1.22.15

Repro steps:
A description with steps to reproduce the issue. If your have a public example or repo to share, please provide the link.

name: unit-tests
on:
  workflow_dispatch

jobs:
  test:
    name: Cache deps
    runs-on: ubuntu-latest

    steps:
      - name: Checkout mobile-react
        uses: actions/checkout@v2

      - name: Set up Node with cache
        uses: actions/setup-node@v2
        with:
          node-version: 14
          cache: 'yarn'

      - name: Install yarn dependencies
        timeout-minutes: 5
        run: yarn install

Expected behavior:
After cache is applied yarn install should be skipped.

Actual behavior:
After cache is applied yarn installs dependencies
Screenshot 2021-10-18 at 17 18 07
.

@gabimoncha gabimoncha added bug Something isn't working needs triage labels Oct 19, 2021
@dmitry-shibanov dmitry-shibanov self-assigned this Oct 19, 2021
@dmitry-shibanov
Copy link
Contributor

Hello @gabrielmoncea. Thank you for your report. Global cache directory is used for caching in setup-node. For yarn you can check cache directory by this command: yarn cache dir. Action does not cache whole node_modules.

@gabimoncha
Copy link
Author

@dmitry-shibanov thanks. It means that I understood the docs wrong. It seemed to me that it applies the cache if detected

@dmitry-shibanov
Copy link
Contributor

You're welcome @gabrielmoncea. For more details please check section Caching packages dependencies in the Advanced usage guide.

I'm going to close the issue. Feel free to contact us if you have any questions.

@rcb4t2
Copy link

rcb4t2 commented Nov 24, 2021

Hi @dmitry-shibanov -- thanks so much to you and the team for the awesome work on this tool!

I'm still not fully understanding how to cache yarn deps. Is it sufficient to add the cache: 'yarn' flag, or do I also need to have a step using actions/cache in the workflow?

I am using the steps indicated in the Advanced usage guide, but do not seem to be seeing any speed improvement. Thanks in advance for any guidance!

For anyone running across this later:
Yes, it is sufficient to add the cache: 'yarn' flag to enable caching: you do not need an additional actions/cache step

In our case, the problem was because caching is per-branch. We were using this in a PR flow, so the first run on a new PR branch was not using the cache. Subsequent runs on the same branch do cache as expected

@dmitry-shibanov
Copy link
Contributor

Hello @rcb4t2. Thank you. The setup-node action does not have restore keys. If primary key (generated by yarn.lock file) is changed, the action will resave cache and it won't restore it. Besides, the speed depends on the size of the project. If it does not have a lot of dependencies, you won't get a big speed up.
Moreover, If I remember well, the yarn --prefer-offline command will check cache from the root of the project and global cache firstly and if it does not exist, it will fall back to load from the Internet.
We have feature requests with adding restore keys and saving .cache in the root of the project.
If you have any questions feel free to ping us.

@rcb4t2
Copy link

rcb4t2 commented Nov 26, 2021

Thanks for the reply, @dmitry-shibanov !

After examining our logs more carefully, I realized that your Action is properly restoring from cache as long as the 2nd run is on the same branch. We do see a speed improvement for yarn install from about 70 seconds to around 30s, which is plenty for our purposes. We are already using --prefer-offline, although I haven't tested the difference without it. Thanks again!

(PS: do you have a support forum or email link for general questions? I don't want to pollute your issue queue)

@akmjenkins
Copy link

akmjenkins commented Dec 3, 2021

Commenting on this closed issue because it's highly relevant.

I still don't understand this thing (my fault I'm sure). described here.

When I create my own cache action to cache node_modules and then run yarn --frozen-lockfile I see:

Run yarn --frozen-lockfile
yarn install v1.22.17
[1/4] Resolving packages...
success Already up-to-date.
Done in 1.21s.

and it takes 3 seconds.

But when I use this action's cache: 'yarn' I get this (45 seconds) when I run yarn --frozen-lockfile:

Run yarn --frozen-lockfile
yarn install v1.22.17
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
...

What am I misunderstanding? Maybe a documentation issue could clear this up (maybe just pointing me to the right lines in the docs/yarn docs)?

@dmitry-shibanov
Copy link
Contributor

Hello @akmjenkins. According to the documentation the action setup-node caches global cache. It does not cache node_modules.

@akmjenkins
Copy link

@dmitry-shibanov thank you but I'm still confused. So I assume it caches node images that it downloads, but why do we specify a cache option of yarn or npm - what difference does this make the the node image being cached (assuming I'm correct)?

The line in the documentation Caching yarn dependencies is incredibly confusing as "yarn dependencies" just sounds like a package in node_modules.

I really appreciate your response!

@dmitry-shibanov
Copy link
Contributor

Hello @akmjenkins. Hosted images have precached versions of Nodejs. If version does not exist on the image, it will be downloaded and precached. If you use self-hosted runners Nodejs versions will be saved. Hosted runners are cleaned at the end of the job, so saved nodejs versions won't be saved for future runs.
If you specify npm or yarn, the action will save global cache for yarn or npm. The cache for yarn and npm is located in different places.

  • For yarn the action uses these commands: yarn cache dir (yarn 1) and yarn config get cacheFolder (other versions)
  • For npm the action uses this command: npm config get cache
  • For pnpm the action uses this command: pnpm store path

@akmjenkins
Copy link

the action will save global cache for yarn or npm.

AHHHH, now I got it. This is why it still takes 40 seconds or so. The modules are all cached (when I specified cache: 'yarn', but they're in the global cache, yarn still needs to fetch them (but it won't go online, it'll find them from the global cache) and resolve them to the local node_modules folder.

Thank you so much for spelling this out for me 🙏🏼 🙏🏼 🙏🏼

deining pushed a commit to deining/setup-node that referenced this issue Nov 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants