Skip to content

Commit

Permalink
Stop reporting gzipped compressed size in the bundle-size task
Browse files Browse the repository at this point in the history
  • Loading branch information
danielrozenberg committed Sep 9, 2019
1 parent 5295f4d commit 12243e0
Showing 1 changed file with 40 additions and 73 deletions.
113 changes: 40 additions & 73 deletions build-system/tasks/bundle-size.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ const {
isTravisPushBuild,
travisRepoSlug,
} = require('../travis');
const {getStdout} = require('../exec');
const {gitCommitHash, gitTravisMasterBaseline} = require('../git');

const runtimeFile = './dist/v0.js';
Expand All @@ -43,25 +42,6 @@ const bundleSizeAppBaseUrl = 'https://amp-bundle-size-bot.appspot.com/v0/';

const {red, cyan, yellow} = colors;

/**
* Get the gzipped bundle size of the current build.
*
* @return {string} the bundle size in KB rounded to 2 decimal points.
*/
function getGzippedBundleSize() {
const cmd = `npx bundlesize -f "${runtimeFile}"`;
log('Running', cyan(cmd) + '...');
const output = getStdout(cmd).trim();

const bundleSizeOutputMatches = output.match(/PASS .*: (\d+.?\d*KB) .*/);
if (bundleSizeOutputMatches) {
const bundleSize = parseFloat(bundleSizeOutputMatches[1]);
log('Bundle size', cyan('(gzipped)'), 'is', cyan(`${bundleSize}KB`));
return bundleSize;
}
throw Error('could not infer bundle size from output.');
}

/**
* Get the brotli bundle size of the current build.
*
Expand Down Expand Up @@ -117,55 +97,47 @@ async function storeBundleSize() {
auth: `token ${process.env.GITHUB_ARTIFACTS_RW_TOKEN}`,
});

for (const [compression, extension, getBundleSize] of [
['gzip', '', getGzippedBundleSize],
['brotli', '.br', getBrotliBundleSize],
]) {
const bundleSize = `${getBundleSize()}KB`;
const bundleSizeFile = `${gitCommitHash()}${extension}`;
const githubApiCallOptions = Object.assign(buildArtifactsRepoOptions, {
path: path.join('bundle-size', bundleSizeFile),
});
const bundleSize = `${getBrotliBundleSize()}KB`;
const bundleSizeFile = `${gitCommitHash()}.br`;
const githubApiCallOptions = Object.assign(buildArtifactsRepoOptions, {
path: path.join('bundle-size', bundleSizeFile),
});

try {
await octokit.repos.getContents(githubApiCallOptions);
log(
'The file',
cyan(`bundle-size/${bundleSizeFile}`),
'already exists in the',
'build artifacts repository on GitHub. Skipping...'
);
continue;
} catch {
// The file was not found in the GitHub repository, so continue to create
// it...
}
try {
await octokit.repos.getContents(githubApiCallOptions);
log(
'The file',
cyan(`bundle-size/${bundleSizeFile}`),
'already exists in the',
'build artifacts repository on GitHub. Skipping...'
);
} catch {
// The file was not found in the GitHub repository, so continue to create
// it...
}

try {
await octokit.repos.createOrUpdateFile(
Object.assign(githubApiCallOptions, {
message: `bundle-size: ${bundleSizeFile} (${bundleSize})`,
content: Buffer.from(bundleSize).toString('base64'),
})
);
log(
'Stored the new',
cyan(compression),
'bundle size of',
cyan(bundleSize),
'in the artifacts',
'repository on GitHub'
);
} catch (error) {
log(
red(
`ERROR: Failed to create the bundle-size/${bundleSizeFile} file in`
),
red('the build artifacts repository on GitHub!')
);
log(red('Error message was:'), error.message);
return Promise.reject(error);
}
try {
await octokit.repos.createOrUpdateFile(
Object.assign(githubApiCallOptions, {
message: `bundle-size: ${bundleSizeFile} (${bundleSize})`,
content: Buffer.from(bundleSize).toString('base64'),
})
);
log(
'Stored the new',
cyan('brotli'),
'bundle size of',
cyan(bundleSize),
'in the artifacts',
'repository on GitHub'
);
} catch (error) {
log(
red(`ERROR: Failed to create the bundle-size/${bundleSizeFile} file in`),
red('the build artifacts repository on GitHub!')
);
log(red('Error message was:'), error.message);
return Promise.reject(error);
}
return Promise.resolve();
}
Expand Down Expand Up @@ -210,8 +182,6 @@ async function skipBundleSize() {
async function reportBundleSize() {
if (isTravisPullRequestBuild()) {
const baseSha = gitTravisMasterBaseline();
// TODO(#21275): remove gzipped reporting within ~1 month.
const gzippedBundleSize = getGzippedBundleSize();
const brotliBundleSize = getBrotliBundleSize();
const commitHash = gitCommitHash();
try {
Expand All @@ -223,10 +193,7 @@ async function reportBundleSize() {
json: true,
body: {
baseSha,
// TODO(#21275): replace the default bundleSize value from the gzipped
// to the brotli value, once the bundle-size app prefers those.
bundleSize: gzippedBundleSize,
gzippedBundleSize,
bundleSize: brotliBundleSize,
brotliBundleSize,
},
});
Expand Down

0 comments on commit 12243e0

Please sign in to comment.