Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions scripts/release/get-build-id-for-commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@

const fetch = require('node-fetch');

const POLLING_INTERVAL = 5 * 1000; // 5 seconds
const RETRY_TIMEOUT = 10 * 60 * 1000; // 10 minutes
const POLLING_INTERVAL = 10 * 1000; // 10 seconds
const RETRY_TIMEOUT = 4 * 60 * 1000; // 4 minutes

function wait(ms) {
return new Promise(resolve => {
setTimeout(() => resolve(), ms);
});
}

function scrapeBuildIDFromStatus(status) {
return /\/facebook\/react\/([0-9]+)/.exec(status.target_url)[1];
}

async function getBuildIdForCommit(sha) {
const retryLimit = Date.now() + RETRY_TIMEOUT;
retry: while (true) {
Expand All @@ -30,11 +34,24 @@ async function getBuildIdForCommit(sha) {
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];
return scrapeBuildIDFromStatus(status);
}
if (status.state === 'failure') {
throw new Error(`Build job for commit failed: ${sha}`);
}
if (status.state === 'pending') {
if (Date.now() < retryLimit) {
await wait(POLLING_INTERVAL);
continue retry;
}
// GitHub's status API is super flaky. Sometimes it reports a job
// as "pending" even after it completes in CircleCI. If it's still
// pending when we time out, return the build ID anyway.
// TODO: The location of the retry loop is a bit weird. We should
// probably combine this function with the one that downloads the
// artifacts, and wrap the retry loop around the whole thing.
return scrapeBuildIDFromStatus(status);
}
}
}
if (state === 'pending') {
Expand Down