<!--- Please direct any generic questions related to actions to our support community forum at https://github.community/c/code-to-cloud/github-actions/41 ---> <!--- Before opening up a new bug report, please make sure to check for similar existing issues --> **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:** - [x] Ubuntu - [ ] macOS - [ ] Windows **Runner type:** - [x] Hosted - [ ] Self-hosted **Tools version:** Yarn 3.2 <!--- Please specify versions of node and package manager (npm, yarn, pnpm and etc)--> **Repro steps:** Configure a pipeline that checks out the Node repo into a subfolder: ```yaml - 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: ```yaml - 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:** ```diff - 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 https://github.com/actions/setup-node/issues/325