-
Notifications
You must be signed in to change notification settings - Fork 25.1k
OSS CI: Store bundle size info for release branch as well #32418
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
Closed
Closed
Changes from all commits
Commits
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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -25,7 +25,7 @@ const datastore = require('./datastore'); | |
| const {createOrUpdateComment} = require('./make-comment'); | ||
|
|
||
| /** | ||
| * Generates and submits a comment. If this is run on main branch, data is | ||
| * Generates and submits a comment. If this is run on the main or release branch, data is | ||
| * committed to the store instead. | ||
| * @param {{ | ||
| 'android-hermes-arm64-v8a'?: number; | ||
|
|
@@ -47,8 +47,7 @@ async function reportSizeStats(stats, replacePattern) { | |
| ); | ||
| const collection = datastore.getBinarySizesCollection(store); | ||
|
|
||
| // Collect the current sizes for main branch only. | ||
| if (GITHUB_REF === 'main') { | ||
| if (GITHUB_REF === 'main' || GITHUB_REF.endsWith('-stable')) { | ||
| // Ensure we only store numbers greater than zero. | ||
| const validatedStats = Object.keys(stats).reduce((validated, key) => { | ||
| const value = stats[key]; | ||
|
|
@@ -59,65 +58,85 @@ async function reportSizeStats(stats, replacePattern) { | |
| validated[key] = value; | ||
| return validated; | ||
| }, {}); | ||
|
|
||
| if (Object.keys(validatedStats).length > 0) { | ||
| // Print out the new stats | ||
| const document = | ||
| (await datastore.getLatestDocument(collection, GITHUB_REF)) || {}; | ||
| const formattedStats = formatBundleStats(document, validatedStats); | ||
| console.log(formattedStats); | ||
|
|
||
| await datastore.createOrUpdateDocument( | ||
| collection, | ||
| GITHUB_SHA, | ||
| validatedStats, | ||
| GITHUB_REF, | ||
| ); | ||
| } | ||
| } else if (GITHUB_REF.endsWith('-stable')) { | ||
| console.log(`Skipping bundle size reporting for branch: ${GITHUB_REF}`); | ||
| } else { | ||
| const document = await datastore.getLatestDocument(collection); | ||
|
|
||
| const diffFormatter = new Intl.NumberFormat('en', {signDisplay: 'always'}); | ||
| const sizeFormatter = new Intl.NumberFormat('en', {}); | ||
|
|
||
| // | Platform | Engine | Arch | Size (bytes) | Diff | | ||
| // |:---------|:-------|:------------|-------------:|-----:| | ||
| // | android | hermes | arm64-v8a | 9437184 | ±0 | | ||
| // | android | hermes | armeabi-v7a | 9015296 | ±0 | | ||
| // | android | hermes | x86 | 9498624 | ±0 | | ||
| // | android | hermes | x86_64 | 9965568 | ±0 | | ||
| // | android | jsc | arm64-v8a | 9236480 | ±0 | | ||
| // | android | jsc | armeabi-v7a | 8814592 | ±0 | | ||
| // | android | jsc | x86 | 9297920 | ±0 | | ||
| // | android | jsc | x86_64 | 9764864 | ±0 | | ||
| // | android | jsc | x86_64 | 9764864 | ±0 | | ||
| // | ios | - | universal | 10715136 | ±0 | | ||
| const comment = [ | ||
| '| Platform | Engine | Arch | Size (bytes) | Diff |', | ||
| '|:---------|:-------|:-----|-------------:|-----:|', | ||
| ...Object.keys(stats).map(identifier => { | ||
| const [size, diff] = (() => { | ||
| const statSize = stats[identifier]; | ||
| if (!statSize) { | ||
| return ['n/a', '--']; | ||
| } else if (!(identifier in document)) { | ||
| return [statSize, 'n/a']; | ||
| } else { | ||
| return [ | ||
| sizeFormatter.format(statSize), | ||
| diffFormatter.format(statSize - document[identifier]), | ||
| ]; | ||
| } | ||
| })(); | ||
|
|
||
| const [platform, engineOrArch, ...archParts] = identifier.split('-'); | ||
| const arch = archParts.join('-') || engineOrArch; | ||
| const engine = arch === engineOrArch ? '-' : engineOrArch; // e.g. 'ios-universal' | ||
| return `| ${platform} | ${engine} | ${arch} | ${size} | ${diff} |`; | ||
| }), | ||
| '', | ||
| `Base commit: ${document.commit}`, | ||
| ].join('\n'); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. prettier/prettier: Replace |
||
| // For PRs, always compare vs main. | ||
| const document = | ||
| (await datastore.getLatestDocument(collection, 'main')) || {}; | ||
| const comment = formatBundleStats(document, stats); | ||
| createOrUpdateComment(comment, replacePattern); | ||
| } | ||
|
|
||
| await datastore.terminateStore(store); | ||
| } | ||
|
|
||
| /** | ||
| * Format the new bundle stats as compared to the latest stored entry. | ||
| * @param {firebase.firestore.DocumentData} document the latest entry to compare against | ||
| * @param {firebase.firestore.UpdateData} stats The stats to be formatted | ||
| * @returns {string} | ||
| */ | ||
| function formatBundleStats(document, stats) { | ||
| const diffFormatter = new Intl.NumberFormat('en', {signDisplay: 'always'}); | ||
| const sizeFormatter = new Intl.NumberFormat('en', {}); | ||
|
|
||
| // | Platform | Engine | Arch | Size (bytes) | Diff | | ||
| // |:---------|:-------|:------------|-------------:|-----:| | ||
| // | android | hermes | arm64-v8a | 9437184 | ±0 | | ||
| // | android | hermes | armeabi-v7a | 9015296 | ±0 | | ||
| // | android | hermes | x86 | 9498624 | ±0 | | ||
| // | android | hermes | x86_64 | 9965568 | ±0 | | ||
| // | android | jsc | arm64-v8a | 9236480 | ±0 | | ||
| // | android | jsc | armeabi-v7a | 8814592 | ±0 | | ||
| // | android | jsc | x86 | 9297920 | ±0 | | ||
| // | android | jsc | x86_64 | 9764864 | ±0 | | ||
| // | android | jsc | x86_64 | 9764864 | ±0 | | ||
| // | ios | - | universal | 10715136 | ±0 | | ||
| const formatted = [ | ||
| '| Platform | Engine | Arch | Size (bytes) | Diff |', | ||
| '|:---------|:-------|:-----|-------------:|-----:|', | ||
| ...Object.keys(stats).map(identifier => { | ||
| const [size, diff] = (() => { | ||
| const statSize = stats[identifier]; | ||
| if (!statSize) { | ||
| return ['n/a', '--']; | ||
| } else if (!(identifier in document)) { | ||
| return [statSize, 'n/a']; | ||
| } else { | ||
| return [ | ||
| sizeFormatter.format(statSize), | ||
| diffFormatter.format(statSize - document[identifier]), | ||
| ]; | ||
| } | ||
| })(); | ||
|
|
||
| const [platform, engineOrArch, ...archParts] = identifier.split('-'); | ||
| const arch = archParts.join('-') || engineOrArch; | ||
| const engine = arch === engineOrArch ? '-' : engineOrArch; // e.g. 'ios-universal' | ||
| return `| ${platform} | ${engine} | ${arch} | ${size} | ${diff} |`; | ||
| }), | ||
| '', | ||
| `Base commit: ${document.commit || '<unknown>'}`, | ||
| `Branch: ${document.branch || '<unknown>'}`, | ||
| ].join('\n'); | ||
|
|
||
| return formatted; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the size of the file at specified path in bytes. | ||
| * @param {fs.PathLike} path | ||
|
|
||
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.
prettier/prettier: Replace
·await·datastore.getLatestDocument(collection,·GITHUB_REFwith⏎········(await·datastore.getLatestDocument(collection,·GITHUB_REF)