-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
chore: upgrade lerna to 6, cache build step #26913
Conversation
4 failed and 35 flaky tests on run #49712 ↗︎
Details:
user_agent_override.cy.ts • 1 failed test • 5x-driver-electron
commands/navigation.cy.ts • 1 failed test • 5x-driver-chrome
specs_list_latest_runs.cy.ts • 1 flaky test • app-e2e
cypress-in-cypress-component.cy.ts • 1 flaky test • app-e2e
cypress-origin-communicator.cy.ts • 1 flaky test • app-e2e
commands/net_stubbing.cy.ts • 1 flaky test • 5x-driver-firefox
e2e/origin/commands/assertions.cy.ts • 1 flaky test • 5x-driver-firefox
The first 5 flaky specs are shown, see all 23 specs in Cypress Cloud. This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. |
3447479
to
0ab0281
Compare
Looks good, just need a rebase and one more +1. |
4da5978
to
dc39d62
Compare
7dcf95b
to
242e6db
Compare
@@ -1913,7 +1914,7 @@ jobs: | |||
- restore_cached_workspace | |||
- run: | |||
name: Build | |||
command: yarn workspace @cypress/webpack-preprocessor build | |||
command: yarn lerna run build --scope @cypress/webpack-preprocessor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order for these jobs to leverage caching we need to change them from yarn workspace
commands to yarn lerna run
commands
"targets": { | ||
"build": { | ||
"outputs": [ | ||
"{projectRoot}/types", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have to specify these outputs because we generate /types
in CI. By default, Nx looks in the following directories so deviations from those standards need to be specified.
"{workspaceRoot}/scripts" | ||
], | ||
"outputs": [ | ||
"{workspaceRoot}/cli/angular" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we copy these assets to the /cli
directory we need to specify them here.
"targets": { | ||
"build": { | ||
"inputs": [ | ||
"{workspaceRoot}/scripts" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We specify /scripts
because we still rely upon many node scripts for handling building (amongst other things). Any changes to a script should invalidate this lib. Eventually we can become more targeted and stricter in the future but we want to be more conservative to start off
@@ -23,14 +22,15 @@ | |||
"commander": "6.2.1", | |||
"find-up": "5.0.0", | |||
"fs-extra": "^9.1.0", | |||
"inquirer": "7.3.3", | |||
"glob": "^7.1.6", | |||
"inquirer": "8.2.4", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a required change as Lerna 6 depends upon [email protected]+
"targets": { | ||
"build": { | ||
"outputs": [ | ||
"{projectRoot}/src/**/*.js", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have to specify these like this because we currently do not place build assets in an outDir
and get placed next to the ts
files
77a44be
to
c4d5aab
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changeset looks good to me. Do we need to change the CONTRIBUTING guide to omit build-prod
? https://github.com/cypress-io/cypress/blob/jordanpowell88/lerna-6/CONTRIBUTING.md#package-level-scripts
@AtofStryker we could do that. I'm not sure why it's in there anyway, no one should be running build-prod during development. Although, I'm not sure if we need to update it |
@astone123 didn't we remove those build steps entirely though? It a) doesn't make sense why they are there and b) since we removed the steps, shouldn't we just update the contributing doc to remove them as well? otherwise the scripts would just fail, right? |
@AtofStryker no, there are still a few packages that use
because they were exactly the same and we can cache them if they're called as |
@astone123 OK that makes sense. So in CI when we run the unit-tests |
@AtofStryker yeah that's right, I added a call to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK makes sense to me!
Released in This comment thread has been locked. If you are still experiencing this issue after upgrading to |
Additional details
This PR does the following:
5
=>6
build
as cacheable stepIt allows for the
build
steps for the following packages to be cached locally and in the distributed cache (using Nx Cloud):cypress
(cli/
)@cypress/angular
create-cypress-tests
@cypress/schematic
@cypress/mount-utils
@cypress/react
@cypress/react18
@cypress/svelte
@cypress/vite-dev-server
@cypress/vite-plugin-cypress-esm
@cypress/vue
@cypress/vue2
@cypress/webpack-dev-server
@cypress/webpack-preprocessor
@packages/electron
@packages/errors
@packages/example
@packages/extension
@packages/icons
@packages/packherd-require
@packages/runner
@packages/telemetry
@packages/v8-snapshot-require
@tooling/electron-mksnapshot
@tooling/packherd
@tooling/v8-snapshot
Rationale
Most of the time when we work on the Cypress repo, we are only editing files in a few packages. If we've already built the source code for the other packages that we did not edit, then we shouldn't waste time and compute resources building all of those packages again.
We can use Lerna (using Nx under the hood) to cache builds when there have been no source code changes in the package. This way, when you run
yarn
oryarn build
, Lerna only builds the packages that we haven't already built with that exact source code in the past.As of right now we are being cautious to avoid accidental false positive cache hits, so we have configured Nx to invalidate the build cache for a package when any source files in the package change. In the future, and as we cache more steps, we should be able to fine-tune this so that we can exclude files that don't affect build outputs (
*.md
files,.eslintignore
, etc.).You can tell if Nx built your package from cache or not based on the output. To the right of the command, you will see some information in brackets like this
This tells us that Nx did not actually build the
@cypress/react18
package, but it pulled the build output from cache, because we've built@cypress/react18
with this exact source code before.To better understand Nx features related to caching, you can read the following
Escape hatches
If you are building the Cypress monorepo and Nx is incorrectly pulling a build from cache, you can run the command with the
--skip-nx-cache
flag, or setNX_SKIP_NX_CACHE=true
in your environment to force Nx to build everything from source and to ignore the cache. This normally should not happen, and if it does, then it means that we need to update the Nx configuration in the repo.Going forward
We still have a bunch of packages that are built and tasks that are run using Gulp. These can't be orchestrated or cached by Nx. There are lots of performance gains to be made by moving these tasks out of Gulp and executing them via yarn scripts with Nx. In the future, we will slowly move these tasks out of Gulp and use Nx to orchestrate and cache them.
Steps to test
Run
yarn
locally on this branch. A lot of the packages that we build during the postinstall step should be taken from the remote cache if you haven't changed any code since CI has already built these packages and uploaded the results to Nx Cloud.Make a change to the source code of a package from the list above, then run
yarn
again, and verify that the package was not built from cache but was actually built with your new source code changes.How has the user experience changed?
n/a
PR Tasks
cypress-documentation
?type definitions
?