Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add pnpm workspaces example #1140

Merged
merged 1 commit into from
Mar 7, 2024

Conversation

MikeMcC399
Copy link
Collaborator

@MikeMcC399 MikeMcC399 commented Mar 7, 2024

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 a pnpm-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:

# 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.

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.

  1. cypress-io/github-action is run in the root of the pnpm workspace example with the option runTests set to false. This installs all dependencies in all workspaces and caches the Cypress binary cache.
  2. cypress-io/github-action is then run in a selected pnpm workspace using the option working_directory set to the workspace directory with the option install set to false. Cypress is able to run because the node_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

  1. a new directory examples/start-and-pnpm-workspaces
  2. a new workflow .github/workflows/example-start-and-pnpm-workspaces.yml
  3. a new entry in the README file under #pnpm-workspaces
  4. a new code block in scripts/update-cypress-latest-other.sh to automate updating the new example to the latest version of Cypress.

Verification

GitHub

  1. In default branch delete all related caches (Actions > Caches)
  2. Run workflow example-start-and-pnpm-workspaces and check for success
  3. Check for new caches
    • Linux-pnpm-store-xxx cache of /home/runner/.local/share/pnpm/store/v3 for pnpm store
    • cypress-linux-x64-xxx cache of /home/runner/.cache/Cypres for Cypress binary
    • pnpm-linux-x64-xxx cache of /home/runner/.npm
  4. Run workflow again and check for success (existing caches being used successfully)

Local

Execute the following on Ubuntu 22.04 and check for success:

git clean -x -f -d
npm run update:cypress

and repeat

npm run update:cypress

The output should be similar to the following:

updating pnpm workspaces example to Cypress latest version

updating examples/start-and-pnpm-workspaces to cypress@latest
Scope: all 3 workspace projects
Progress: resolved 236, reused 236, downloaded 0, added 0, done
Done in 2.8s
Legend: production dependency, optional only, dev only

workspace-1@1.0.0 /home/mike/github/cypress-io/github-action/examples/start-and-pnpm-workspaces/packages/workspace-1

devDependencies:
cypress 13.6.6

workspace-2@1.0.0 /home/mike/github/cypress-io/github-action/examples/start-and-pnpm-workspaces/packages/workspace-2

devDependencies:
cypress 13.6.6

@cypress-app-bot
Copy link

@MikeMcC399 MikeMcC399 added documentation Improvements or additions to documentation type: enhancement New feature or request tests ci labels Mar 7, 2024
@MikeMcC399
Copy link
Collaborator Author

README Preview

https://github.com/MikeMcC399/github-action/tree/pnpm-workspaces?tab=readme-ov-file#pnpm-workspaces

The badge shows no status since workflow does not yet exist in the master branch.

@MikeMcC399 MikeMcC399 marked this pull request as ready for review March 7, 2024 12:29
Copy link
Member

@jennifer-shehane jennifer-shehane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MikeMcC399 This is great. Thanks for the thorough addition and the explanation on how to test it.

@jennifer-shehane jennifer-shehane merged commit 4090c65 into cypress-io:master Mar 7, 2024
76 checks passed
@MikeMcC399
Copy link
Collaborator Author

@jennifer-shehane

This is great. Thanks for the thorough addition and the explanation on how to test it.

There have been a couple of users lately who were struggling to use the action with pnpm workspaces, so that was the motivation to put together a working demo. I will also submit an enhancement request, just so the requirement is documented.

Copy link

🎉 This PR is included in version 6.7.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci documentation Improvements or additions to documentation released tests type: enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants