Skip to content

Commit 8a35f96

Browse files
authored
feat: add boolean option package-manager-cache (#1641)
* feat: add boolean option package-manager-cache * correct runTests parameter * update actions/setup-node to v6 * update actions versions in README
1 parent dca9861 commit 8a35f96

File tree

9 files changed

+192
-32
lines changed

9 files changed

+192
-32
lines changed

.github/workflows/example-basic-pnpm.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ jobs:
1111
strategy:
1212
fail-fast: false
1313
matrix:
14-
os: [ubuntu-24.04, windows-2025, macos-15]
14+
os:
15+
- ubuntu-24.04
16+
- windows-2025
17+
- macos-15
1518
runs-on: ${{ matrix.os }}
1619
steps:
1720
- name: Checkout
@@ -28,12 +31,13 @@ jobs:
2831
uses: actions/setup-node@v6
2932
with:
3033
node-version-file: '.node-version'
31-
cache: 'pnpm'
34+
cache: pnpm
3235
cache-dependency-path: examples/basic-pnpm/pnpm-lock.yaml
3336

3437
- name: Cypress tests
3538
uses: ./ # if copying, replace with cypress-io/github-action@v7
3639
with:
40+
package-manager-cache: false
3741
working-directory: examples/basic-pnpm
3842
# print information about detected browsers, etc
3943
# see https://on.cypress.io/command-line#cypress-info

.github/workflows/example-basic.yml

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
name: example-basic
22
# This workflow represents a set of basic End-to-End tests
3+
#
4+
# In the example jobs, the action is called with
5+
# uses: ./
6+
# which runs the action code from the current branch.
7+
# If you copy this workflow to another repo, replace the line with
8+
# uses: cypress-io/github-action@v7
39
on:
410
push:
511
branches:
@@ -12,14 +18,18 @@ jobs:
1218
strategy:
1319
fail-fast: false
1420
matrix:
15-
os: [ubuntu-22.04, ubuntu-24.04, windows-2025, macos-15]
21+
os:
22+
- ubuntu-22.04
23+
- ubuntu-24.04
24+
- windows-2025
25+
- macos-15
1626
runs-on: ${{ matrix.os }}
1727
steps:
1828
- name: Checkout
1929
uses: actions/checkout@v6
2030

2131
- name: Cypress tests
22-
uses: ./ # if copying, replace with cypress-io/github-action@v7
32+
uses: ./
2333
# the parameters below are only necessary
2434
# because we are running these examples in a monorepo
2535
with:
@@ -28,3 +38,31 @@ jobs:
2838
# print information about detected browsers, etc
2939
# see https://on.cypress.io/command-line#cypress-info
3040
build: npx cypress info
41+
42+
basic-npm-cache:
43+
# Use setup-node to cache npm dependencies
44+
strategy:
45+
fail-fast: false
46+
matrix:
47+
os:
48+
- ubuntu-22.04
49+
- ubuntu-24.04
50+
- windows-2025
51+
- macos-15
52+
runs-on: ${{ matrix.os }}
53+
steps:
54+
- name: Checkout
55+
uses: actions/checkout@v6
56+
- name: Setup Node.js
57+
uses: actions/setup-node@v6
58+
with:
59+
node-version-file: .node-version
60+
cache: npm
61+
cache-dependency-path: examples/basic/package-lock.json
62+
63+
- name: Cypress tests
64+
uses: ./
65+
with:
66+
package-manager-cache: false
67+
working-directory: examples/basic
68+
build: npx cypress info

.github/workflows/example-node-versions.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,15 @@ jobs:
2020
- 25
2121
name: Cypress E2E on Node v${{ matrix.node }}
2222
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v6
2325
- name: Install Node.js
2426
uses: actions/setup-node@v6
2527
with:
2628
node-version: ${{ matrix.node }}
2729
- run: node -v
2830
- run: npm -v
2931

30-
- name: Checkout
31-
uses: actions/checkout@v6
32-
3332
- name: Cypress tests
3433
uses: ./ # if copying, replace with cypress-io/github-action@v7
3534
with:

.github/workflows/example-start-and-pnpm-workspaces.yml

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,27 @@ jobs:
2626
- name: Checkout repository
2727
uses: actions/checkout@v6
2828

29-
# pnpm is not installed by default on GitHub runners
29+
# See https://github.com/pnpm/action-setup
3030
- name: Install pnpm
31-
run: npm install -g pnpm@10
31+
uses: pnpm/action-setup@v4
32+
with:
33+
version: 10
34+
35+
# See https://github.com/actions/setup-node
36+
- name: Install Node.js
37+
uses: actions/setup-node@v6
38+
with:
39+
node-version-file: '.node-version'
40+
cache: pnpm
41+
cache-dependency-path: examples/start-and-pnpm-workspaces/pnpm-lock.yaml
3242

3343
- name: Install dependencies
3444
# All dependencies including workspaces are installed
35-
run: pnpm install --frozen-lockfile
36-
working-directory: examples/start-and-pnpm-workspaces
45+
uses: ./
46+
with:
47+
package-manager-cache: false
48+
runTests: false
49+
working-directory: examples/start-and-pnpm-workspaces
3750

3851
- name: Cypress test Single
3952
# Run Cypress in examples/start-and-pnpm-workspaces/packages/workspace-1 only
@@ -66,11 +79,23 @@ jobs:
6679
uses: actions/checkout@v6
6780

6881
- name: Install pnpm
69-
run: npm install -g pnpm@10
82+
uses: pnpm/action-setup@v4
83+
with:
84+
version: 10
85+
86+
- name: Install Node.js
87+
uses: actions/setup-node@v6
88+
with:
89+
node-version-file: '.node-version'
90+
cache: pnpm
91+
cache-dependency-path: examples/start-and-pnpm-workspaces/pnpm-lock.yaml
7092

7193
- name: Install dependencies
72-
run: pnpm install --frozen-lockfile
73-
working-directory: examples/start-and-pnpm-workspaces
94+
uses: ./
95+
with:
96+
package-manager-cache: false
97+
runTests: false
98+
working-directory: examples/start-and-pnpm-workspaces
7499

75100
- name: Cypress test Multiple
76101
# Run Cypress in

.github/workflows/example-yarn-classic.yml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
name: example-yarn-classic
2+
# In the example jobs, the action is called with
3+
# uses: ./
4+
# which runs the action code from the current branch.
5+
# If you copy this workflow to another repo, replace the line with
6+
# uses: cypress-io/github-action@v7
27
on:
38
push:
49
branches:
@@ -14,6 +19,25 @@ jobs:
1419
uses: actions/checkout@v6
1520

1621
- name: Test with Yarn Classic
17-
uses: ./ # if copying, replace with cypress-io/github-action@v7
22+
uses: ./
1823
with:
1924
working-directory: examples/yarn-classic
25+
26+
yarn-classic-cache:
27+
# Use setup-node to cache Yarn dependencies
28+
runs-on: ubuntu-24.04
29+
steps:
30+
- name: Checkout
31+
uses: actions/checkout@v6
32+
- name: Setup Node.js
33+
uses: actions/setup-node@v6
34+
with:
35+
node-version-file: .node-version
36+
cache: yarn
37+
cache-dependency-path: examples/yarn-classic/yarn.lock
38+
39+
- name: Test with Yarn Classic
40+
uses: ./
41+
with:
42+
package-manager-cache: false
43+
working-directory: examples/yarn-classic

README.md

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ The following examples demonstrate the actions' functions.
6868
- Use [Yarn Modern](#yarn-modern)
6969
- Use [Yarn Plug'n'Play](#yarn-plugnplay)
7070
- Use [Yarn workspaces](#yarn-workspaces)
71+
- Disable [package manager cache](#package-manager-cache-disable)
7172
- Use [custom cache key](#custom-cache-key)
7273
- Run tests on multiple [Node versions](#node-versions)
7374
- Split [install and tests](#split-install-and-tests) into separate jobs
@@ -100,7 +101,7 @@ jobs:
100101
steps:
101102
- name: Checkout
102103
uses: actions/checkout@v6
103-
# Install npm dependencies, cache them correctly
104+
# Install dependencies with caching
104105
# and run all Cypress tests
105106
- name: Cypress run
106107
uses: cypress-io/github-action@v7
@@ -566,15 +567,14 @@ jobs:
566567
node: [20, 22, 24, 25]
567568
name: E2E on Node v${{ matrix.node }}
568569
steps:
570+
- name: Checkout
571+
uses: actions/checkout@v6
569572
- name: Install Node.js
570573
uses: actions/setup-node@v6
571574
with:
572575
node-version: ${{ matrix.node }}
573576
- run: node -v
574577
575-
- name: Checkout
576-
uses: actions/checkout@v6
577-
578578
- name: Cypress run
579579
uses: cypress-io/github-action@v7
580580
with:
@@ -663,7 +663,7 @@ jobs:
663663
steps:
664664
- name: Checkout
665665
uses: actions/checkout@v6
666-
# Install npm dependencies, cache them correctly
666+
# Install dependencies with caching
667667
# and run all Cypress tests with `quiet` parameter
668668
- name: Cypress run
669669
uses: cypress-io/github-action@v7
@@ -1167,9 +1167,14 @@ jobs:
11671167

11681168
### pnpm
11691169

1170-
The package manager `pnpm` is not pre-installed in [GitHub Actions runner images](https://github.com/actions/runner-images) (unlike `npm` and `yarn`) and so it must be installed in a separate workflow step (see below). If the action finds a `pnpm-lock.yaml` file, it uses the [pnpm](https://pnpm.io/cli/install) command `pnpm install --frozen-lockfile` by default to install dependencies.
1170+
The package manager `pnpm` is not pre-installed in [GitHub Actions runner images](https://github.com/actions/runner-images)
1171+
(unlike npm and Yarn Classic) and so it must be installed in a separate workflow step (see below).
1172+
If the action finds a `pnpm-lock.yaml` file, it uses the [pnpm](https://pnpm.io/cli/install) command `pnpm install --frozen-lockfile` by default to install dependencies.
11711173

1172-
The example below follows [pnpm recommendations](https://pnpm.io/continuous-integration#github-actions) for installing pnpm and caching the [pnpm store](https://pnpm.io/cli/store). Follow the [Cypress pnpm configuration instructions](https://docs.cypress.io/app/get-started/install-cypress#pnpm-configuration) and apply them to your project, to enable pnpm to install the Cypress binary.
1174+
The example below follows [pnpm recommendations](https://pnpm.io/continuous-integration#github-actions) for installing pnpm and caching the
1175+
[pnpm store](https://pnpm.io/cli/store).
1176+
Follow the [Cypress pnpm configuration instructions](https://docs.cypress.io/app/get-started/install-cypress#pnpm-configuration)
1177+
and apply them to your project, to enable pnpm to install the Cypress binary.
11731178

11741179
```yaml
11751180
name: example-basic-pnpm
@@ -1193,20 +1198,27 @@ jobs:
11931198
- name: Cypress run
11941199
uses: cypress-io/github-action@v7
11951200
with:
1201+
package-manager-cache: false
11961202
working-directory: examples/basic-pnpm
11971203
```
11981204

11991205
[![pnpm example](https://github.com/cypress-io/github-action/actions/workflows/example-basic-pnpm.yml/badge.svg)](.github/workflows/example-basic-pnpm.yml)
12001206

12011207
### pnpm workspaces
12021208

1203-
The action does not directly support using [pnpm workspaces](https://pnpm.io/workspaces) (see feature request [#1144](https://github.com/cypress-io/github-action/issues/1144)). As a workaround, you can install dependencies and run Cypress tests in a workspace in separate steps. The snippet below shows this principle.
1209+
The action does not directly support using [pnpm workspaces](https://pnpm.io/workspaces)
1210+
(see feature request [#1144](https://github.com/cypress-io/github-action/issues/1144)).
1211+
As a workaround, you can install dependencies and run Cypress tests in a workspace in separate steps.
1212+
The snippet below shows this principle.
12041213

12051214
```yml
12061215
...
12071216
- name: Install dependencies
1208-
run: pnpm install --frozen-lockfile
1209-
working-directory: examples/start-and-pnpm-workspaces
1217+
uses: cypress-io/github-action@v7
1218+
with:
1219+
package-manager-cache: false
1220+
runTests: false
1221+
working-directory: examples/start-and-pnpm-workspaces
12101222
12111223
- name: Cypress test
12121224
uses: cypress-io/github-action@v7
@@ -1329,6 +1341,38 @@ jobs:
13291341

13301342
[![Yarn workspaces example](https://github.com/cypress-io/github-action/actions/workflows/example-start-and-yarn-workspaces.yml/badge.svg)](.github/workflows/example-start-and-yarn-workspaces.yml)
13311343

1344+
### Package manager cache disable
1345+
1346+
When the action installs dependencies,
1347+
it caches the package manager cache from npm or from Yarn 1 (Classic) by default,
1348+
based on the [lockfile](#package-manager-cache) it discovers.
1349+
If package manager caching is implemented separately from the action,
1350+
for example to work with Yarn Modern or pnpm,
1351+
then disable the actions' package manager caching by setting the parameter
1352+
`package-manager-cache` to `false`.
1353+
1354+
GitHub's [actions/setup-node](https://github.com/actions/setup-node/blob/main/README.md) offers a convenient way to install a chosen version of Node.js
1355+
and to set up caching of package manager caches in one step.
1356+
1357+
```yml
1358+
name: Package manager caching
1359+
on: push
1360+
jobs:
1361+
cypress-run:
1362+
runs-on: ubuntu-24.04
1363+
name:
1364+
steps:
1365+
- uses: actions/checkout@v6
1366+
- uses: actions/setup-node@v6
1367+
with:
1368+
node-version: lts
1369+
cache: 'pnpm'
1370+
cache-dependency-path: pnpm-lock.yaml
1371+
- uses: cypress-io/github-action@v7
1372+
with:
1373+
package-manager-cache: false
1374+
```
1375+
13321376
### Custom cache key
13331377

13341378
Sometimes the default cache key does not work. For example, if you cannot share the Node modules across Node versions due to native extensions. In that case pass your own `cache-key` parameter.
@@ -1345,12 +1389,12 @@ jobs:
13451389
node: [20, 22, 24, 25]
13461390
name: E2E on Node v${{ matrix.node }}
13471391
steps:
1392+
- name: Checkout
1393+
uses: actions/checkout@v6
13481394
- name: Install Node.js
13491395
uses: actions/setup-node@v6
13501396
with:
13511397
node-version: ${{ matrix.node }}
1352-
- name: Checkout
1353-
uses: actions/checkout@v6
13541398
# run Cypress tests and record them under the same run
13551399
# associated with commit SHA and just give a different group name
13561400
- name: Cypress run
@@ -1379,10 +1423,10 @@ jobs:
13791423
node: [20, 22, 24, 25]
13801424
name: E2E on Node v${{ matrix.node }}
13811425
steps:
1426+
- uses: actions/checkout@v6
13821427
- uses: actions/setup-node@v6
13831428
with:
13841429
node-version: ${{ matrix.node }}
1385-
- uses: actions/checkout@v6
13861430
- uses: cypress-io/github-action@v7
13871431
```
13881432

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ inputs:
8383
install-command:
8484
description: 'Custom install command to use'
8585
required: false
86+
package-manager-cache:
87+
description: 'Set to false to disable automatic package manager caching. By default, package manager caching is enabled.'
88+
required: false
89+
default: true
8690
publish-summary:
8791
description: 'Whether or not to publish a job summary'
8892
required: false

0 commit comments

Comments
 (0)