Skip to content

Commit 0073171

Browse files
committed
OSS CI: Store bundle size info for release branch as well (facebook#32418)
Summary: Pull Request resolved: facebook#32418 This commit does 2 things: * Process and store stats for *-stable branches, in addition to main * Print out the new stats to stdout, so that CI jobs can display them for verification purpose This also means a new field `branch` is used for the Firestore data. Changelog: [Internal] Reviewed By: hramos Differential Revision: D31717251 fbshipit-source-id: 9dbfa8fb8f0243c013dcd822230400d26c09eaa4
1 parent e18cf90 commit 0073171

2 files changed

Lines changed: 73 additions & 50 deletions

File tree

bots/datastore.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,14 @@ function getBinarySizesCollection(db) {
9292
* @param {firebase.firestore.CollectionReference<firebase.firestore.DocumentData>} collection
9393
* @param {string} sha The Git SHA used to identify the entry
9494
* @param {firebase.firestore.UpdateData} data The data to be inserted/updated
95+
* @param {string} branch The Git branch where this data was computed for
9596
* @returns {Promise<void>}
9697
*/
97-
function createOrUpdateDocument(collectionRef, sha, data) {
98+
function createOrUpdateDocument(collectionRef, sha, data, branch) {
9899
const stampedData = {
99100
...data,
100101
timestamp: firestore.Timestamp.now(),
102+
branch,
101103
};
102104
const docRef = firestore.doc(collectionRef, sha);
103105
return firestore.updateDoc(docRef, stampedData).catch(async error => {
@@ -115,14 +117,16 @@ function createOrUpdateDocument(collectionRef, sha, data) {
115117
* Returns the latest document in collection.
116118
*
117119
* @param {firebase.firestore.CollectionReference<firebase.firestore.DocumentData>} collection
120+
* @param {string} branch The Git branch for the data
118121
* @returns {Promise<firebase.firestore.DocumentData | undefined>}
119122
*/
120-
async function getLatestDocument(collectionRef) {
123+
async function getLatestDocument(collectionRef, branch) {
121124
try {
122125
const querySnapshot = await firestore.getDocs(
123126
firestore.query(
124127
collectionRef,
125128
firestore.orderBy('timestamp', 'desc'),
129+
firestore.where('branch', '==', branch),
126130
firestore.limit(1),
127131
),
128132
);

bots/report-bundle-size.js

Lines changed: 67 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const datastore = require('./datastore');
2525
const {createOrUpdateComment} = require('./make-comment');
2626

2727
/**
28-
* Generates and submits a comment. If this is run on main branch, data is
28+
* Generates and submits a comment. If this is run on the main or release branch, data is
2929
* committed to the store instead.
3030
* @param {{
3131
'android-hermes-arm64-v8a'?: number;
@@ -47,8 +47,7 @@ async function reportSizeStats(stats, replacePattern) {
4747
);
4848
const collection = datastore.getBinarySizesCollection(store);
4949

50-
// Collect the current sizes for main branch only.
51-
if (GITHUB_REF === 'main') {
50+
if (GITHUB_REF === 'main' || GITHUB_REF.endsWith('-stable')) {
5251
// Ensure we only store numbers greater than zero.
5352
const validatedStats = Object.keys(stats).reduce((validated, key) => {
5453
const value = stats[key];
@@ -59,65 +58,85 @@ async function reportSizeStats(stats, replacePattern) {
5958
validated[key] = value;
6059
return validated;
6160
}, {});
61+
6262
if (Object.keys(validatedStats).length > 0) {
63+
// Print out the new stats
64+
const document =
65+
(await datastore.getLatestDocument(collection, GITHUB_REF)) || {};
66+
const formattedStats = formatBundleStats(document, validatedStats);
67+
console.log(formattedStats);
68+
6369
await datastore.createOrUpdateDocument(
6470
collection,
6571
GITHUB_SHA,
6672
validatedStats,
73+
GITHUB_REF,
6774
);
6875
}
69-
} else if (GITHUB_REF.endsWith('-stable')) {
70-
console.log(`Skipping bundle size reporting for branch: ${GITHUB_REF}`);
7176
} else {
72-
const document = await datastore.getLatestDocument(collection);
73-
74-
const diffFormatter = new Intl.NumberFormat('en', {signDisplay: 'always'});
75-
const sizeFormatter = new Intl.NumberFormat('en', {});
76-
77-
// | Platform | Engine | Arch | Size (bytes) | Diff |
78-
// |:---------|:-------|:------------|-------------:|-----:|
79-
// | android | hermes | arm64-v8a | 9437184 | ±0 |
80-
// | android | hermes | armeabi-v7a | 9015296 | ±0 |
81-
// | android | hermes | x86 | 9498624 | ±0 |
82-
// | android | hermes | x86_64 | 9965568 | ±0 |
83-
// | android | jsc | arm64-v8a | 9236480 | ±0 |
84-
// | android | jsc | armeabi-v7a | 8814592 | ±0 |
85-
// | android | jsc | x86 | 9297920 | ±0 |
86-
// | android | jsc | x86_64 | 9764864 | ±0 |
87-
// | android | jsc | x86_64 | 9764864 | ±0 |
88-
// | ios | - | universal | 10715136 | ±0 |
89-
const comment = [
90-
'| Platform | Engine | Arch | Size (bytes) | Diff |',
91-
'|:---------|:-------|:-----|-------------:|-----:|',
92-
...Object.keys(stats).map(identifier => {
93-
const [size, diff] = (() => {
94-
const statSize = stats[identifier];
95-
if (!statSize) {
96-
return ['n/a', '--'];
97-
} else if (!(identifier in document)) {
98-
return [statSize, 'n/a'];
99-
} else {
100-
return [
101-
sizeFormatter.format(statSize),
102-
diffFormatter.format(statSize - document[identifier]),
103-
];
104-
}
105-
})();
106-
107-
const [platform, engineOrArch, ...archParts] = identifier.split('-');
108-
const arch = archParts.join('-') || engineOrArch;
109-
const engine = arch === engineOrArch ? '-' : engineOrArch; // e.g. 'ios-universal'
110-
return `| ${platform} | ${engine} | ${arch} | ${size} | ${diff} |`;
111-
}),
112-
'',
113-
`Base commit: ${document.commit}`,
114-
].join('\n');
77+
// For PRs, always compare vs main.
78+
const document =
79+
(await datastore.getLatestDocument(collection, 'main')) || {};
80+
const comment = formatBundleStats(document, stats);
11581
createOrUpdateComment(comment, replacePattern);
11682
}
11783

11884
await datastore.terminateStore(store);
11985
}
12086

87+
/**
88+
* Format the new bundle stats as compared to the latest stored entry.
89+
* @param {firebase.firestore.DocumentData} document the latest entry to compare against
90+
* @param {firebase.firestore.UpdateData} stats The stats to be formatted
91+
* @returns {string}
92+
*/
93+
function formatBundleStats(document, stats) {
94+
const diffFormatter = new Intl.NumberFormat('en', {signDisplay: 'always'});
95+
const sizeFormatter = new Intl.NumberFormat('en', {});
96+
97+
// | Platform | Engine | Arch | Size (bytes) | Diff |
98+
// |:---------|:-------|:------------|-------------:|-----:|
99+
// | android | hermes | arm64-v8a | 9437184 | ±0 |
100+
// | android | hermes | armeabi-v7a | 9015296 | ±0 |
101+
// | android | hermes | x86 | 9498624 | ±0 |
102+
// | android | hermes | x86_64 | 9965568 | ±0 |
103+
// | android | jsc | arm64-v8a | 9236480 | ±0 |
104+
// | android | jsc | armeabi-v7a | 8814592 | ±0 |
105+
// | android | jsc | x86 | 9297920 | ±0 |
106+
// | android | jsc | x86_64 | 9764864 | ±0 |
107+
// | android | jsc | x86_64 | 9764864 | ±0 |
108+
// | ios | - | universal | 10715136 | ±0 |
109+
const formatted = [
110+
'| Platform | Engine | Arch | Size (bytes) | Diff |',
111+
'|:---------|:-------|:-----|-------------:|-----:|',
112+
...Object.keys(stats).map(identifier => {
113+
const [size, diff] = (() => {
114+
const statSize = stats[identifier];
115+
if (!statSize) {
116+
return ['n/a', '--'];
117+
} else if (!(identifier in document)) {
118+
return [statSize, 'n/a'];
119+
} else {
120+
return [
121+
sizeFormatter.format(statSize),
122+
diffFormatter.format(statSize - document[identifier]),
123+
];
124+
}
125+
})();
126+
127+
const [platform, engineOrArch, ...archParts] = identifier.split('-');
128+
const arch = archParts.join('-') || engineOrArch;
129+
const engine = arch === engineOrArch ? '-' : engineOrArch; // e.g. 'ios-universal'
130+
return `| ${platform} | ${engine} | ${arch} | ${size} | ${diff} |`;
131+
}),
132+
'',
133+
`Base commit: ${document.commit || '<unknown>'}`,
134+
`Branch: ${document.branch || '<unknown>'}`,
135+
].join('\n');
136+
137+
return formatted;
138+
}
139+
121140
/**
122141
* Returns the size of the file at specified path in bytes.
123142
* @param {fs.PathLike} path

0 commit comments

Comments
 (0)