Skip to content

Commit

Permalink
ci: fix
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Feb 4, 2024
1 parent 4f4d603 commit 88e23b5
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 14 deletions.
11 changes: 9 additions & 2 deletions packages/blade/PRBundleSizeStats.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@
{
"name": "Button",
"passed": true,
"size": 223142,
"size": 25142,
"sizeLimit": 2000000,
"loading": 0.5496484375
},
{
"name": "Card",
"passed": true,
"size": 3142,
"size": 39142,
"sizeLimit": 2000000,
"loading": 0.5496484375
},
{
"name": "Link",
"passed": true,
"size": 20142,
"sizeLimit": 2000000,
"loading": 0.5496484375
}
Expand Down
17 changes: 16 additions & 1 deletion packages/blade/dangerfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,25 @@ const generateBundleDiff = require('./scripts/generateBundleDiff');
const showBundleSizeDiff = async () => {
const { diffTable } = await generateBundleDiff(danger);

markdown(`
if (diffTable) {
markdown(`
## Bundle Size Report
<details>
<summary> Updated Components </summary>
${diffTable}
</details>
`);
} else {
markdown(`
## Bundle Size Report
No bundle size changes detected.
`);
}
};

showBundleSizeDiff();
31 changes: 20 additions & 11 deletions packages/blade/scripts/generateBundleDiff.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,41 @@ const generateBundleDiff = async () => {
);
}

if (bundleDiff.length === 0) {
return { diffTable: null };
}

bundleDiff.forEach((component) => {
const currentComponent = currentBundleSizeStats.find((stat) => stat.name === component.name);
const baseComponent = baseBundleSizeStats.find((stat) => stat.name === component.name);

if (baseComponent && !currentComponent) {
component.diffSize = -baseComponent.size;
component.baseSize = baseComponent.size;
component.diffSize = -baseComponent.size / 1000;
component.baseSize = baseComponent.size / 1000;
component.prSize = 0;
component.isSizeIncreased = false;
} else if (!baseComponent && currentComponent) {
component.diffSize = currentComponent.size;
component.diffSize = currentComponent.size / 1000;
component.baseSize = 0;
component.prSize = currentComponent.size;
component.prSize = currentComponent.size / 1000;
component.isSizeIncreased = true;
} else {
component.diffSize = currentComponent.size - baseComponent.size;
component.baseSize = baseComponent.size;
component.prSize = currentComponent.size;
component.diffSize = (currentComponent.size - baseComponent.size) / 1000;
component.baseSize = baseComponent.size / 1000;
component.prSize = currentComponent.size / 1000;
component.isSizeIncreased = component.diffSize > 0;
}
});

const diffTable = `
| Component | Base Size | Current Size | Diff |
| --- | --- | --- | --- |
| Status | Component | Base Size (kb) | Current Size (kb) | Diff |
| --- | --- | --- | --- | --- |
${bundleDiff
.map(
({ name, baseSize, prSize, diffSize }) =>
`| ${name} | ${baseSize / 1000} | ${prSize / 1000} | ${diffSize / 1000} kb |`,
({ name, baseSize, prSize, diffSize, isSizeIncreased }) =>
`| ${isSizeIncreased ? '🚫' : '✅'} | ${name} | ${baseSize} | ${prSize} | ${
isSizeIncreased ? `+${diffSize}` : diffSize
} kb |`,
)
.join('\n')}
`;
Expand Down

0 comments on commit 88e23b5

Please sign in to comment.