test: add pnpm workspaces example #1140
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue
The Cypress GitHub JavaScript Action (GHA) provides minimum support for projects using the pnpm package manager. It runs
pnpm install --frozen-lockfile
if it finds apnpm-lock.yaml
lockfile. It however offers no simple out-of-the-box provision for working with pnpm workspaces. There is no logic in GHA to deal with the lack of a lockfile in a pnpm workspace and so GHA is unable to install dependencies directly from the workspace.Background
pnpm has built-in support for monorepositories (AKA multi-package repositories, multi-project repositories, or monolithic repositories).
pnpm repos using workspaces and Cypress are typically structured similar to the following E2E example:
Requirements
An example is needed to show how the Cypress GitHub Action (GHA) can be used with pnpm workspaces to install and cache dependencies including the Cypress binary and run Cypress tests in a selected workspace.
Example structure
The action is run twice. Once to install dependencies and a second time to run Cypress tests.
cypress-io/github-action
is run in the root of the pnpm workspace example with the optionrunTests
set tofalse
. This installs all dependencies in all workspaces and caches the Cypress binary cache.cypress-io/github-action
is then run in a selected pnpm workspace using the optionworking_directory
set to the workspace directory with the optioninstall
set tofalse
. Cypress is able to run because thenode_modules
directory is populated from the previous step, and because the Cypress binary is also available in the cache.The example also includes caching of the pnpm store, like the non-workspace example for pnpm.
Additions
The example includes
examples/start-and-pnpm-workspaces
.github/workflows/example-start-and-pnpm-workspaces.yml
#pnpm-workspaces
Verification
GitHub
example-start-and-pnpm-workspaces
and check for successLinux-pnpm-store-xxx
cache of/home/runner/.local/share/pnpm/store/v3
for pnpm storecypress-linux-x64-xxx
cache of/home/runner/.cache/Cypres
for Cypress binarypnpm-linux-x64-xxx
cache of/home/runner/.npm
Local
Execute the following on Ubuntu 22.04 and check for success:
and repeat
The output should be similar to the following: