mirror of
https://github.com/zebrajr/react.git
synced 2025-12-07 12:20:38 +01:00
* build-combined: Fix bundle sizes path * Output COMMIT_SHA in build directory Alternative to parsing an arbitrary package's version number, or its `build-info.json`. * Remove CircleCI environment variable requirement I think this only reason we needed this was to support passing any job id to `--build`, instead of requiring the `process_artifacts` job. And to do that you needed to use the workflows API endpoint, which requires an API token. But now that the `--commit` argument exists and automatically finds the correct job id, we can just use that. * Add CI job that gets base artifacts Uses download-experimental script and places the base artifacts into a top-level folder. * Migrate sizebot to combined workflow Replaces the two separate sizebot jobs (one for each channel, stable and experimental) with a single combined job that outputs size information for all bundles in a single GitHub comment. I didn't attempt to simplify the output at all, but we should. I think what I would do is remove our custom Rollup sizes plugin, and read the sizes from the filesystem instead. We would lose some information about the build configuration used to generate each artifact, but that can be inferred from the filepath. For example, the filepath `fb-www/ReactDOM-dev.classic.js` already tells us everything we need to know about the artifact. Leaving this for a follow up. * Move GitHub status check inside retry loop The download script will poll the CircleCI endpoint until the build job is complete; it should also poll the GitHub status endpoint if the build job hasn't been spawned yet. * Only run get_base_build on main branch
52 lines
1.5 KiB
JavaScript
52 lines
1.5 KiB
JavaScript
'use strict';
|
|
|
|
const fetch = require('node-fetch');
|
|
|
|
const POLLING_INTERVAL = 5 * 1000; // 5 seconds
|
|
const RETRY_TIMEOUT = 10 * 60 * 1000; // 10 minutes
|
|
|
|
function wait(ms) {
|
|
return new Promise(resolve => {
|
|
setTimeout(() => resolve(), ms);
|
|
});
|
|
}
|
|
|
|
async function getBuildIdForCommit(sha) {
|
|
const retryLimit = Date.now() + RETRY_TIMEOUT;
|
|
retry: while (true) {
|
|
const statusesResponse = await fetch(
|
|
`https://api.github.com/repos/facebook/react/commits/${sha}/status`
|
|
);
|
|
|
|
if (!statusesResponse.ok) {
|
|
throw Error('Could not find commit for: ' + sha);
|
|
}
|
|
|
|
const {statuses, state} = await statusesResponse.json();
|
|
if (state === 'failure') {
|
|
throw new Error(`Base commit is broken: ${sha}`);
|
|
}
|
|
for (let i = 0; i < statuses.length; i++) {
|
|
const status = statuses[i];
|
|
if (status.context === `ci/circleci: process_artifacts_combined`) {
|
|
if (status.state === 'success') {
|
|
return /\/facebook\/react\/([0-9]+)/.exec(status.target_url)[1];
|
|
}
|
|
if (status.state === 'failure') {
|
|
throw new Error(`Build job for commit failed: ${sha}`);
|
|
}
|
|
}
|
|
}
|
|
if (state === 'pending') {
|
|
if (Date.now() < retryLimit) {
|
|
await wait(POLLING_INTERVAL);
|
|
continue retry;
|
|
}
|
|
throw new Error('Exceeded retry limit. Build job is still pending.');
|
|
}
|
|
throw new Error('Could not find build for commit: ' + sha);
|
|
}
|
|
}
|
|
|
|
module.exports = getBuildIdForCommit;
|