Repository navigation
Description
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-repoSetup 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.lockExpected 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
Activity
e-korolevskii commentedon May 11, 2022
Hi @kachkaev ,
We will investigate on that issue and come back to you.
e-korolevskii commentedon May 18, 2022
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.
kachkaev commentedon May 18, 2022
Yep, that's what happens. Keeping Yarn binary in the project and calling global
yarnis a normal thing for Yarn berry. In this case globalyarncommand finds a local binary and delegates everything to it. Thus, there is no need install the right version of globalyarnto get the right behavior.Running
yarn config get cacheFolderreturns[project-dir]/.yarn/cacherather than some shared global folder. Even if I install the ‘right’ global Yarn but call it from a wrongcwd, 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 writingThis proposed
working-directoryoption will help findyarn.lockpath, socache-dependency-pathwon't be necessary. This will also make globalyarndelegate everything to[job-dir]/tooling/.yarn/releases/yarn-3.x.x.cjs. The delegated binary will know the rightcacheFolder:[job-dir]/tooling/.yarn/cache.Please let me know if you see other solutions here! 🙂
IvanZosimov commentedon 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 commentedon May 25, 2022
👋 @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 commentedon May 26, 2022
Hello, @kachkaev 👋 ! Yes, it's OK, I changed the label by myself, thank you again for contributing 🤟
12 remaining items
Release 2.0.1 (#95)
Release 2.0.2 (#96)
update gh-pages commands (#98)
gh-pages (#100)
danialdezfouli commentedon 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.
Release 2.0.2 (#101)
Merge branch 'develop'
extend setup-node with proper yarn 3 caching
dsame commentedon 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
chore(deps-dev): bump typescript from 4.9.5 to 5.0.2 (actions#488)
More website fixes (#672)
Update actions/setup-node action to v4 (#56)
chore: pin binfmt to qemu-v10.2.3 for the arm64 cross-build
chore: bump GitHub Actions to their Node 24 majors (#19)