GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — `cache: yarn` not working for Yarn 3 (Berry) in a subfolder · Issue #488 · actions/setup-node

cache: yarn not working for Yarn 3 (Berry) in a subfolder #488

New issue
Copy link
New issue
Copy link
Closed
Closed
cache: yarn not working for Yarn 3 (Berry) in a subfolder#488
Copy link
Assignees
dsame
Labels
feature requestNew feature or request to improve the current logic

Description

@kachkaev
kachkaev
opened on May 10, 2022
Issue body actions

Description:

When a repo with Yarn Berry is in a subfolder, cache: yarn does not get applied.

Action version:

[email protected]

Platform:

  • Ubuntu
  • macOS
  • Windows

Runner type:

  • Hosted
  • Self-hosted

Tools version:

Yarn 3.2

Repro steps:

Configure a pipeline that checks out the Node repo into a subfolder:

    - name: Check out tooling
      uses: actions/checkout@v3
      with:
        path: tooling ## 👈 👀
        repository: example-org/example-tooling-repo

Setup Node, as suggested in the action docs:

    - name: Setup Node
      uses: actions/setup-node@v3
      with:
        node-version: 18
        cache: yarn
        cache-dependency-path: tooling/yarn.lock

Expected behavior:

actions/setup-node correctly launches the right version of Yarn (which is included into the repo). Therefore, the right folder is cached and the follow-up setup is faster.

Actual behavior:

Yarn cache dir is resolved to /home/runner/.cache/yarn/v6. This is because yarn --version is called in the default directory, which is followed by yarn cache dir instead of yarn config get cacheFolder inside tooling. Cache end up empty and so all packages are re-downloaded again each time.

Potential solution:

It’d be nice to pass working-directory down to actions/setup-node (similar to the run task).

Workaround:

     - name: Setup Node
       uses: actions/setup-node@v3
       with:
         node-version: 18
-       cache: yarn
-       cache-dependency-path: tooling/yarn.lock
+        
+    - name: Get yarn cache directory path
+      id: yarn-cache-dir-path
+      run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
+      shell: bash
+      working-directory: tooling
+
+    - name: Restore yarn cache
+      uses: actions/cache@v3
+      with:
+        path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
+        key: yarn-cache-folder-${{ hashFiles('**/yarn.lock', '.yarnrc.yml') }}
+        restore-keys: |
+          yarn-cache-folder-

Cache key is inspired by #325

Reacted by DanCodes, tony kerz, Eric Fu, Roman Makarov, Spenser Black, Oji Ishimori, Yuku Takahashi, Yusuke Fujiki, Joey Orlando, Ilko Kacharov and 13 more

Activity

Next
  1. kachkaev
    added
    bugSomething isn't working
    needs triage
    on May 10, 2022
  2. e-korolevskii
    added
    investigationThe issue is under investigation
    and removed
    needs triage
    on May 11, 2022
  3. e-korolevskii commented on May 11, 2022

    @e-korolevskii
    e-korolevskii
    on May 11, 2022
    Contributor
    More actions

    Hi @kachkaev ,

    We will investigate on that issue and come back to you.

    Reacted by Alexander Kachkaev
  4. marko-zivic-93
    assigned
    e-korolevskii
    on May 12, 2022
  5. e-korolevskii commented on May 18, 2022

    @e-korolevskii
    e-korolevskii
    on May 18, 2022
    Contributor
    More actions

    Hello @kachkaev ,

    Thanks for your issue. This is unexpected behavior because you're using binaries located directly in a directory, but the action is running at the root of the repository, so it doesn't see yarn binaries in a subfolder. So the yarn version hasn't changed.
    We recommend that you install the required version before restoring the cache.

  6. e-korolevskii
    removed
    investigationThe issue is under investigation
    on May 18, 2022
  7. kachkaev commented on May 18, 2022

    @kachkaev
    kachkaev
    on May 18, 2022
    Author
    More actions

    This is unexpected behavior because you're using binaries located directly in a directory, but the action is running at the root of the repository

    Yep, that's what happens. Keeping Yarn binary in the project and calling global yarn is a normal thing for Yarn berry. In this case global yarn command finds a local binary and delegates everything to it. Thus, there is no need install the right version of global yarn to get the right behavior.

    Running yarn config get cacheFolder returns [project-dir]/.yarn/cache rather than some shared global folder. Even if I install the ‘right’ global Yarn but call it from a wrong cwd, it won't return the correct result. Thus, as far as I understand, the only solution is to have something like:

         - name: Setup Node
           uses: actions/setup-node@v3
           with:
             node-version: 18
            cache: yarn
    -       cache-dependency-path: tooling/yarn.lock
    +       working-directory: tooling ## proposed option, does not exist at the time of writing

    This proposed working-directory option will help find yarn.lock path, so cache-dependency-path won't be necessary. This will also make global yarn delegate everything to [job-dir]/tooling/.yarn/releases/yarn-3.x.x.cjs. The delegated binary will know the right cacheFolder: [job-dir]/tooling/.yarn/cache.

    Please let me know if you see other solutions here! 🙂

    Reacted by Spenser Black, subash adhikari, Daniel Hoffmann Bernardes, Yuku Takahashi and Kevin Hu
  8. IvanZosimov commented on May 25, 2022

    @IvanZosimov
    IvanZosimov
    on May 25, 2022
    Contributor
    More actions

    Hi, @kachkaev 👋 ! Thanks for popping this issue up! Our action, in fact, doesn't support yarn berry out of the box, but you found the perfect workaround that can be helpful to other customers! I think we can close this issue now because it's not really a bug, but expected behaviour. However, I'd like to ask you to open a new feature request and we will investigate the possibility of adding this functionality to the new releases.

    Reacted by David Zulaica
  9. kachkaev commented on May 25, 2022

    @kachkaev
    kachkaev
    on May 25, 2022
    Author
    More actions

    👋 @IvanZosimov! Yeah I actually agree with you that this more like a feature request rather than a bug report. Do you know if it’s OK to just change issue labels instead of closing and reopening it?

  10. IvanZosimov
    added
    feature requestNew feature or request to improve the current logic
    and removed
    bugSomething isn't working
    on May 26, 2022
  11. IvanZosimov commented on May 26, 2022

    @IvanZosimov
    IvanZosimov
    on May 26, 2022
    Contributor
    More actions

    Hello, @kachkaev 👋 ! Yes, it's OK, I changed the label by myself, thank you again for contributing 🤟

    Reacted by Alexander Kachkaev
  12. marko-zivic-93
    unassigned
    e-korolevskii
    on Jun 10, 2022
  13. 12 remaining items

  14. mcmartins
    added 2 commits that reference this issue on Feb 27, 2023

    Release 2.0.1 (#95)

    ce2639f

    Release 2.0.2 (#96)

    d7276cf
  15. mcmartins
    added 2 commits that reference this issue on Mar 10, 2023

    update gh-pages commands (#98)

    60c26e2

    gh-pages (#100)

    3c931df
  16. danialdezfouli commented on Mar 13, 2023

    @danialdezfouli
    danialdezfouli
    on Mar 13, 2023
    More actions

    I fixed it with the following setup, but the docker still takes time (2-3m) to build the image, maybe we should apply cache to docker too.

    jobs:
      frontend:
        runs-on: ubuntu-latest
        steps:
          - name: Checkout code
            uses: actions/checkout@v3
    
          - name: Get yarn cache directory path
            id: yarn-cache-dir-path
            run: echo "dir=$(cd client && yarn config get cacheFolder)" >> $GITHUB_ENV
    
          - name: Cache Dependencies
            uses: actions/cache@v3
            with:
              path: ${{ env.dir }}
              key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
              restore-keys: |
                ${{ runner.os }}-yarn-
    
          - name: Setup Node.js and Yarn
            uses: actions/setup-node@v3
            with:
              node-version: 18
              cache: yarn
              cache-dependency-path: client/yarn.lock
              registry-url: "https://registry.yarnpkg.com"
    
          - name: Install dependencies
            working-directory: client
            run: yarn install
    
          - name: Run linter
            working-directory: client
            run: yarn lint
  17. mcmartins
    added 2 commits that reference this issue on Mar 14, 2023

    Release 2.0.2 (#101)

    927ac9a

    Merge branch 'develop'

    1af057b
  18. astrowq
    added a commit that references this issue on Jun 2, 2023

    extend setup-node with proper yarn 3 caching

    56f62e5
  19. dsame commented on Jul 25, 2023

    @dsame
    dsame
    on Jul 25, 2023
    Contributor
    More actions

    Hello @kachkaev, i am going to close this issue because the PR is merged , but please feel free to reopen it or create new issue in case if the problem still exists

    Reacted by Alexander Kachkaev
  20. dsame
    closed this as completedon Jul 25, 2023
  21. deining
    added a commit that references this issue on Nov 9, 2023

    chore(deps-dev): bump typescript from 4.9.5 to 5.0.2 (actions#488)

    05c8619
  22. rgalanakis
    added a commit that references this issue on Jan 7, 2024

    More website fixes (#672)

    7b6f7e1
  23. CrispyBaguette
    added a commit that references this issue on Nov 8, 2024

    Update actions/setup-node action to v4 (#56)

    a2ef20d
  24. olegstepura
    added 2 commits that reference this issue on Oct 28, 2026

    chore: pin binfmt to qemu-v10.2.3 for the arm64 cross-build

    5946209

    chore: bump GitHub Actions to their Node 24 majors (#19)

    b063297
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @dsame
    dsame

Labels

feature requestNew feature or request to improve the current logic

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.