-
Notifications
You must be signed in to change notification settings - Fork 940
size presubmit check #2720
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
size presubmit check #2720
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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 |
---|---|---|
@@ -0,0 +1,95 @@ | ||
const { resolve } = require('path'); | ||
const fs = require('fs'); | ||
const { execSync } = require('child_process'); | ||
|
||
const repoRoot = resolve(__dirname, '..'); | ||
|
||
const commitHash = process.env.GITHUB_SHA || execSync('git rev-parse HEAD').toString(); | ||
const runId = process.env.GITHUB_RUN_ID || 'local-run-id'; | ||
|
||
// CDN scripts | ||
function generateReportForCDNScripts() { | ||
const reports = []; | ||
const firebaseRoot = resolve(__dirname, '../packages/firebase'); | ||
const pkgJson = require(`${firebaseRoot}/package.json`); | ||
|
||
const special_files = [ | ||
'firebase-performance-standalone.es2017.js', | ||
'firebase-performance-standalone.js', | ||
'firebase.js' | ||
]; | ||
|
||
const files = [ | ||
...special_files.map(file => `${firebaseRoot}/${file}`), | ||
...pkgJson.components.map(component => `${firebaseRoot}/firebase-${component}.js`) | ||
]; | ||
|
||
for (const file of files) { | ||
const { size } = fs.statSync(file); | ||
const fileName = file.split('/').slice(-1)[0]; | ||
reports.push(makeReportObject('firebase', fileName, size)); | ||
} | ||
|
||
return reports; | ||
} | ||
|
||
// NPM packages | ||
function generateReportForNPMPackages() { | ||
const reports = []; | ||
const fields = [ | ||
'main', | ||
'module', | ||
'esm2017', | ||
'browser', | ||
'react-native', | ||
'lite', | ||
'lite-esm2017' | ||
]; | ||
|
||
const packageInfo = JSON.parse( | ||
execSync('npx lerna ls --json --scope @firebase/*', { cwd: repoRoot }).toString() | ||
); | ||
|
||
for (const package of packageInfo) { | ||
const packageJson = require(`${package.location}/package.json`); | ||
|
||
for (const field of fields) { | ||
if (packageJson[field]) { | ||
const filePath = `${package.location}/${packageJson[field]}`; | ||
const { size } = fs.statSync(filePath); | ||
reports.push(makeReportObject(packageJson.name, field, size)); | ||
} | ||
} | ||
} | ||
|
||
return reports; | ||
} | ||
|
||
function makeReportObject(sdk, type, value) { | ||
return { | ||
sdk, | ||
type, | ||
value | ||
}; | ||
} | ||
|
||
function generateSizeReport() { | ||
const reports = [ | ||
...generateReportForCDNScripts(), | ||
...generateReportForNPMPackages() | ||
]; | ||
|
||
for (const r of reports) { | ||
console.log(r.sdk, r.type, r.value); | ||
} | ||
|
||
console.log(`Github Action URL: https://github.com/firebase/firebase-js-sdk/actions/runs/${runId}`); | ||
|
||
return { | ||
log: `https://github.com/firebase/firebase-js-sdk/actions/runs/${runId}`, | ||
metric: "BinarySize", | ||
results: reports | ||
}; | ||
} | ||
|
||
generateSizeReport(); | ||
Feiyang1 marked this conversation as resolved.
Show resolved
Hide resolved
|
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.
We seem to use
simple-git
for git operations in other places in this repo.I'm okay with both. Will leave it up to you whether we want to pursue any consistency.