-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
[ci] Use dangerJS to report bundle size changes #14587
Conversation
366ee80
to
3323e02
Compare
tmp/ was not created on ci
Use circle ci workspaces to persist build output. attach that workspace in a size_snapshot job. dangerJS will later run in that job and report size changes. An additional persist_size_snapshot will later upload the size-snapshot permanently. CircleCI artifacts are not supposed to be used permanently. Only "around build time".
createSizeSnapshot script takes care of this
was only removed to speed up CI
- improves code docs - move some generic utils to utils module
3323e02
to
a1ec9ea
Compare
This PR introduced some changes to the bundle size. @material-ui/core: parsed: +Infinity%, gzip: +Infinity% Details of bundle changes.Comparing: 23e10fa...24a3f80
|
allows for more useful comparison: - add means current.size abs change, +inf rel change - remove means -prev.size abs change, -100% rel change
looks "weird" otherwise
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.
@eps1lon This is significantly better than the current size-limit usage we have 😍! cc @ai. Danger updates the first comment as more work is done on the pull request, so we won't be spammed, perfect. I'm glad we could keep using size-limit :). This change significantly reduces the overhead of keeping track of 1 specific module. We can consider keeping track of all our components 💥! It's not something I would have tried before as one single change to a highly dependent module would have mean updating dozen of values by hand. It would have been too time-consuming.
This change will also save us time, we do no longer have to update the .size-limit.js
, then wait for the build to pass to merge a pull request. It was frustrating for our new contributors:
"It's red 😱. What have I done wrong?" cc @TrySound
- by depending on
test_build
we can recycle the build output via CircleCI workspaces
I would be cautious with this architectural choice. The last time I have tried this strategy, CircleCI was losing track of the workspace when rebuilding. We have a few flaky tests, we need to rebuild from time to time.
* @param {string[][]} body | ||
* @returns {string} | ||
*/ | ||
function generateMDTable(headers, body) { |
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.
Note for self: we could have used this abstraction the API markdown generation logic.
@@ -42,6 +42,7 @@ | |||
"prettier:all": "yarn babel-node ./scripts/prettier.js write", | |||
"size": "size-limit", | |||
"size:overhead:why": "size-limit --why ./test/size/overhead.js", | |||
"size:snapshot": "node scripts/createSizeSnapshot", | |||
"size:why": "size-limit --why packages/material-ui/build/index.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.
The best command ever! We might be able to kill 1KB by removing the usage of dom-helpers/styles
:) cc @joshwooding
Workspaces are not persisted between workflows (I think this is what you're referring to with If we have problems with workspaces between jobs then we can always run the builds before the size snapshot. |
This will leave a "fail" comment on the PR but it's better than having the build show green.
Inspired by facebook/react#11865
Example eps1lon#4 (comment) (browse through versions to see different views)
Abstract
report on any change in bundle size instead of failing on exceeding an arbitrary limit.
Motivation
CI will only ever inform us if a change exceeded a given size limit. This ensures that we keep track of every size increase via version control. However no reduction is explicitly reported. Not only should this be part of the review anyway. It can also hide future increases. Imagine feature A and B reducing the size limit. Now feature C will pass even if it increases the bundle. Now a feature D is proposed that exceeds the limit and now any historic information regarding the bundle size is gone. In addition to that it will mark that build as "failed" even if the change is considered "good".
Therefore I'm proposing to track bundle size for every change committed to this repo and simply adding a report to PRs how this would affect the bundle size.
Strategy
{ [bundleKey]: { parsed: number, gzip: number } }
mui-org/material-ui
repo i.e. every build that is not a PR.Implementation
Each point in the implementation corresponds to a bullet-point in #Strategy.
size-limit
has a programmatic API that creates webpack bundles for a given file and reads that sizetest_build
we can recycle the build output via CircleCI workspacesCircleCI has an obvious solution for persisting a size snapshot via build artifacts. However they state that those are not stored permanently and are only intended to be used around build time. We therefore have to use a different service.
We can't use any storage system because we couldn't control explicitly who would've access to it. CircleCI exposes environment variables either to every build or only non-fork builds. I didn't find another solution to expose write access to some storage without implicitly giving this away to any PR.
Which is why I ended up building my own solution on aws.
mui-org/material-ui
size-snapshot.json
build artifact from that build to a s3 bucket following the patternroot-bucket-name/artifacts/$branch/$commit/size-snapshot.json
artifacts/*
(for debugging)artifacts/*
public_repo
access following the docs. It should not be part of the org.Changes
.size-snapshot.json
from version controlCI pipeline
size_snapshot
that requirestest_build
test_build
before
after
public tokens
All tokens belong to private services. For testing things out it can stay that way. In the future we should move those to accounts that are handle by either board-members or whitelisted core-members (not every core-contributor needs access to those)
React has the token for the sizebot directly in source control and no issues as far as I know. By having this as an environment variable we can at least know when a token has been made public (code change that read the var).
The aws token is for an API gateway that has the lowest rate limit, free tier usage alerts and a 0.01$ limit. Like the bot token we can know if the token was read publicly and can revoke the token at this point.
material-size-bot comment breakdown
The comment includes changes to the main package bundles if the exceed parsed size by 300B or gzip size by 100B. A detailed breakdown is listed in a collapsible table.
The comment in this PR lists every bundle as +Infinity because no bundles are found previously. This displays that this approach is robust to new bundles that are introduced. Once this gets merged the first snapshot will be persisted and any PR that has a merge base after that will include a proper report.
TODO
CIRCLE_AWS_API_KEY
(¨and rename this one toit's passed via*_TOKEN
for consistencyx-api-key
and they're managed asKeys
)DANGER_GITHUB_API_TOKEN
mui-org/material-ui
instead ofeps1lon/material-ui