From e8b3db419d4d8ad959c3b260d873b90bf8a2cbec Mon Sep 17 00:00:00 2001 From: Mike McCready <66998419+MikeMcC399@users.noreply.github.com> Date: Thu, 20 Feb 2025 12:47:45 +0100 Subject: [PATCH] test: add yarn modern caching --- .github/workflows/example-yarn-modern-pnp.yml | 6 ++++++ .github/workflows/example-yarn-modern.yml | 6 ++++++ README.md | 13 ++++++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/.github/workflows/example-yarn-modern-pnp.yml b/.github/workflows/example-yarn-modern-pnp.yml index 69bd501a5..520ee55e8 100644 --- a/.github/workflows/example-yarn-modern-pnp.yml +++ b/.github/workflows/example-yarn-modern-pnp.yml @@ -14,6 +14,12 @@ jobs: - name: Checkout uses: actions/checkout@v4 - run: corepack enable yarn # experimental - see https://nodejs.org/docs/latest/api/corepack.html + - name: Set up Yarn cache + uses: actions/setup-node@v4 + with: + node-version-file: '.node-version' + cache: yarn + cache-dependency-path: examples/yarn-modern-pnp/yarn.lock - name: Custom Yarn command uses: ./ with: diff --git a/.github/workflows/example-yarn-modern.yml b/.github/workflows/example-yarn-modern.yml index b2cffe152..8efb38fc9 100644 --- a/.github/workflows/example-yarn-modern.yml +++ b/.github/workflows/example-yarn-modern.yml @@ -14,6 +14,12 @@ jobs: - name: Checkout uses: actions/checkout@v4 - run: corepack enable yarn # experimental - see https://nodejs.org/docs/latest/api/corepack.html + - name: Set up Yarn cache + uses: actions/setup-node@v4 + with: + node-version-file: '.node-version' + cache: yarn + cache-dependency-path: examples/yarn-modern/yarn.lock - name: Custom Yarn command uses: ./ with: diff --git a/README.md b/README.md index 0fd506756..0e241d0c5 100644 --- a/README.md +++ b/README.md @@ -1204,7 +1204,9 @@ jobs: ### Yarn Modern -To install dependencies using a `yarn.lock` file from [Yarn Modern](https://yarnpkg.com/) (Yarn 2 and later) you need to override the default [Yarn 1 (Classic)](https://classic.yarnpkg.com/) installation command `yarn --frozen-lockfile`. You can do this by using the `install-command` parameter and specifying `yarn install` for example: +To install dependencies using a `yarn.lock` file from [Yarn Modern](https://yarnpkg.com/) (Yarn 2 and later) you need to override the default [Yarn 1 (Classic)](https://classic.yarnpkg.com/) installation command `yarn --frozen-lockfile`. You can do this by using the `install-command` parameter and specifying `yarn install` as in the example below. + +The action supports built-in caching of Yarn Classic dependencies only. To cache Yarn Modern dependencies additionally use [actions/setup-node](https://github.com/actions/setup-node) and specify `cache: yarn`. ```yaml name: example-yarn-modern @@ -1215,6 +1217,13 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + - run: corepack enable # (experimental and optional) + - name: Set up Yarn cache + uses: actions/setup-node@v4 + with: + node-version: 22 + cache: yarn + cache-dependency-path: examples/yarn-modern/yarn.lock - name: Cypress run uses: cypress-io/github-action@v6 with: @@ -1231,6 +1240,8 @@ This example covers the [`.yarnrc.yml`](https://yarnpkg.com/configuration/yarnrc When using [Yarn Modern](https://yarnpkg.com/) (Yarn 2 and later) with [Plug'n'Play](https://yarnpkg.com/features/pnp) enabled, you will need to use the `command` parameter to run [`yarn`](https://yarnpkg.com/cli/run) instead of [`npx`](https://docs.npmjs.com/cli/v9/commands/npx). +See the above [Yarn Modern](#yarn-modern) section for information on caching Yarn Modern dependencies. + ```yaml name: example-yarn-modern-pnp on: push