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

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

Closed
2 of 5 tasks
kachkaev opened this issue May 10, 2022 · 11 comments
Closed
2 of 5 tasks

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

kachkaev opened this issue May 10, 2022 · 11 comments
Assignees
Labels
feature request New feature or request to improve the current logic

Comments

@kachkaev
Copy link

kachkaev commented May 10, 2022

Description:

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

Action version:

setup-node@3.1.1

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

@kachkaev kachkaev added bug Something isn't working needs triage labels May 10, 2022
@e-korolevskii e-korolevskii added investigation The issue is under investigation and removed needs triage labels May 11, 2022
@e-korolevskii
Copy link
Contributor

Hi @kachkaev ,

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

@e-korolevskii
Copy link
Contributor

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.

@e-korolevskii e-korolevskii removed the investigation The issue is under investigation label May 18, 2022
@kachkaev
Copy link
Author

kachkaev commented May 18, 2022

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! 🙂

@IvanZosimov
Copy link
Contributor

IvanZosimov commented May 25, 2022

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.

@kachkaev
Copy link
Author

👋 @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?

@IvanZosimov IvanZosimov added feature request New feature or request to improve the current logic and removed bug Something isn't working labels May 26, 2022
@IvanZosimov
Copy link
Contributor

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

@gruckion
Copy link

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.

Read the comments it sounds like there is a potential work around? But I am unclear on what the work around is. I also don't see working-directory in the actions.yml or in any open PRs.

What's the status of this one?

@IvanZosimov
Copy link
Contributor

Hi, @gruckion 👋 Most probably my comment mislead you, sorry for that. About the status, this feature request is not the top priority at the moment, so we keep it to implement in the future.

@kachkaev
Copy link
Author

Read the comments it sounds like there is a potential work around? But I am unclear on what the work around is

See workaround section in the first comment.

olegstepura added a commit to muehlemann-popp/html-to-pdf that referenced this issue Nov 9, 2022
olegstepura added a commit to muehlemann-popp/html-to-pdf that referenced this issue Nov 11, 2022
- fix dockerfile
- remove i386 arch
- fix puppeteer running on arm
- use a fix from actions/setup-node#488 (comment)
- lint inside container
- remove double build for tests
- upgrade all deps
- fix linter errors
nweldev pushed a commit to fullwebdev/fullwebdev that referenced this issue Dec 4, 2022
@dsame dsame self-assigned this Dec 15, 2022
mcmartins added a commit to gap-packages/francy that referenced this issue Feb 27, 2023
* Canvas test failures #91
fixed workflows
fixed dockerfile for binder

* Fix unknown entity warnings (#90)

* fixed package info

* fix for #92 #93 and #94
added new workflow for releasetools

* use yarn instead of npm

* workaround for yarn caches on subprojects: from actions/setup-node#488 (comment)

---------

Co-authored-by: Manuel Martins <Manuel.Martins@ecmwf.int>
Co-authored-by: Jerry James <loganjerry@gmail.com>
mcmartins added a commit to gap-packages/francy that referenced this issue Mar 2, 2023
* Canvas test failures #91
fixed workflows
fixed dockerfile for binder

* Fix unknown entity warnings (#90)

* fixed workflows
fixed dockerfile for binder

* fixed dockerfile for binder

* fixed dockerfile for binder

* fixed dockerfile for binder

* fixed package info

* fix for #92 #93 and #94
added new workflow for releasetools

* revert changes from latest jupyterlab extension cookiecutter

* use yarn instead of npm

* workaround for yarn caches on subprojects: from actions/setup-node#488 (comment)

* workaround for yarn caches on subprojects: from actions/setup-node#488 (comment)

* new release 2.0.2 to test ReleaseTools

---------

Co-authored-by: Manuel Martins <Manuel.Martins@ecmwf.int>
Co-authored-by: Jerry James <loganjerry@gmail.com>
mcmartins added a commit to gap-packages/francy that referenced this issue Mar 10, 2023
* Canvas test failures #91
fixed workflows
fixed dockerfile for binder

* Fix unknown entity warnings (#90)

* fixed workflows
fixed dockerfile for binder

* fixed dockerfile for binder

* fixed dockerfile for binder

* fixed dockerfile for binder

* fixed package info

* fix for #92 #93 and #94
added new workflow for releasetools

* revert changes from latest jupyterlab extension cookiecutter

* use yarn instead of npm

* workaround for yarn caches on subprojects: from actions/setup-node#488 (comment)

* workaround for yarn caches on subprojects: from actions/setup-node#488 (comment)

* new release 2.0.2 to test ReleaseTools

* Update RELEASE.yml

use already present gh-pages branch

---------

Co-authored-by: Manuel Martins <Manuel.Martins@ecmwf.int>
Co-authored-by: Jerry James <loganjerry@gmail.com>
mcmartins added a commit to gap-packages/francy that referenced this issue Mar 10, 2023
* Canvas test failures #91
fixed workflows
fixed dockerfile for binder

* Fix unknown entity warnings (#90)

* fixed workflows
fixed dockerfile for binder

* fixed dockerfile for binder

* fixed dockerfile for binder

* fixed dockerfile for binder

* fixed package info

* fix for #92 #93 and #94
added new workflow for releasetools

* revert changes from latest jupyterlab extension cookiecutter

* use yarn instead of npm

* workaround for yarn caches on subprojects: from actions/setup-node#488 (comment)

* workaround for yarn caches on subprojects: from actions/setup-node#488 (comment)

* new release 2.0.2 to test ReleaseTools

* Update RELEASE.yml

use already present gh-pages branch

* Update RELEASE.yml

---------

Co-authored-by: Manuel Martins <Manuel.Martins@ecmwf.int>
Co-authored-by: Jerry James <loganjerry@gmail.com>
@danialdezfouli
Copy link

danialdezfouli commented Mar 13, 2023

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

mcmartins added a commit to gap-packages/francy that referenced this issue Mar 14, 2023
* Canvas test failures #91
fixed workflows
fixed dockerfile for binder

* Fix unknown entity warnings (#90)

* fixed workflows
fixed dockerfile for binder

* fixed dockerfile for binder

* fixed dockerfile for binder

* fixed dockerfile for binder

* fixed package info

* fix for #92 #93 and #94
added new workflow for releasetools

* revert changes from latest jupyterlab extension cookiecutter

* use yarn instead of npm

* workaround for yarn caches on subprojects: from actions/setup-node#488 (comment)

* workaround for yarn caches on subprojects: from actions/setup-node#488 (comment)

* new release 2.0.2 to test ReleaseTools

* Update RELEASE.yml

use already present gh-pages branch

* Update RELEASE.yml

* added fetch-depth: 0 to fetch all branches

---------

Co-authored-by: Manuel Martins <Manuel.Martins@ecmwf.int>
Co-authored-by: Jerry James <loganjerry@gmail.com>
mcmartins pushed a commit to gap-packages/francy that referenced this issue Mar 14, 2023
* develop:
  update gh-pages branch
  added fetch-depth: 0 to fetch all branches
  Update RELEASE.yml
  Update RELEASE.yml
  new release 2.0.2 to test ReleaseTools
  workaround for yarn caches on subprojects: from actions/setup-node#488 (comment)
  workaround for yarn caches on subprojects: from actions/setup-node#488 (comment)
  use yarn instead of npm
  revert changes from latest jupyterlab extension cookiecutter
  fix for #92 #93 and #94 added new workflow for releasetools
  fixed package info
  fixed dockerfile for binder
  fixed dockerfile for binder
  fixed dockerfile for binder
  fixed workflows fixed dockerfile for binder
  Fix unknown entity warnings (#90)
  Canvas test failures #91 fixed workflows fixed dockerfile for binder
astrowq added a commit to astrowq/setup-yarn that referenced this issue Jun 2, 2023
@dsame
Copy link
Contributor

dsame commented Jul 25, 2023

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

@dsame dsame closed this as completed Jul 25, 2023
deining pushed a commit to deining/setup-node that referenced this issue Nov 9, 2023
Bumps [typescript](https://github.com/Microsoft/TypeScript) from 4.9.5 to 5.0.2.
- [Release notes](https://github.com/Microsoft/TypeScript/releases)
- [Commits](microsoft/TypeScript@v4.9.5...v5.0.2)

---
updated-dependencies:
- dependency-name: typescript
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
rgalanakis added a commit to webhookdb/webhookdb that referenced this issue Jan 7, 2024
* Fix incorrect sizing of recent blog post images

* Fix broken hash navigation on page load with code examples

The code replacement modifies height, which means
the anchor navigation is at the wrong place.
Renavigate after code has loaded.

* Update browserlist

* Yarn workaround in github action

See actions/setup-node#488
for reference.

* eslint-check -> eslint, remove website test (we don't have them)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request to improve the current logic
Projects
None yet
Development

No branches or pull requests

7 participants