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

Move code of the icfy-analyze CircleCI task to a NPM script #39502

Merged
merged 2 commits into from
Feb 18, 2020

Conversation

jsnajdr
Copy link
Member

@jsnajdr jsnajdr commented Feb 18, 2020

In hope to get better error handling a recovery, I'm moving the commands for the icfy-analyze CircleCI task (the npm run preanalyze-bundles, running the bin/analyze-icfy.js script, moving files to artifacts folder) to a NPM script called analyze-icfy. That script chains the steps using && operator, relying on exit codes.

That should be more reliable (or at least more comprehensible) than the set +o errexit bash option.

This also creates a build-client-stats NPM script that's used by both analyze-bundles and analyze-icfy scripts.

For more context, see also:

  • icfy-analyze CI run where preanalyze-bundles failed with error and yet the task proceeded to run bin/icfy-analyze.js instead of terminating: https://circleci.com/gh/Automattic/wp-calypso/601462
  • a bug in cross-env I found and reported when investigating the above CI failure. The CI failure doesn't seem to involve a SIGINT signal anywhere, but yet it's the only way I see how a failed webpack build could lead to exit code 0.

In hope to get better error handling a recovery, I'm moving the commands for the
`icfy-analyze` CircleCI task (the `npm run preanalyze-bundles`, running the `bin/analyze-icfy.js`
script, moving files to artifacts folder) to a NPM script called `analyze-icfy`. That
script chains the steps using `&&` operator, relying on exit codes.

That should be more reliable (or at least more comprehensible) than the `set +o errexit` bash option.

This also creates a `build-client-stats` NPM script that's used by both `analyze-bundles` and
`analyze-icfy` scripts.
@jsnajdr jsnajdr added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. Build labels Feb 18, 2020
@jsnajdr jsnajdr requested review from sgomes, sirreal and a team February 18, 2020 08:33
@jsnajdr jsnajdr self-assigned this Feb 18, 2020
@matticbot
Copy link
Contributor

@matticbot
Copy link
Contributor

This PR does not affect the size of JS and CSS bundles shipped to the user's browser.

Generated by performance advisor bot at iscalypsofastyet.com.

Copy link
Member

@sirreal sirreal left a comment

Choose a reason for hiding this comment

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

I left a few questions, but this seems fine to try 👍

ICFY job completed successfully.

"preanalyze-bundles": "cross-env-shell NODE_ENV=production CALYPSO_ENV=production EMIT_STATS=true PROGRESS=true npm run -s build-client-evergreen",
"analyze-bundles": "webpack-bundle-analyzer client/stats.json public/evergreen -h 127.0.0.1 -p 9898 -s gzip",
"analyze-bundles": "npm run build-client-stats && webpack-bundle-analyzer client/stats.json public/evergreen -h 127.0.0.1 -p 9898 -s gzip",
"analyze-icfy": "npm run build-client-stats && node --max-old-space-size=4096 bin/icfy-analyze.js && mv client/stats.json client/chart.json \"$CIRCLE_ARTIFACTS/icfy\"",
Copy link
Member

Choose a reason for hiding this comment

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

If there's an issue with cross-env-shell that results in a 0 exist status when we expect non-0, this type of chaining will fail to capture that, won't it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that's true. I discovered the cross-env issue only after migrating the icfy-analyze task to a NPM script and debugging it.

In other words, I don't expect this PR to solve any of the problems, but the refactoring still seems like a good idea to me 🙂

package.json Outdated
@@ -81,6 +81,7 @@
"build-client-both": "CONCURRENT_BUILDS=2 concurrently -c cyan -n \"fallback ,evergreen\" \"npm run build-client-fallback\" \"npm run build-client-evergreen\"",
"build-client-if-prod": "node -e \"process.env.CALYPSO_ENV === 'production' && process.exit(1)\" || npm run build-client-both",
"build-client-if-desktop": "node -e \"(process.env.CALYPSO_ENV === 'desktop' || process.env.CALYPSO_ENV === 'desktop-development') && process.exit(1)\" || npm run build-client-fallback",
"build-client-stats": "cross-env-shell NODE_ENV=production CALYPSO_ENV=production EMIT_STATS=true PROGRESS=true npm run build-client-evergreen",
Copy link
Member

Choose a reason for hiding this comment

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

If we have issues with cross-env-shell, I think we can drop it here.

Copy link
Member Author

Choose a reason for hiding this comment

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

We can drop cross-env completely, but it means dropping the remaining support for Windows that we have.

cross-env doesn't do anything useful on Unix systems: the shell already understands the ENV_VAR=value command --to-run syntax. It's useful for Windows: there, cross-env will parse the ENV_VAR=value prefixes, and sets up the environment and runs command --to-run in a way that Windows cmd.exe understands.

While removing cross-env, we could also get rid of rimraf and friends and replace them with rm -rf. That saves time where npm rimraf needs to download the package from the NPM registry.

Copy link
Contributor

@sgomes sgomes Feb 18, 2020

Choose a reason for hiding this comment

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

If we have issues with cross-env-shell, I think we can drop it here.

+1. I think it's reasonable to remove the ability for non-Unix developers to generate stats while we wait for the cross-env-shell fix.

Copy link
Contributor

Choose a reason for hiding this comment

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

We can drop cross-env completely, but it means dropping the remaining support for Windows that we have.

I'm not sure I'd remove it permanently, more as a temporary measure. I'm hoping that cross-env-shell will be fixed at some point, or perhaps we can find an earlier version of it without the bug.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, I removed the cross-env usages in 02d3d34

The terser issue and the swallowed exit codes can bite at any time, including a production build.

Copy link
Contributor

@sgomes sgomes left a comment

Choose a reason for hiding this comment

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

LGTM 👍 Seems like a good refactor to remove as much logic as possible from the CircleCI config, and everything still seems to be working both locally and on CI.

@jsnajdr jsnajdr merged commit 84c84cb into master Feb 18, 2020
@jsnajdr jsnajdr deleted the move/icfy-analyze-to-npm-script branch February 18, 2020 18:24
@matticbot matticbot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Feb 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants