-
Notifications
You must be signed in to change notification settings - Fork 148
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
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
1b624cb
ci: fix bundlemon check
snitin315 e2d8deb
chore: remove unwanted changes
snitin315 72e5d64
chore: add comments
snitin315 0ae51dd
ci: use M1 MacOS runners for bundle size action
snitin315 144850e
fix: updates
snitin315 139f138
fix: updates
snitin315 eca70c2
fix: updates
snitin315 48ee678
fix: updates
snitin315 c39b36c
fix: updates
snitin315 3b2f7de
fix: updates
snitin315 ad1be92
fix: updates
snitin315 a20ce9a
fix: remove empty project size
snitin315 315dccd
fix: report actualu size
snitin315 af3f2f1
fix: report actual size
snitin315 23eecf3
ci: fix
snitin315 b0cd3d9
ci: fix
snitin315 256d1de
fix: exclude PopupArrow
snitin315 5fa5e42
chore: add baseBundleSizeStats.json & PRBundleSizeStats.json to .pret…
snitin315 6fe7be5
chore: prettify files & fix action edge acse
snitin315 84bac07
chore: fix lint
snitin315 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
name: Blade Bundle Size | ||
|
||
on: | ||
pull_request: | ||
types: [opened, synchronize, reopened] | ||
push: | ||
branches: | ||
- master | ||
|
||
env: | ||
GITHUB_ACCESS_TOKEN: ${{ secrets.CI_BOT_TOKEN }} | ||
|
||
jobs: | ||
pr-bundle-size: | ||
name: Generate PR Report | ||
runs-on: ubuntu-latest # nosemgrep: non-self-hosted-runner | ||
if: ${{ github.event_name == 'pull_request' }} | ||
steps: | ||
- name: Checkout Codebase | ||
uses: actions/checkout@v4 | ||
- name: Use Node v18 | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 18.12.1 | ||
- name: Setup Cache & Install Dependencies | ||
uses: ./.github/actions/install-dependencies | ||
- name: Update Bundle Size Data | ||
run: yarn generate-bundle-size-info | ||
working-directory: packages/blade | ||
- name: Danger | ||
run: yarn danger ci | ||
working-directory: packages/blade | ||
env: | ||
DANGER_GITHUB_API_TOKEN: ${{ env.GITHUB_ACCESS_TOKEN }} | ||
DANGER_DISABLE_TRANSPILATION: 'true' | ||
|
||
master-bundle-size: | ||
name: Update Base Stats | ||
runs-on: ubuntu-latest # nosemgrep: non-self-hosted-runner | ||
if: ${{ github.event_name == 'push' }} | ||
steps: | ||
- name: Checkout Codebase | ||
uses: actions/checkout@v4 | ||
- name: Use Node v18 | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 18.12.1 | ||
- name: Setup Cache & Install Dependencies | ||
uses: ./.github/actions/install-dependencies | ||
- name: Build Blade React Production | ||
run: yarn run-s build:clean build:generate-types build:react-prod | ||
working-directory: packages/blade | ||
- name: Update Bundle Size Data | ||
run: yarn generate-bundle-size-info | ||
working-directory: packages/blade | ||
env: | ||
BUNDLE_SIZE_STATS_FILENAME: 'baseBundleSizeStats.json' | ||
- name: Check if file is modified | ||
id: file-check | ||
run: if [ -n "$(git status baseBundleSizeStats.json --porcelain)" ]; then echo "result=true" >> $GITHUB_OUTPUT; else echo "result=false" >> $GITHUB_OUTPUT; fi | ||
working-directory: packages/blade | ||
- name: Commit Updated Bundle Size Data | ||
if: ${{ steps.file-check.outputs.result == 'true' }} | ||
run: | | ||
git config user.email "tools+cibot@razorpay.com" | ||
git config user.name "rzpcibot" | ||
git add baseBundleSizeStats.json | ||
git commit -m "chore: update bundle size data [skip ci]" | ||
git push | ||
working-directory: packages/blade |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const { danger, markdown } = require('danger'); | ||
const generateBundleDiff = require('./scripts/generateBundleDiff'); | ||
|
||
const showBundleSizeDiff = async () => { | ||
const { diffTable } = await generateBundleDiff(danger); | ||
|
||
if (diffTable) { | ||
markdown(` | ||
## Bundle Size Report | ||
|
||
<details> | ||
<summary> Updated Components </summary> | ||
|
||
${diffTable} | ||
|
||
</details> | ||
|
||
`); | ||
} else { | ||
markdown(` | ||
## Bundle Size Report | ||
|
||
No bundle size changes detected. | ||
`); | ||
} | ||
}; | ||
|
||
showBundleSizeDiff(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// Asynchronous function to generate the bundle size difference report | ||
const generateBundleDiff = async () => { | ||
// Array to store the base bundle size statistics | ||
let baseBundleSizeStats = []; | ||
// Get the base bundle size report from the master branch | ||
const baseBundleStatsURL = | ||
process.env.BASE_BUNDLE_SIZE_STATS_URL || | ||
'https://raw.githubusercontent.com/razorpay/blade/master/packages/blade/baseBundleSizeStats.json'; | ||
const response = await fetch(baseBundleStatsURL); | ||
|
||
// Parse the JSON response if the request is successful | ||
if (response.status === 200) { | ||
baseBundleSizeStats = await response.json(); | ||
} | ||
|
||
// Import the current bundle size statistics from the PR | ||
// eslint-disable-next-line import/extensions | ||
const currentBundleSizeStats = require('../prBundleSizeStats.json'); | ||
// Initialize the bundle difference array with current bundle stats | ||
let bundleDiff = currentBundleSizeStats; | ||
|
||
// Filter the components that don't have the same size in the base and current bundle | ||
if (baseBundleSizeStats.length > 0) { | ||
bundleDiff = baseBundleSizeStats.filter( | ||
({ size: baseSize, name: baseName }) => | ||
!currentBundleSizeStats.some( | ||
({ size: currentSize, name: currentName }) => | ||
currentSize === baseSize && currentName === baseName, | ||
), | ||
); | ||
} | ||
|
||
// If there is no difference, return null | ||
if (bundleDiff.length === 0) { | ||
return { diffTable: null }; | ||
} | ||
|
||
// Calculate the size differences and create a formatted diff table | ||
bundleDiff.forEach((component) => { | ||
if (component.name === 'Base') { | ||
return; | ||
} | ||
|
||
const currentComponent = currentBundleSizeStats.find((stat) => stat.name === component.name); | ||
const baseComponent = baseBundleSizeStats.find((stat) => stat.name === component.name); | ||
// Calculate the empty project size, including all dependencies, and subtract it from the component bundle size | ||
// This adjustment is crucial to obtain more accurate results, mitigating size differences due to additional dependencies in the project | ||
const emptyProjectSize = | ||
snitin315 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
currentBundleSizeStats.find((stat) => stat.name === 'Base').size / 1000; | ||
const currentComponentSize = currentComponent | ||
? currentComponent.size / 1000 - emptyProjectSize | ||
: 0; | ||
const baseComponentSize = baseComponent ? baseComponent.size / 1000 - emptyProjectSize : 0; | ||
|
||
if (baseComponent && !currentComponent) { | ||
snitin315 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Component removed in the PR | ||
component.diffSize = -baseComponentSize; | ||
component.baseSize = baseComponentSize; | ||
component.prSize = 0; | ||
component.isSizeIncreased = false; | ||
} else if (!baseComponent && currentComponent) { | ||
// Component added in the PR | ||
component.diffSize = currentComponentSize; | ||
component.baseSize = 0; | ||
component.prSize = currentComponentSize; | ||
component.isSizeIncreased = true; | ||
} else { | ||
// Component size changed in the PR | ||
component.diffSize = currentComponentSize - baseComponentSize; | ||
component.baseSize = baseComponentSize; | ||
component.prSize = currentComponentSize; | ||
component.isSizeIncreased = component.diffSize > 0; | ||
} | ||
}); | ||
|
||
// Generate a Markdown table for the bundle size differences | ||
const diffTable = ` | ||
| Status | Component | Base Size (kb) | Current Size (kb) | Diff | | ||
| --- | --- | --- | --- | --- | | ||
${bundleDiff | ||
.filter(({ name }) => name !== 'Base') | ||
.map( | ||
({ name, baseSize, prSize, diffSize, isSizeIncreased }) => | ||
`| ${isSizeIncreased ? '⬆' : '⬇'} | ${name} | ${baseSize.toFixed(3)} | ${prSize.toFixed( | ||
3, | ||
)} | ${isSizeIncreased ? `+${diffSize.toFixed(3)}` : diffSize.toFixed(3)} KB |`, | ||
) | ||
.join('\n')} | ||
`; | ||
|
||
return { diffTable }; | ||
}; | ||
|
||
module.exports = generateBundleDiff; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why this change?
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.
postinstall script is no longer required, it was just running patch-package for bundlemon & we no longer depend on bundlemon.