action-setup icon indicating copy to clipboard operation
action-setup copied to clipboard

Use actions/setup-node to cache pnpm store instead of doing it manually

Open dtinth opened this issue 2 years ago • 7 comments

actions/setup-node supports the option cache: pnpm, so we can take advantage of that to make our workflow simpler.

image

Note: pnpm/action-setup must be run BEFORE actions/setup-node because otherwise the setup-node action will fail due to not being able to find the pnpm executable.

dtinth avatar Mar 14 '23 07:03 dtinth

Anyone knows what the difference is between the two methods? https://github.com/pnpm/action-setup/issues/82

robotkutya avatar May 06 '23 09:05 robotkutya

I don't know if I have set this up incorrectly, but I find the manual way to be faster than using the cache from setup-node.

The manual way does not require us to install the packages again (as we cache node_modules), while this suggested one does require it:

Manual (~20s)

image

Using setup-node (~1m)

(This was a cache hit) image

setup-node step config

    - name: Install pnpm
      uses: pnpm/action-setup@v2
      with:
        version: 8.1.0
        run_install: false

    # Has to be done after installing pnpm, otherwise the cache will not work.
    - name: Install Node.js
      uses: actions/setup-node@v3
      with:
        node-version: 18
        cache: pnpm
        cache-dependency-path: 'pnpm-lock.yaml'

nicolassanmar avatar Jun 12 '23 14:06 nicolassanmar

@nicolassanmar Does your “manual” setup also cache node_modules? Using cache: pnpm merely caches the pnpm store, not node_modules.

This is how I interpret the log message:

Log message Description
resolved X, reused 0, downloaded X, added X, done Cache is not working.
resolved X, reused X, downloaded 0, added X, done Store cache is working.
Already up to date node_modules is cached.

dtinth avatar Jun 12 '23 14:06 dtinth

@dtinth You are 100% right. I thought that https://github.com/pnpm/action-setup#use-cache-to-reduce-installation-time suggested caching node_modules but I was mistaken. I am manually caching node_modules and ~I don't think setup-node provides a way to do that~ They stated that it is not supported and they are not planning to add it https://github.com/actions/setup-node/issues/406#issuecomment-1014271353

nicolassanmar avatar Jun 12 '23 14:06 nicolassanmar

thanks guys for the discussion, makes it much more clear!

I think more info about this would be appreciated to newcomers, any ideas how to improve the docs in this regard?

robotkutya avatar Jun 12 '23 17:06 robotkutya

I would highly suggest you show both as two different options (as opposed to replacing the existing one) - this solution won't work if you're using a self-hosted runner that has node pre-installed

dhorkin avatar Sep 27 '23 19:09 dhorkin

pnpm docs also mention using setup-node to cache pnpm store

https://pnpm.io/continuous-integration#github-actions

I think we should update the example to go the recommended way by using setup-node. I think that would be the recommended way given you don't have to maintain a custom cache. setup-node takes care of that for you (what if pnpm store command is deprecated and now another one is used? setup-node would take care of that). So a thing less to worry about

Links:

davidlj95 avatar Apr 14 '24 11:04 davidlj95