-
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
size presubmit check #2720
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,93 @@ | ||||||||||
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)) | ||||||||||
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.
Suggested change
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. Done. |
||||||||||
} | ||||||||||
|
||||||||||
return reports; | ||||||||||
} | ||||||||||
|
||||||||||
// @firebase/* | ||||||||||
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.
Suggested change
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. Done. |
||||||||||
function generateReportForNPMPacakges() { | ||||||||||
hsubox76 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
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(), | ||||||||||
...generateReportForNPMPacakges() | ||||||||||
]; | ||||||||||
|
||||||||||
for (const r of reports) { | ||||||||||
console.log(r.sdk, r.type, r.value); | ||||||||||
} | ||||||||||
|
||||||||||
return { | ||||||||||
log: "https://www.goog.com", | ||||||||||
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. I guess this is only applicable to CI runs. So maybe we want to configure it to be some value when on CI and empty when running locally. Or we can leave this field empty. The only use of this field is to provide a link on the PR comment for developers to examine the original log (when they are surprised by the number.) 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. updated to report github action url. |
||||||||||
metric: "BinarySize", | ||||||||||
results: reports | ||||||||||
}; | ||||||||||
} | ||||||||||
|
||||||||||
generateSizeReport(); | ||||||||||
Feiyang1 marked this conversation as resolved.
Show resolved
Hide resolved
|
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.