Skip to content

Commit

Permalink
🏗 Make bundle-size reporting failures non-blocking (#32864)
Browse files Browse the repository at this point in the history
  • Loading branch information
rsimha committed Feb 24, 2021
1 parent e908431 commit aeccddf
Showing 1 changed file with 30 additions and 31 deletions.
61 changes: 30 additions & 31 deletions build-system/tasks/bundle-size/index.js
Expand Up @@ -35,7 +35,7 @@ const {
VERSION: internalRuntimeVersion,
} = require('../../compile/internal-version');
const {cyan, red, yellow} = require('kleur/colors');
const {log} = require('../../common/logging');
const {log, logWithoutTimestamp} = require('../../common/logging');
const {report, NoTTYReport} = require('@ampproject/filesize');

const requestPost = util.promisify(require('request').post);
Expand Down Expand Up @@ -113,6 +113,7 @@ async function storeBundleSize() {
}

const commitHash = gitCommitHash();
log('Storing bundle sizes for commit', cyan(shortSha(commitHash)) + '...');
try {
const response = await requestPost({
uri: url.resolve(
Expand All @@ -125,15 +126,10 @@ async function storeBundleSize() {
bundleSizes: await getBrotliBundleSizes(),
},
});
checkResponse(
response,
'Successfully stored bundle sizes for commit',
cyan(shortSha(commitHash)) + '.'
);
checkResponse(response, 'Successfully stored bundle sizes.');
} catch (error) {
log(red('Could not store bundle sizes'));
log(red(error));
process.exitCode = 1;
log(yellow('WARNING:'), 'Could not store bundle sizes');
logWithoutTimestamp(error);
return;
}
}
Expand All @@ -144,26 +140,28 @@ async function storeBundleSize() {
async function skipBundleSize() {
if (isPullRequestBuild()) {
const commitHash = gitCommitHash();
log(
'Skipping bundle size reporting for commit',
cyan(shortSha(commitHash)) + '...'
);
try {
const response = await requestPost(
url.resolve(
bundleSizeAppBaseUrl,
path.join('commit', commitHash, 'skip')
)
);
checkResponse(
response,
'Skipped bundle size reporting for commit',
cyan(shortSha(commitHash)) + '.'
);
checkResponse(response, 'Successfully skipped bundle size reporting.');
} catch (error) {
log(red('Could not report a skipped pull request'));
log(red(error));
process.exitCode = 1;
log(yellow('WARNING:'), 'Could not skip bundle size reporting');
logWithoutTimestamp(error);
return;
}
} else {
log(yellow('Pull requests can be marked as skipped only during CI builds'));
log(
yellow('WARNING'),
'Pull requests can be marked as skipped only during CI builds'
);
}
}

Expand All @@ -174,6 +172,12 @@ async function reportBundleSize() {
if (isPullRequestBuild()) {
const baseSha = gitCiMasterBaseline();
const commitHash = gitCommitHash();
log(
'Reporting bundle sizes for commit',
cyan(shortSha(commitHash)),
'using baseline commit',
cyan(shortSha(baseSha)) + '...'
);
try {
const response = await requestPost({
uri: url.resolve(
Expand All @@ -186,24 +190,19 @@ async function reportBundleSize() {
bundleSizes: await getBrotliBundleSizes(),
},
});
checkResponse(
response,
'Successfully reported bundle sizes for commit',
cyan(shortSha(commitHash)),
'using baseline commit',
cyan(shortSha(baseSha)) + '.'
);
checkResponse(response, 'Successfully reported bundle sizes.');
} catch (error) {
log(red('Could not report the bundle sizes for this pull request'));
log(red(error));
process.exitCode = 1;
log(
yellow('WARNING:'),
'Could not report the bundle sizes for this pull request'
);
logWithoutTimestamp(error);
return;
}
} else {
log(
yellow(
'Bundle sizes from pull requests can be reported only during CI builds'
)
yellow('WARNING:'),
'Bundle sizes from pull requests can be reported only during CI builds'
);
}
}
Expand Down

0 comments on commit aeccddf

Please sign in to comment.