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

ci: add bundle size report #1975

Merged
merged 20 commits into from
Feb 28, 2024
Merged

ci: add bundle size report #1975

merged 20 commits into from
Feb 28, 2024

Conversation

snitin315
Copy link
Member

@snitin315 snitin315 commented Jan 17, 2024

Workflow

PR

  • Read package exports & run size-limit on each component export.
  • Create json output file named PRBundleSizeStats.json
  • Compare PRBundleSizeStats.json with baseBundleSizeStats.json from the master and report the difference on PR via danger-js.

master

  • Read package exports & run size-limit on each component export.
  • Create json output file named baseBundleSizeStats.json.
  • Commit & push the baseBundleSizeStats.json file.

Addition info

Screenshot 2024-02-04 at 12 46 52 PM

Copy link

changeset-bot bot commented Jan 17, 2024

⚠️ No Changeset found

Latest commit: 84bac07

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@snitin315 snitin315 changed the title Ci/bundle-size-report ci: add bundle size report Jan 17, 2024
Copy link
Contributor

github-actions bot commented Jan 17, 2024

✅ PR title follows Conventional Commits specification.

Copy link

codesandbox-ci bot commented Jan 17, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 84bac07:

Sandbox Source
razorpay/blade: basic Configuration

@snitin315 snitin315 force-pushed the ci/bundle-size-report branch from 4405a91 to 9c287f4 Compare February 3, 2024 07:53
@rzpcibot
Copy link
Collaborator

rzpcibot commented Feb 3, 2024

Bundle Size Report

Updated Components
Status Component Base Size (kb) Current Size (kb) Diff
Accordion, AccordionItem 0.000 4.711 +4.711 KB
ActionList, ActionListItem, ActionListItemBadge, ActionListItemBadgeGroup, ActionListItemIcon, ActionListItemText, ActionListSection 0.000 12.480 +12.480 KB
Alert 0.000 11.119 +11.119 KB
Amount 0.000 1.114 +1.114 KB
Badge 0.000 0.850 +0.850 KB
BladeProvider 0.000 1.562 +1.562 KB
BottomSheet 0.000 9.516 +9.516 KB
Box 0.000 0.769 +0.769 KB
Card, CardBody, CardHeader, CardHeaderIcon, CardHeaderIconButton, CardHeaderLeading, CardHeaderTrailing, CardFooter, CardFooterLeading, CardFooterTrailing 0.000 8.836 +8.836 KB
Carousel, CarouselItem 0.000 6.876 +6.876 KB
Checkbox 0.000 5.910 +5.910 KB
Chip, ChipGroup 0.000 5.403 +5.403 KB
Collapsible, CollapsibleLink, CollapsibleButton, CollapsibleBody 0.000 9.285 +9.285 KB
Counter 0.000 0.808 +0.808 KB
Divider 0.000 0.562 +0.562 KB
Dropdown, DropdownOverlay, DropdownButton, DropdownLink, DropdownFooter, DropdownHeader 0.000 22.305 +22.305 KB
Indicator 0.000 0.953 +0.953 KB
List, ListItem, ListItemLink, ListItemCode, ListItemText 0.000 5.086 +5.086 KB
Modal 0.000 12.637 +12.637 KB
Popover, PopoverInteractiveWrapper 0.000 20.418 +20.418 KB
ProgressBar 0.000 1.719 +1.719 KB
Radio 0.000 4.720 +4.720 KB
Skeleton 0.000 0.780 +0.780 KB
SpotlightPopoverTour, SpotlightPopoverTourFooter, SpotlightPopoverTourStep 0.000 28.177 +28.177 KB
Switch 0.000 4.572 +4.572 KB
Table, TableHeader, TableHeaderCell, TableHeaderRow, TableBody, TableCell, TableRow, TableFooter, TableFooterCell, TableFooterRow, TablePagination, TableToolbar, TableToolbarActions 0.000 50.202 +50.202 KB
Tabs, TabItem, TabList, TabPanel 0.000 6.625 +6.625 KB
Tag 0.000 3.451 +3.451 KB
ToastContainer, useToast 0.000 12.496 +12.496 KB
Tooltip, TooltipInteractiveWrapper 0.000 15.259 +15.259 KB
Button 0.000 5.638 +5.638 KB
IconButton 0.000 0.824 +0.824 KB
CheckboxGroup 0.000 4.022 +4.022 KB
SelectInput, AutoComplete 0.000 17.262 +17.262 KB
OTPInput 0.000 11.462 +11.462 KB
PasswordInput 0.000 13.456 +13.456 KB
TextArea 0.000 11.848 +11.848 KB
TextInput 0.000 13.394 +13.394 KB
Link 0.000 2.098 +2.098 KB
RadioGroup 0.000 3.983 +3.983 KB
Spinner 0.000 1.929 +1.929 KB
Code 0.000 0.629 +0.629 KB
Display 0.000 0.524 +0.524 KB
Heading 0.000 0.488 +0.488 KB
Text 0.000 0.002 +0.002 KB

Generated by 🚫 dangerJS against 84bac07

@snitin315 snitin315 marked this pull request as ready for review February 4, 2024 08:59
@snitin315 snitin315 marked this pull request as draft February 4, 2024 08:59
@snitin315 snitin315 force-pushed the ci/bundle-size-report branch from c74fb27 to 0635f48 Compare February 4, 2024 15:23
@snitin315 snitin315 marked this pull request as ready for review February 5, 2024 04:38
@snitin315 snitin315 added the Review - L1 First level of review label Feb 6, 2024
Comment on lines 30 to 31
'ActionListItemAsset', // This is just an <img> tag
// These are same as Badge, Amount, Counter, Link, Text components
'CardHeaderAmount',
'CardHeaderBadge',
'CardHeaderCounter',
'CardHeaderLink',
'CardHeaderText',
Copy link
Member

Choose a reason for hiding this comment

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

Any harm in keeping these? They are wrappers but their size might increase decrease depending on the code we add later no.

Copy link
Member Author

Choose a reason for hiding this comment

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

It just increases the script run time, these components can add approx ~2mins. I believe these wrappers would hardly get updates. They have dev-only checks to verify amount is being used inside card only.

const _CardHeaderAmount = (props: AmountProps): React.ReactElement => {
useVerifyInsideCard('CardHeaderAmount');
return <Amount {...props} />;
};

Copy link
Collaborator

Choose a reason for hiding this comment

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

Add this in a comment for future reference. I was going to propose the same, to keep these components. But if it increases our CI time by 2 mins then we shouldn't

@kamleshchandnani
Copy link
Collaborator

instead of ✅ and 🚫 can we use 🟢 and 🔴 to be more clear?

@saurabhdaware
Copy link
Member

The check seems to take 15 - 17minutes 😢 Is there any alternate way to implement or any way to optimize this?

@snitin315
Copy link
Member Author

The check seems to take 15 - 17 minutes 😢 Is there any alternate way to implement or any way to optimize this?

Yeah, this is the time taken by the size limit package. But this is expected because we have to initialize and bundle a webpack project for each component. Let me try to use m1 MacOS on CI. Otherwise, we can move to our custom implementation in the future but that would be a significant effort.

saurabhdaware
saurabhdaware previously approved these changes Feb 20, 2024
@snitin315 snitin315 force-pushed the ci/bundle-size-report branch from 2e5f5b2 to 9fd449b Compare February 20, 2024 07:06
anuraghazra
anuraghazra previously approved these changes Feb 20, 2024
@@ -127,6 +127,7 @@
"watch:test:react-native": "yarn test:react-native --watch --onlyChanged",
"chromatic": "npx chromatic",
"publish-npm": "node ./scripts/publishToNpm.js",
"bundle-size": "node ./scripts/generateBundleSizeInfo.js",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Call it generate-bundle-size-info

Copy link
Collaborator

Choose a reason for hiding this comment

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

Run the build command before generating a bundle size info. This way we can ensure that the generated info is always on the latest changes and not some old build on local

Suggested change
"bundle-size": "node ./scripts/generateBundleSizeInfo.js",
"bundle-size": "yarn build && node ./scripts/generateBundleSizeInfo.js",

Copy link
Member Author

Choose a reason for hiding this comment

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

Done. We don't need to run the entire build, just the react:prod build. Added generate-bundle-size-info & pregenerate-bundle-size-info (this will automatically run before generate-bundle-size-info)

packages/blade/package.json Outdated Show resolved Hide resolved
Comment on lines 30 to 31
'ActionListItemAsset', // This is just an <img> tag
// These are same as Badge, Amount, Counter, Link, Text components
'CardHeaderAmount',
'CardHeaderBadge',
'CardHeaderCounter',
'CardHeaderLink',
'CardHeaderText',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add this in a comment for future reference. I was going to propose the same, to keep these components. But if it increases our CI time by 2 mins then we shouldn't

packages/blade/scripts/generateBundleDiff.js Outdated Show resolved Hide resolved
});

// Write the gathered size information to the specified file
const filename = process.env.BUNDLE_SIZE_STATS_FILENAME || 'PRBundleSizeStats.json';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Lets run prettier on this file once generated?

Copy link
Member Author

Choose a reason for hiding this comment

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

I feel prettier is not required, we need to store json just for diff. Someone will hardly read it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks terribly ugly otherwise. Even if its just for diff, lets format it properly and store. It will hardly take any time

packages/blade/scripts/generateBundleSizeInfo.js Outdated Show resolved Hide resolved
@snitin315 snitin315 added Review - L2 Second level of review and removed Review - L1 First level of review labels Feb 25, 2024
ci: fix size-limit check

ci: add bundle size check
@snitin315 snitin315 dismissed stale reviews from anuraghazra and saurabhdaware via a20ce9a February 25, 2024 18:49
@snitin315 snitin315 force-pushed the ci/bundle-size-report branch from 9fd449b to a20ce9a Compare February 25, 2024 18:49
@@ -25,6 +25,6 @@ runs:
if: steps.cache.outputs.cache-hit != 'true'

- name: Run postinstall script
run: yarn postinstall && yarn workspace @razorpay/blade postinstall
run: yarn postinstall
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why this change?

Copy link
Member Author

Choose a reason for hiding this comment

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

postinstall script is no longer required, it was just running patch-package for bundlemon & we no longer depend on bundlemon.

packages/blade/.gitignore Outdated Show resolved Hide resolved
packages/blade/scripts/generateBundleDiff.js Show resolved Hide resolved
packages/blade/scripts/generateBundleSizeInfo.js Outdated Show resolved Hide resolved
packages/blade/scripts/generateBundleSizeInfo.js Outdated Show resolved Hide resolved
@snitin315
Copy link
Member Author

Let's see how it goes 🙏🏻

@snitin315 snitin315 merged commit 24f1cbe into master Feb 28, 2024
17 checks passed
@snitin315 snitin315 deleted the ci/bundle-size-report branch February 28, 2024 10:37
anuraghazra pushed a commit that referenced this pull request Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Review - L2 Second level of review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants