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

Proof of Concept: Monitor Component bundle sizes #2005

Draft
wants to merge 44 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
9b3a914
install and setup compsizer
jamieomaguire Oct 18, 2024
66873dc
upgrade package
jamieomaguire Oct 18, 2024
56b1b0f
update package verison
jamieomaguire Oct 19, 2024
1e80a13
update version
jamieomaguire Oct 19, 2024
d357461
update version
jamieomaguire Oct 22, 2024
96786cd
remove old file
jamieomaguire Oct 22, 2024
01b2df6
add turbo command and to all components
jamieomaguire Oct 24, 2024
5ea75af
add bundle size json output to all components
jamieomaguire Oct 24, 2024
882a32b
remove filters from root command
jamieomaguire Oct 24, 2024
64a5440
run in ci
jamieomaguire Oct 25, 2024
c6730ee
use npx
jamieomaguire Oct 25, 2024
8a4a356
use yarn
jamieomaguire Oct 25, 2024
9d139c4
limit modal to fail analyse step
jamieomaguire Oct 25, 2024
64daaf7
move to ci command to fix build order
jamieomaguire Oct 25, 2024
d64b28f
remove ci suffix
jamieomaguire Oct 25, 2024
1221f8e
use beta compsizer version
jamieomaguire Oct 25, 2024
dea4534
try to use json error output in pr comment
jamieomaguire Oct 25, 2024
25f2602
debug
jamieomaguire Oct 25, 2024
c932168
debug
jamieomaguire Oct 25, 2024
059f3d8
debug threshold warning
jamieomaguire Oct 31, 2024
d9fad93
Merge branch 'main' into dsw-000-compsizer-poc
jamieomaguire Oct 31, 2024
b1b448f
remove baseline files
jamieomaguire Oct 31, 2024
327ba45
ignore baseline files
jamieomaguire Oct 31, 2024
3fec096
BREAKING: break button and modal size checks
jamieomaguire Nov 1, 2024
b0b2337
remove baseline and warnings from config
jamieomaguire Nov 1, 2024
8675e04
BREAKING: break cookie banner and tag
jamieomaguire Nov 1, 2024
0a03f98
Continue on errors and clean up previous error reports
jamieomaguire Nov 1, 2024
b136abd
Ensure cleanup works on windows
jamieomaguire Nov 1, 2024
905785f
Only run on linux/when input says to
jamieomaguire Nov 1, 2024
c8445c8
fix cookie banner, tag and assistive text sizes
jamieomaguire Nov 1, 2024
7c79343
delete old gh comment if needed
jamieomaguire Nov 1, 2024
1e1d34f
BREAKING: break link and card
jamieomaguire Nov 1, 2024
ab2d59a
only post report comment on failure and in ubuntu build
jamieomaguire Nov 1, 2024
e5c7e91
fix card and link
jamieomaguire Nov 1, 2024
eecb4d9
split report and cleanup tasks
jamieomaguire Nov 1, 2024
40aa2af
add watermark
jamieomaguire Nov 1, 2024
ed7b84f
add comment
jamieomaguire Nov 1, 2024
9e3af88
BREAKING: break lottie player
jamieomaguire Nov 1, 2024
08a905a
FIX: lottie player size
jamieomaguire Nov 1, 2024
5428096
bump to 0.5.2
jamieomaguire Nov 1, 2024
d4dcb30
remove baseline file config
jamieomaguire Nov 1, 2024
c021131
remove failure reports
jamieomaguire Nov 1, 2024
1086d2d
use next version compsizer and remove compression config
jamieomaguire Nov 1, 2024
9e93da3
use package.json files for config
jamieomaguire Nov 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/scripts/cleanup-component-size-report.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const fs = require('fs');
const path = require('path');

module.exports = async ({ github, context }) => {
const watermark = '<!-- COMPONENT_SIZE_REPORT -->';
const { owner, repo } = context.repo;
const issueNumber = context.payload.pull_request.number;

// Fetch existing comments and find the one with the watermark
const { data: comments } = await github.rest.issues.listComments({
owner,
repo,
issue_number: issueNumber,
});

const existingComment = comments.find(comment => comment.body.startsWith(watermark));

if (existingComment) {
console.log("Existing comment found, deleting.");
await github.rest.issues.deleteComment({
owner,
repo,
comment_id: existingComment.id,
});
} else {
console.log("No existing comment to delete.");
}
};
95 changes: 95 additions & 0 deletions .github/scripts/post-component-size-report.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
const fs = require('fs');
const path = require('path');

module.exports = async ({ github, context }) => {
const watermark = '<!-- COMPONENT_SIZE_REPORT -->';
let summary = "| Component | Expected Threshold | Actual Size (KB) |\n| --- | --- | --- |\n";

// Find all compsizer-failure-report.json files
const reportFiles = getAllReportFiles('packages/components');

// Log the files found to verify
console.log("Found report files:", reportFiles);

const { owner, repo } = context.repo;
const issueNumber = context.payload.pull_request.number;

// Fetch existing comments and find the one with the watermark
const { data: comments } = await github.rest.issues.listComments({
owner,
repo,
issue_number: issueNumber,
});

const existingComment = comments.find(comment => comment.body.startsWith(watermark));

// If no files are found, delete any existing comment and exit
// There is a separate action to do this in cleanup-component-size-report.js. But this is a fallback in case that step fails.
if (reportFiles.length === 0) {
console.log("No compsizer-failure-report.json files found. Checking for existing comment to delete.");

if (existingComment) {
console.log("Existing comment found, deleting.");
await github.rest.issues.deleteComment({
owner,
repo,
comment_id: existingComment.id,
});
} else {
console.log("No existing comment to delete.");
}
return;
}

// Build the markdown table from JSON data in each file
for (const file of reportFiles) {
try {
const data = JSON.parse(fs.readFileSync(file, 'utf-8'));

data.forEach(({ component, expectedThreshold, actualSizeKB }) => {
summary += `| ${component} | ${expectedThreshold} | ${actualSizeKB} |\n`;
});
} catch (error) {
console.error(`Failed to parse JSON in file ${file}:`, error);
}
}

// Check if summary was populated
console.log("Generated summary:", summary);

const commentBody = `${watermark}\n### Component Size Report\n${summary}`;

if (existingComment) {
// Update the existing comment
await github.rest.issues.updateComment({
owner,
repo,
comment_id: existingComment.id,
body: commentBody,
});
} else {
// Create a new comment
await github.rest.issues.createComment({
owner,
repo,
issue_number: issueNumber,
body: commentBody,
});
}
};

// Helper function to find all report files
function getAllReportFiles(dir) {
let results = [];
const list = fs.readdirSync(dir);
list.forEach((file) => {
const filePath = path.resolve(dir, file);
const stat = fs.statSync(filePath);
if (stat && stat.isDirectory()) {
results = results.concat(getAllReportFiles(filePath));
} else if (file === 'compsizer-failure-report.json') {
results.push(filePath);
}
});
return results;
}
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ jobs:
with:
os: ubuntu-latest
node-version: 20
analyse-component-bundles: true
secrets: inherit

unit-tests:
Expand Down
36 changes: 35 additions & 1 deletion .github/workflows/install-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ on:
required: false
type: string
default: 'build'
analyse-component-bundles:
type: boolean
required: false
default: false

env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
Expand All @@ -33,4 +37,34 @@ jobs:
- name: Build Packages
uses: ./.github/actions/run-script
with:
script-name: ${{ inputs.build-script }}
script-name: ${{ inputs.build-script }}
- name: Clean Up Old Component Size Failure Reports
if: inputs.analyse-component-bundles
run: |
echo "Cleaning up and verifying..."
find packages/components -type f -name 'compsizer-failure-report.json' -delete
echo "Remaining failure reports (if any):"
find packages/components -type f -name 'compsizer-failure-report.json'
- name: Analyse Component Bundle Sizes
if: inputs.analyse-component-bundles
run: yarn analyse-component-bundles --only --continue
- name: Cleanup Component Size Report
if: inputs.analyse-component-bundles && success()
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
env:
GITHUB_TOKEN: ${{ secrets.CHANGESETS_TOKEN }}
with:
github-token: ${{ secrets.CHANGESETS_TOKEN }}
script: |
const script = require('./.github/scripts/cleanup-component-size-report.js');
await script({ github, context });
- name: Post Component Size Report
if: inputs.analyse-component-bundles && failure()
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
env:
GITHUB_TOKEN: ${{ secrets.CHANGESETS_TOKEN }}
with:
github-token: ${{ secrets.CHANGESETS_TOKEN }}
script: |
const script = require('./.github/scripts/post-component-size-report.js');
await script({ github, context });
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,7 @@ custom-elements.json
# Yalc
.yalc
yalc.lock

# Compsizer
**/compsizer-failure-report.json
**/component-bundle-sizes.json
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"generate-component-statuses": "./utilities/component-statuses/generate-component-statuses.js"
},
"scripts": {
"analyse-component-bundles": "turbo run analyse-component-bundles --filter=!pie-monorepo",
"watch": "turbo run watch --filter=!pie-monorepo",
"build": "cross-env-shell turbo run build --filter=!'./apps/examples/*' --filter=!pie-monorepo --token=${TURBO_TOKEN}",
"build:dev": "cross-env-shell turbo run build:dev --filter=!'./apps/examples/*' --filter=!pie-monorepo --token=${TURBO_TOKEN}",
Expand Down Expand Up @@ -94,6 +95,7 @@
"autoprefixer": "10.4.20",
"babel-loader": "8.3.0",
"commitizen": "4.3.0",
"compsizer": "next",
"cross-env": "7.0.3",
"cssnano": "5.1.15",
"cz-customizable": "7.2.1",
Expand Down
14 changes: 13 additions & 1 deletion packages/components/pie-assistive-text/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"componentStatus": "beta"
},
"scripts": {
"analyse-component-bundles": "run -T compsizer",
"build": "run -T vite build",
"build:react-wrapper": "npx build-react-wrapper",
"create:manifest": "yarn cem analyze --litelement",
Expand Down Expand Up @@ -50,5 +51,16 @@
"customElements": "custom-elements.json",
"sideEffects": [
"dist/*.js"
]
],
"compsizer": {
"exclude": [
"**/*.d.ts"
],
"components": {
"pie-assistive-text": {
"maxSize": "50 KB",
"distFolderLocation": "./dist"
}
}
}
}
12 changes: 12 additions & 0 deletions packages/components/pie-button/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"componentStatus": "beta"
},
"scripts": {
"analyse-component-bundles": "run -T compsizer",
"build": "run -T vite build",
"build:react-wrapper": "npx build-react-wrapper",
"create:manifest": "yarn cem analyze --litelement",
Expand Down Expand Up @@ -52,5 +53,16 @@
"@justeattakeaway/pie-spinner": "0.7.2",
"@justeattakeaway/pie-webc-core": "0.24.2",
"element-internals-polyfill": "1.3.11"
},
"compsizer": {
"exclude": [
"**/*.d.ts"
],
"components": {
"pie-button": {
"maxSize": "50 KB",
"distFolderLocation": "./dist"
}
}
}
}
14 changes: 13 additions & 1 deletion packages/components/pie-card/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"componentStatus": "beta"
},
"scripts": {
"analyse-component-bundles": "run -T compsizer",
"build": "run -T vite build",
"build:react-wrapper": "npx build-react-wrapper",
"create:manifest": "yarn cem analyze --litelement",
Expand Down Expand Up @@ -50,5 +51,16 @@
"customElements": "custom-elements.json",
"sideEffects": [
"dist/*.js"
]
],
"compsizer": {
"exclude": [
"**/*.d.ts"
],
"components": {
"pie-card": {
"maxSize": "50 KB",
"distFolderLocation": "./dist"
}
}
}
}
14 changes: 13 additions & 1 deletion packages/components/pie-checkbox-group/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"componentStatus": "beta"
},
"scripts": {
"analyse-component-bundles": "run -T compsizer",
"build": "run -T vite build",
"build:react-wrapper": "npx build-react-wrapper",
"create:manifest": "yarn cem analyze --litelement",
Expand Down Expand Up @@ -51,5 +52,16 @@
"customElements": "custom-elements.json",
"sideEffects": [
"dist/*.js"
]
],
"compsizer": {
"exclude": [
"**/*.d.ts"
],
"components": {
"pie-checkbox-group": {
"maxSize": "50 KB",
"distFolderLocation": "./dist"
}
}
}
}
14 changes: 13 additions & 1 deletion packages/components/pie-checkbox/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"componentStatus": "beta"
},
"scripts": {
"analyse-component-bundles": "run -T compsizer",
"build": "run -T vite build",
"build:react-wrapper": "npx build-react-wrapper",
"create:manifest": "yarn cem analyze --litelement",
Expand Down Expand Up @@ -50,5 +51,16 @@
"customElements": "custom-elements.json",
"sideEffects": [
"dist/*.js"
]
],
"compsizer": {
"exclude": [
"**/*.d.ts"
],
"components": {
"pie-checkbox": {
"maxSize": "50 KB",
"distFolderLocation": "./dist"
}
}
}
}
14 changes: 13 additions & 1 deletion packages/components/pie-chip/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"componentStatus": "beta"
},
"scripts": {
"analyse-component-bundles": "run -T compsizer",
"build": "run -T vite build",
"build:react-wrapper": "npx build-react-wrapper",
"create:manifest": "yarn cem analyze --litelement",
Expand Down Expand Up @@ -51,5 +52,16 @@
"customElements": "custom-elements.json",
"sideEffects": [
"dist/*.js"
]
],
"compsizer": {
"exclude": [
"**/*.d.ts"
],
"components": {
"pie-chip": {
"maxSize": "50 KB",
"distFolderLocation": "./dist"
}
}
}
}
14 changes: 13 additions & 1 deletion packages/components/pie-cookie-banner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"componentStatus": "stable"
},
"scripts": {
"analyse-component-bundles": "run -T compsizer",
"build": "run -T vite build",
"build:react-wrapper": "npx build-react-wrapper",
"create:manifest": "yarn cem analyze --litelement",
Expand Down Expand Up @@ -57,5 +58,16 @@
"customElements": "custom-elements.json",
"sideEffects": [
"dist/*.js"
]
],
"compsizer": {
"exclude": [
"**/*.d.ts"
],
"components": {
"pie-cookie-banner": {
"maxSize": "50 KB",
"distFolderLocation": "./dist"
}
}
}
}
Loading
Loading