cypress-io / cypress-io/github-action

Add workspace support for pnpm

Open
#1,144 11 comments 4 reactions 0 assignees View on GitHub
type: feature
Dominant language
JavaScript
Stars
1.5k
Forks
353
Avg merge
1d 22h
Merged PRs (30d)
27

Description

- This is an enhancement suggestion in response to issues #1054 and #1138.

## What would you like

When the `cypress-io/github-action` processes a project with a `pnpm-lock.yaml` lockfile from the [pnmp package manager](https://pnpm.io/) it should be able to interpret [pnpm workspaces](https://pnpm.io/workspaces) correctly and run Cypress from a pnpm workspace, including dependency installation and caching.

For example, the following should work:

```yml
- name: Cypress test
uses: cypress-io/github-action@v6
with:
working-directory: examples/start-and-pnpm-workspaces/packages/workspace-1
```

This fails because Cypress can't find `pnpm-lock.yaml` to install dependencies.

- For pnpm dependency caching see enhancement suggestion #1044.

## Why is this needed?

The workspace of a pnpm project does not contain any `pnpm-lock.yaml` file and `cypress-io/github-action` does not read and interpret any `pnpm-workspace.yaml` file in the root of a pnpm project using workspaces. This means that the action needs to be applied twice, once in the root and then again in the workspace in order to run Cypress in a pnpm workspace. (See [pnpm workspaces](https://github.com/cypress-io/github-action/blob/master/README.md#pnpm-workspaces).) This is error prone.

The `cypress-io/github-action` already provides support for [Yarn workspaces](https://github.com/cypress-io/github-action/blob/master/README.md#yarn-workspaces). Not providing this functionality for pnpm projects with workspaces is inconsistent.

The benefit for users of pnpm projects with workspaces is that the workflows using GitHub Actions can be written in a more simpler way. This reduces the risk of introducing errors especially with caching the Cypress binary.

## Background

[pnpm](https://pnpm.io/workspaces) 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:

```text
# repo root
/node_modules
/packages
/package.json
/pnpm-lock.yaml
/pnpm-workspace.yaml

# workspace 1
/packages/ws1
/packages/ws1/cypress/e2e/spec.cy.js
/packages/ws1/node_modules
/packages/ws1/cypress.config.js
/packages/ws1/package.json

# workspace 2
etc.
```

## Other

- PR https://github.com/cypress-io/github-action/pull/1140 added instructions in the [README > pnpm workspaces](https://github.com/cypress-io/github-action/blob/master/README.md#pnpm-workspaces) to describe how to handle this configuration without out-of-the-box support. See next section for snapshot of this text:

---

### pnpm workspaces

If you are using [pnpm workspaces](https://pnpm.io/workspaces) you need to install dependencies and run Cypress tests in a workspace in separate steps. The snippet below shows this principle.

```yml
...
- name: Install dependencies
uses: cypress-io/github-action@v6
with:
working-directory: examples/start-and-pnpm-workspaces
runTests: false

- name: Cypress test
uses: cypress-io/github-action@v6
with:
install: false
working-directory: examples/start-and-pnpm-workspaces/packages/workspace-1
...
```

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

See the example project [start-and-pnpm-workspaces](https://github.com/cypress-io/github-action/examples/start-and-pnpm-workspaces/) and the [example-start-and-pnpm-workspaces.yml](https://github.com/cypress-io/github-action/.github/workflows/example-start-and-pnpm-workspaces.yml) workflow for a full working example including pnpm caching.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.